diff options
author | root <root@bpcserver.bpcserver> | 2024-02-27 21:53:44 -0600 |
---|---|---|
committer | root <root@bpcserver.bpcserver> | 2024-02-27 21:53:44 -0600 |
commit | afa02f645056c5823b0d8a29d37c1ff10aedce7a (patch) | |
tree | 0bc89e7909c17d8f33538ac9f31a641872b89f40 /cop.hpp |
Diffstat (limited to 'cop.hpp')
-rw-r--r-- | cop.hpp | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -0,0 +1,48 @@ +#include <typeinfo> +#include "robber.h" + +// Programmer: Brett Weiland +// Date: 4/30/23 +// File: cop.hpp +// Assignment: SP-B-finalProject +// Purpose: all the functions specific to how cops interact and move. + +template <class T> char cop<T>::getIcon() const { return 'p'; } +template <class T> unsigned int cop<T>::get_drawPriority() const { return 1; } +template <class T> unsigned int cop<T>::get_robbersCaught() const { return robbers_caught; } +template <class T> void cop<T>::robbersReleased() { robbers_caught = 0; } + +template <class T> void cop<T>::move() { + this->location.stepDirection(this->parentCity->randomDirection(this->location)); + for(gameObject *peer = this->parentCity->findObjsByLocation(this->location); + peer != NULL; peer = peer->get_top()) { + + const std::type_info &peer_type = typeid(*peer); + + if(peer_type == typeid(robber<T>)) { + robber<T> &rob = dynamic_cast<robber<T>&>(*peer); + if(rob.is_active()) arrest(rob); + } + + if(peer_type == typeid(T)) { + this->inventory[this->inventory_qty] = dynamic_cast<T*>(peer); + this->inventory[this->inventory_qty++]->pickup(); + } + } +} + +template <class T> void cop<T>::arrest(robber<T> &offender) { + T **crinimal_stash = offender.getArrested(); + size_t loot_i; + for(loot_i = 0; crinimal_stash[loot_i] != NULL; loot_i++) { //assumes robbers + this->inventory[this->inventory_qty + loot_i] = crinimal_stash[loot_i]; + crinimal_stash[loot_i] = NULL; + } + this->inventory_qty += loot_i; + robbers_caught++; +} + +template <class T> void cop<T>::takeBribe(T *bribe) { + this->inventory[this->inventory_qty++] = bribe; + this->parentCity->freeAllRobbers(); +} |