From afa02f645056c5823b0d8a29d37c1ff10aedce7a Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Feb 2024 21:53:44 -0600 Subject: init --- robber.hpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 robber.hpp (limited to 'robber.hpp') diff --git a/robber.hpp b/robber.hpp new file mode 100644 index 0000000..9c2c81e --- /dev/null +++ b/robber.hpp @@ -0,0 +1,91 @@ +#include +#include + +// Programmer: Brett Weiland +// Date: 4/30/23 +// File: cop.hpp +// Assignment: SP-B-finalProject +// Purpose: contains member functions for robber class; see robber.h + +#include "cop.h" + +template void robber::setGreedy(const bool greedy_value) { greedy = greedy_value; } +template unsigned int robber::get_drawPriority() const { return 0; } +template void robber::free() { this->active = true; } +template bool robber::isGreedy() const { return greedy; } + +template bool robber::iterateInteractables() { + for(gameObject *peer = this->parentCity->findObjsByLocation(this->location); + peer != NULL; peer = peer->get_top()) { + return handleInteractable(*peer); + } + return false; +} + +template bool robber::handleInteractable(gameObject &peer) { + const std::type_info &peer_type = typeid(peer); + if(peer_type == typeid(robber)) { + if(!greedy) return false; + this->inventory_qty /= 2; + for(size_t loot_i = this->inventory_qty; + (loot_i < BAG_SIZE) && (this->inventory[loot_i] != NULL); loot_i++) { + total_loot_value -= this->inventory[loot_i]->value(); + this->inventory[loot_i]->drop(); + this->inventory[loot_i] = NULL; + } + } + + if(peer_type == typeid(cop)) { + cop &popo = dynamic_cast&>(peer); + if(greedy && (this->inventory_qty >= BAG_SIZE)) { + this->inventory_qty--; + popo.takeBribe(this->inventory[this->inventory_qty]); + total_loot_value -= this->inventory[this->inventory_qty]->value(); + this->inventory[this->inventory_qty] = NULL; + } else { popo.arrest(*this); } + return false; + } + + if(peer_type == typeid(T)) { + if(this->inventory_qty >= BAG_SIZE) return false; + this->inventory[this->inventory_qty] = dynamic_cast(&peer); + this->inventory[this->inventory_qty]->pickup(); + total_loot_value += this->inventory[this->inventory_qty]->value(); + if(!(this->inventory[this->inventory_qty++]->value() % 2)) return true; + } + return false; +} + + +template void robber::move() { + for(unsigned int moves = 0; moves < MAX_MOVES; moves++) { + if(greedy) { + if(this->inventory_qty >= BAG_SIZE) + this->location.stepDirection(this->parentCity->nearestCopDirection(this->location)); + else + this->location.stepDirection(this->parentCity->directionToAnyJewl(this->location)); + } + else { + this->location.stepDirection(this->parentCity->randomDirection(this->location)); + } + if(!iterateInteractables()) break; + } +} + + +template T **robber::getArrested() { + this->active = false; + total_loot_value -= this->get_inventoryValue(); + this->inventory_qty = 0; + return this->inventory; +} + +template char robber::getIcon() const { + if(this->bottom_obj == NULL) return 'r'; + if((typeid(*this->bottom_obj) == typeid(robber)) && (dynamic_cast*>(this->bottom_obj)->active)) { + return 'R'; + } + return 'r'; +} + +template unsigned int robber::get_totalRobberValue() const { return total_loot_value; } -- cgit v1.2.3