#include #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 char cop::getIcon() const { return 'p'; } template unsigned int cop::get_drawPriority() const { return 1; } template unsigned int cop::get_robbersCaught() const { return robbers_caught; } template void cop::robbersReleased() { robbers_caught = 0; } template void cop::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)) { robber &rob = dynamic_cast&>(*peer); if(rob.is_active()) arrest(rob); } if(peer_type == typeid(T)) { this->inventory[this->inventory_qty] = dynamic_cast(peer); this->inventory[this->inventory_qty++]->pickup(); } } } template void cop::arrest(robber &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 void cop::takeBribe(T *bribe) { this->inventory[this->inventory_qty++] = bribe; this->parentCity->freeAllRobbers(); }