summaryrefslogtreecommitdiff
path: root/robber.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'robber.hpp')
-rw-r--r--robber.hpp91
1 files changed, 91 insertions, 0 deletions
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 <math.h>
+#include <typeinfo>
+
+// 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 <class T> void robber<T>::setGreedy(const bool greedy_value) { greedy = greedy_value; }
+template <class T> unsigned int robber<T>::get_drawPriority() const { return 0; }
+template <class T> void robber<T>::free() { this->active = true; }
+template <class T> bool robber<T>::isGreedy() const { return greedy; }
+
+template <class T> bool robber<T>::iterateInteractables() {
+ for(gameObject *peer = this->parentCity->findObjsByLocation(this->location);
+ peer != NULL; peer = peer->get_top()) {
+ return handleInteractable(*peer);
+ }
+ return false;
+}
+
+template <class T> bool robber<T>::handleInteractable(gameObject &peer) {
+ const std::type_info &peer_type = typeid(peer);
+ if(peer_type == typeid(robber<T>)) {
+ 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<T>)) {
+ cop<T> &popo = dynamic_cast<cop<T>&>(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<T*>(&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 <class T> void robber<T>::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 <class T> T **robber<T>::getArrested() {
+ this->active = false;
+ total_loot_value -= this->get_inventoryValue();
+ this->inventory_qty = 0;
+ return this->inventory;
+}
+
+template <class T> char robber<T>::getIcon() const {
+ if(this->bottom_obj == NULL) return 'r';
+ if((typeid(*this->bottom_obj) == typeid(robber<T>)) && (dynamic_cast<robber<T>*>(this->bottom_obj)->active)) {
+ return 'R';
+ }
+ return 'r';
+}
+
+template <class T> unsigned int robber<T>::get_totalRobberValue() const { return total_loot_value; }