summaryrefslogtreecommitdiff
path: root/cop.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'cop.hpp')
-rw-r--r--cop.hpp48
1 files changed, 48 insertions, 0 deletions
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 <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();
+}