summaryrefslogtreecommitdiff
path: root/npc.h
blob: c45d971fe81101ec8934ff290add67d7b2a424dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef NPC_H
#define NPC_H

// Programmer: Brett Weiland
// Date: 4/30/23
// File: npc.h
// Assignment: SP-B-finalProject
// Purpose: contains the abstract base class for npcs.
//          npcs are gameObjects that move, and consist of the cop and robber.

#include <typeindex>    
#include <typeinfo>    

#include "gameObject.h"
#include "coordinate.h"

template <class T>
class npc : public gameObject {
  public:
    //Desc: npc initilizer
    //Pre:  none
    //Post: npc initilized, ID is set and static ID counter incrimented
    npc();

    //Desc: the move function for the NPC. Called once for every NPC each round
    //Pre:  none
    //Post: NPC's actions for that round will be taken, unless another npc interacts with it
    virtual void move() = 0;

    //Desc: called when NPC is arrested. returns inventory pointer to caller,
    //      cop uses this to record items in their own stash.
    //Pre:  none
    //Post: npc is no longer active (can't move), more behavior is defined by cop arrest() function
    T **getArrested();

    //Desc: gets value of all items in inventory
    //Pre:  inventory must have pointers to items with value() function or NULL where there are none
    //Post: total value of al objects in inventory returned
    unsigned int get_inventoryValue() const;

    //getters and setters
    int get_id() const;
    bool is_active() const; //false if arrested
    void free(); //sets active to true
    unsigned int get_inventoryQty() const;
  protected:
    /**
      IMPORTAINT
      with the schools -pedantic-errors option, there seemed to be no way to declare
      a static array of any size other then a static constant type, which requires initilizatoin
      in the class at compile time.

      I could use preprocessor directives, 
      but I figured I should stay away from for my grade them due to never seeing them in class.
      I could have also used a dynamic array, but we have not been taught new/delete yet.

      Dynmaic arrays are great, I would have allowed them, they aren't too difficult. 
      You would just need to learn destructors.
    **/
    static const std::size_t INVENTORY_SIZE = 47; // MUST BE SET TO CITY JEWL COUNT <---

    //inventory size shold be set to jewl count to ensure any gameObject has enough inventory space.
    T *inventory[INVENTORY_SIZE] = {NULL};

    //number of items in inventory
    unsigned int inventory_qty = 0;
    int id;

    //false if we should be on the map, but shouldn't be allowed to move. 
    //Used when robber is arrested
    bool active = true;

  private:
    static int id_counter; //ensures the next constructed ID is one higher then ours
};

template <class T> int npc<T>::id_counter = 1;


#include "npc.hpp"


#endif