-
Notifications
You must be signed in to change notification settings - Fork 0
/
Agent.h
93 lines (71 loc) · 3.06 KB
/
Agent.h
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
84
85
86
87
88
89
90
91
92
93
/*
Agents are a kind of Sim_object, and privately inherit from Moving_object.
Agents can be commanded to move to a destination. Agents have a health, which
is decreased when they take a hit. If the Agent's health > 0, it is alive.
If its health <= 0, it is dead, and removed from the world.
*/
#ifndef AGENT_H
#define AGENT_H
#include "Sim_object.h"
#include "Moving_object.h"
#include <memory>
class Structure;
class Soldier;
class Witch_doctor;
class Archer;
class Agent : public Sim_object, public std::enable_shared_from_this<Agent>,
private Moving_object {
public:
Agent(const std::string& in_name, Point in_location);
virtual ~Agent() = 0;
// return true if this agent is Alive or Disappearing
bool is_alive() const
{return state == ALIVE;}
// return this Agent's location
Point get_location() const override;
// return true if this Agent is in motion
bool is_moving() const;
// return true if this Agent is attacking
// Default behavior is false.
virtual bool is_attacking() const
{return false;}
// return the health of the agent
int get_health() const
{return health;}
// Increase the health of the agent by the curing strength, max health is 5/
void gain_health(int curing_strength);
// tell this Agent to start moving to location destination_
virtual void move_to(Point destination_);
// tell this Agent to stop its activity
virtual void stop();
// All of the three funcitons below tell this Agent to accept a hit from an attack of a specified strength.
// The attacking Agent identifies itself with its shared_from_this pointer.
// A derived class can override this function.
// The function lose_health is called to handle the effect of the attack.
virtual void take_hit(int attack_strength, std::shared_ptr<Soldier> soldier_ptr);
virtual void take_hit(int attack_strength, std::shared_ptr<Archer> archer_ptr);
virtual void take_hit(int attack_strength, std::shared_ptr<Witch_doctor> doctor_ptr);
// update the moving state and Agent state of this object.
void update() override;
// output information about the current state
void describe() const override;
// ask Model to broadcast our current state to all Views
void broadcast_current_state() const override;
/* Fat Interface for derived classes */
// Throws exception that an Agent cannot work.
virtual void start_working(std::shared_ptr<Structure> source_ptr,
std::shared_ptr<Structure> destination_ptr);
// Throws exception that an Agent cannot attack.
virtual void start_attacking(std::shared_ptr<Agent> target_ptr);
// Throws exception that an Agent cannot heal.
virtual void start_healing(std::shared_ptr<Agent> target_ptr);
protected:
// calculate loss of health due to hit.
// if health decreases to zero or negative, Agent state becomes Dying, and any movement is stopped.
void lose_health(int attack_strength);
private:
enum State_e {ALIVE, DEAD};
int health;
State_e state;
};
#endif