From afa02f645056c5823b0d8a29d37c1ff10aedce7a Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Feb 2024 21:53:44 -0600 Subject: init --- cop.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cop.hpp (limited to 'cop.hpp') diff --git a/cop.hpp b/cop.hpp new file mode 100644 index 0000000..f6f821d --- /dev/null +++ b/cop.hpp @@ -0,0 +1,48 @@ +#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(); +} -- cgit v1.2.3