22
22
#include "nofSoldier.h"
24
/// Base class for all 3 types of "active" soldiers (i.e. who are in the free world to fight and don't
24
/// Base class for all 3 types of "active" soldiers (i.e. who are in the free world to fight and don't
25
25
/// walk on the roads just to fill buildings)
26
26
/// Attackers, defenders and aggressive defenders
27
27
class nofActiveSoldier : public nofSoldier
31
friend class noFighting;
33
/// State of each soldier
36
STATE_FIGUREWORK = 0, /// Go to work etc., all which is done by noFigure
37
STATE_WALKINGHOME, /// Walking home after work to the military building
38
STATE_MEETENEMY, /// Prepare fighting with an enemy
39
STATE_WAITINGFORFIGHT, /// Standing still and waiting for a fight
40
STATE_FIGHTING, // Fighting
42
STATE_ATTACKING_WALKINGTOGOAL, // Attacker is walking to his attacked destination
43
STATE_ATTACKING_WAITINGAROUNDBUILDING, // Attacker is waiting around the building for his fight at the flag against the defender(s)
44
STATE_ATTACKING_WAITINGFORDEFENDER, // Waiting at the flag until the defender emerges from the building
45
STATE_ATTACKING_CAPTURINGFIRST, // Captures the hostile building as first person
46
STATE_ATTACKING_CAPTURINGNEXT, // The next soldiers capture the building in this state
47
STATE_ATTACKING_ATTACKINGFLAG, // Goes to the flag to fight the defender
48
STATE_ATTACKING_FIGHTINGVSDEFENDER, // Fighting against a defender at the flag
50
STATE_SEAATTACKING_GOTOHARBOR, // Goes from his home military building to the start harbor
51
STATE_SEAATTACKING_WAITINHARBOR, // Waiting in the start harbor for the ship
52
STATE_SEAATTACKING_ONSHIP, // On the ship to the destination
53
STATE_SEAATTACKING_RETURNTOSHIP, // Returns to the ship at the destination environment
55
STATE_AGGRESSIVEDEFENDING_WALKINGTOAGGRESSOR, // Follow the attacker in order to fight against him
57
STATE_DEFENDING_WAITING, // Waiting at the flag for further attackers
58
STATE_DEFENDING_WALKINGTO, // Goes to the flag before the fight
59
STATE_DEFENDING_WALKINGFROM // Goes into the building after the fight
65
/// State of the soldier, always has to be a valid value
66
enum SoldierState state;
70
/// Current enemy when fighting in the nofActiveSoldier modes (and only in this case!)
71
nofActiveSoldier * enemy;
72
/// Meeting point for fighting against the enemy
73
Point<MapCoord> fight_spot;
77
/// Start returning home
79
/// Walking home, called after each walking step
82
/// Examines hostile people on roads and expels them
86
/// Handle walking for nofActiveSoldier speciefic sates
87
virtual void Walked();
89
/// Looks for enemies nearby which want to fight with this soldier
90
/// Returns true if it found one
91
bool FindEnemiesNearby();
92
/// Informs this soldier that another soldier starts meeting him
93
void MeetEnemy(nofActiveSoldier * other, const Point<MapCoord> figh_spot);
94
/// Handle state "meet enemy" after each walking step
96
/// Looks for an appropriate fighting spot between the two soldiers
97
/// Returns true if successful
98
bool GetFightSpotNear(nofActiveSoldier * other, Point<MapCoord> * fight_spot);
102
/// The derived classes regain control after a fight of nofActiveSoldier
103
virtual void FreeFightEnded() = 0;
107
/// Is informed when...
108
void GoalReached(); // ... he reached his "working place" (i.e. his military building)
110
/// Gets the visual range radius of this soldier
111
virtual unsigned GetVisualRange() const;
117
nofActiveSoldier(const unsigned short x, const unsigned short y,const unsigned char player,
118
nobBaseMilitary * const home,const unsigned char rank, const SoldierState init_state);
119
/// (Copy-)Constructor
120
nofActiveSoldier(const nofSoldier& other, const SoldierState init_state);
122
nofActiveSoldier(SerializedGameData * sgd, const unsigned obj_id);
125
protected: void Destroy_nofActiveSoldier() { Destroy_nofSoldier(); }
126
public: void Destroy() { Destroy_nofActiveSoldier(); }
129
protected: void Serialize_nofActiveSoldier(SerializedGameData * sgd) const;
130
public: void Serialize(SerializedGameData *sgd) const { Serialize_nofActiveSoldier(sgd); }
132
/// Draw soldier (for all types of soldiers done by this base class!)
133
void Draw(int x, int y);
136
virtual void HandleDerivedEvent(const unsigned int id);
138
/// Informs the different things that we are not coming anymore
139
virtual void InformTargetsAboutCancelling() = 0;
140
/// Is called when our home military building was destroyed
141
virtual void HomeDestroyed() = 0;
142
/// When the soldier is still hanging in the going-out waiting queue in the home military building
143
virtual void HomeDestroyedAtBegin() = 0;
144
/// When a fight was won
145
virtual void WonFighting() = 0;
146
/// When a fight was lost
147
virtual void LostFighting() = 0;
149
/// Determines if this soldier is ready for a spontaneous fight
150
bool IsReadyForFight() const;
151
/// Informs a waiting soldier about the start of a fight
152
void FightingStarted();
155
/// Gets the current state
156
SoldierState GetState() const { return state; }
31
friend class noFighting;
33
/// State of each soldier
36
STATE_FIGUREWORK = 0, /// Go to work etc., all which is done by noFigure
37
STATE_WALKINGHOME, /// Walking home after work to the military building
38
STATE_MEETENEMY, /// Prepare fighting with an enemy
39
STATE_WAITINGFORFIGHT, /// Standing still and waiting for a fight
40
STATE_FIGHTING, // Fighting
42
STATE_ATTACKING_WALKINGTOGOAL, // Attacker is walking to his attacked destination
43
STATE_ATTACKING_WAITINGAROUNDBUILDING, // Attacker is waiting around the building for his fight at the flag against the defender(s)
44
STATE_ATTACKING_WAITINGFORDEFENDER, // Waiting at the flag until the defender emerges from the building
45
STATE_ATTACKING_CAPTURINGFIRST, // Captures the hostile building as first person
46
STATE_ATTACKING_CAPTURINGNEXT, // The next soldiers capture the building in this state
47
STATE_ATTACKING_ATTACKINGFLAG, // Goes to the flag to fight the defender
48
STATE_ATTACKING_FIGHTINGVSDEFENDER, // Fighting against a defender at the flag
50
STATE_SEAATTACKING_GOTOHARBOR, // Goes from his home military building to the start harbor
51
STATE_SEAATTACKING_WAITINHARBOR, // Waiting in the start harbor for the ship
52
STATE_SEAATTACKING_ONSHIP, // On the ship to the destination
53
STATE_SEAATTACKING_RETURNTOSHIP, // Returns to the ship at the destination environment
55
STATE_AGGRESSIVEDEFENDING_WALKINGTOAGGRESSOR, // Follow the attacker in order to fight against him
57
STATE_DEFENDING_WAITING, // Waiting at the flag for further attackers
58
STATE_DEFENDING_WALKINGTO, // Goes to the flag before the fight
59
STATE_DEFENDING_WALKINGFROM // Goes into the building after the fight
65
/// State of the soldier, always has to be a valid value
66
enum SoldierState state;
70
/// Current enemy when fighting in the nofActiveSoldier modes (and only in this case!)
71
nofActiveSoldier* enemy;
72
/// Meeting point for fighting against the enemy
73
Point<MapCoord> fight_spot;
77
/// Start returning home
79
/// Walking home, called after each walking step
82
/// Examines hostile people on roads and expels them
86
/// Handle walking for nofActiveSoldier speciefic sates
87
virtual void Walked();
89
/// Looks for enemies nearby which want to fight with this soldier
90
/// Returns true if it found one
91
bool FindEnemiesNearby();
92
/// Informs this soldier that another soldier starts meeting him
93
void MeetEnemy(nofActiveSoldier* other, const Point<MapCoord> figh_spot);
94
/// Handle state "meet enemy" after each walking step
96
/// Looks for an appropriate fighting spot between the two soldiers
97
/// Returns true if successful
98
bool GetFightSpotNear(nofActiveSoldier* other, Point<MapCoord> * fight_spot);
102
/// The derived classes regain control after a fight of nofActiveSoldier
103
virtual void FreeFightEnded() = 0;
107
/// Is informed when...
108
void GoalReached(); // ... he reached his "working place" (i.e. his military building)
110
/// Gets the visual range radius of this soldier
111
virtual unsigned GetVisualRange() const;
117
nofActiveSoldier(const unsigned short x, const unsigned short y, const unsigned char player,
118
nobBaseMilitary* const home, const unsigned char rank, const SoldierState init_state);
119
/// (Copy-)Constructor
120
nofActiveSoldier(const nofSoldier& other, const SoldierState init_state);
122
nofActiveSoldier(SerializedGameData* sgd, const unsigned obj_id);
125
protected: void Destroy_nofActiveSoldier() { Destroy_nofSoldier(); }
126
public: void Destroy() { Destroy_nofActiveSoldier(); }
129
protected: void Serialize_nofActiveSoldier(SerializedGameData* sgd) const;
130
public: void Serialize(SerializedGameData* sgd) const { Serialize_nofActiveSoldier(sgd); }
132
/// Draw soldier (for all types of soldiers done by this base class!)
133
void Draw(int x, int y);
136
virtual void HandleDerivedEvent(const unsigned int id);
138
/// Informs the different things that we are not coming anymore
139
virtual void InformTargetsAboutCancelling() = 0;
140
/// Is called when our home military building was destroyed
141
virtual void HomeDestroyed() = 0;
142
/// When the soldier is still hanging in the going-out waiting queue in the home military building
143
virtual void HomeDestroyedAtBegin() = 0;
144
/// When a fight was won
145
virtual void WonFighting() = 0;
146
/// When a fight was lost
147
virtual void LostFighting() = 0;
149
/// Determines if this soldier is ready for a spontaneous fight
150
bool IsReadyForFight() const;
151
/// Informs a waiting soldier about the start of a fight
152
void FightingStarted();
155
/// Gets the current state
156
SoldierState GetState() const { return state; }
159
159
#endif // !NOF_ACTIVESOLDIER_H_