~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/nofActiveSoldier.h

  • Committer: FloSoft
  • Date: 2014-04-25 15:35:50 UTC
  • Revision ID: flosoft@siedler25.org-20140425153550-9muu4vodhlqu58m0
committing subversion revision 9357 by FloSoft
astyle

modified:
s25client/trunk/
s25client/trunk/contrib/lua/lin32/include/
s25client/trunk/contrib/lua/lin64/include/
s25client/trunk/contrib/lua/mac/include/
s25client/trunk/contrib/lua/win32/include/
s25client/trunk/contrib/lua/win64/include/
s25client/trunk/driver/audio/SDL/src/
s25client/trunk/driver/src/
s25client/trunk/driver/video/GLFW/src/
s25client/trunk/driver/video/SDL/src/
s25client/trunk/driver/video/WinAPI/src/
s25client/trunk/src/
s25client/trunk/win32/
s25client/trunk/win32/prebuild-mutex/src/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: nofActiveSoldier.h 7521 2011-09-08 20:45:55Z FloSoft $
 
1
// $Id: nofActiveSoldier.h 9357 2014-04-25 15:35:25Z FloSoft $
2
2
//
3
3
// Copyright (c) 2005 - 2011 Settlers Freaks (sf-team at siedler25.org)
4
4
//
21
21
 
22
22
#include "nofSoldier.h"
23
23
 
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
28
28
{
29
 
public:
30
 
 
31
 
        friend class noFighting;
32
 
 
33
 
        /// State of each soldier
34
 
        enum SoldierState
35
 
        {
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
41
 
                
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
49
 
                
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
54
 
 
55
 
                STATE_AGGRESSIVEDEFENDING_WALKINGTOAGGRESSOR, // Follow the attacker in order to fight against him
56
 
 
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
60
 
 
61
 
        };
62
 
 
63
 
protected:
64
 
 
65
 
        /// State of the soldier, always has to be a valid value
66
 
        enum SoldierState state;
67
 
 
68
 
private:
69
 
 
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;
74
 
 
75
 
protected:
76
 
 
77
 
        /// Start returning home
78
 
        void ReturnHome();
79
 
        /// Walking home, called after each walking step
80
 
        void WalkingHome();
81
 
        
82
 
        /// Examines hostile people on roads and expels them
83
 
        void ExpelEnemies();
84
 
 
85
 
 
86
 
        /// Handle walking for nofActiveSoldier speciefic sates
87
 
        virtual void Walked();
88
 
 
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
95
 
        void MeetingEnemy();
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);
99
 
        
100
 
 
101
 
 
102
 
        /// The derived classes regain control after a fight of nofActiveSoldier
103
 
        virtual void FreeFightEnded() = 0;
104
 
 
105
 
private:
106
 
 
107
 
        /// Is informed when...
108
 
        void GoalReached(); // ... he reached his "working place" (i.e. his military building)
109
 
        
110
 
        /// Gets the visual range radius of this soldier
111
 
        virtual unsigned GetVisualRange() const;
112
 
 
113
 
 
114
 
public:
115
 
 
116
 
        /// Constructors
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);
121
 
        /// Deserializer
122
 
        nofActiveSoldier(SerializedGameData * sgd, const unsigned obj_id);
123
 
 
124
 
        /// Tidy up
125
 
        protected:      void Destroy_nofActiveSoldier() { Destroy_nofSoldier(); }
126
 
        public:         void Destroy() { Destroy_nofActiveSoldier(); }
127
 
 
128
 
        /// Serializer
129
 
        protected:      void Serialize_nofActiveSoldier(SerializedGameData * sgd) const;
130
 
        public:         void Serialize(SerializedGameData *sgd) const { Serialize_nofActiveSoldier(sgd); }
131
 
 
132
 
        /// Draw soldier (for all types of soldiers done by this base class!)
133
 
        void Draw(int x, int y);
134
 
 
135
 
        /// Event handling
136
 
        virtual void HandleDerivedEvent(const unsigned int id);
137
 
 
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;
148
 
 
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();
153
 
 
154
 
 
155
 
        /// Gets the current state
156
 
        SoldierState GetState() const { return state; }
 
29
    public:
 
30
 
 
31
        friend class noFighting;
 
32
 
 
33
        /// State of each soldier
 
34
        enum SoldierState
 
35
        {
 
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
 
41
 
 
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
 
49
 
 
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
 
54
 
 
55
            STATE_AGGRESSIVEDEFENDING_WALKINGTOAGGRESSOR, // Follow the attacker in order to fight against him
 
56
 
 
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
 
60
 
 
61
        };
 
62
 
 
63
    protected:
 
64
 
 
65
        /// State of the soldier, always has to be a valid value
 
66
        enum SoldierState state;
 
67
 
 
68
    private:
 
69
 
 
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;
 
74
 
 
75
    protected:
 
76
 
 
77
        /// Start returning home
 
78
        void ReturnHome();
 
79
        /// Walking home, called after each walking step
 
80
        void WalkingHome();
 
81
 
 
82
        /// Examines hostile people on roads and expels them
 
83
        void ExpelEnemies();
 
84
 
 
85
 
 
86
        /// Handle walking for nofActiveSoldier speciefic sates
 
87
        virtual void Walked();
 
88
 
 
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
 
95
        void MeetingEnemy();
 
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);
 
99
 
 
100
 
 
101
 
 
102
        /// The derived classes regain control after a fight of nofActiveSoldier
 
103
        virtual void FreeFightEnded() = 0;
 
104
 
 
105
    private:
 
106
 
 
107
        /// Is informed when...
 
108
        void GoalReached(); // ... he reached his "working place" (i.e. his military building)
 
109
 
 
110
        /// Gets the visual range radius of this soldier
 
111
        virtual unsigned GetVisualRange() const;
 
112
 
 
113
 
 
114
    public:
 
115
 
 
116
        /// Constructors
 
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);
 
121
        /// Deserializer
 
122
        nofActiveSoldier(SerializedGameData* sgd, const unsigned obj_id);
 
123
 
 
124
        /// Tidy up
 
125
    protected:  void Destroy_nofActiveSoldier() { Destroy_nofSoldier(); }
 
126
    public:     void Destroy() { Destroy_nofActiveSoldier(); }
 
127
 
 
128
        /// Serializer
 
129
    protected:  void Serialize_nofActiveSoldier(SerializedGameData* sgd) const;
 
130
    public:     void Serialize(SerializedGameData* sgd) const { Serialize_nofActiveSoldier(sgd); }
 
131
 
 
132
        /// Draw soldier (for all types of soldiers done by this base class!)
 
133
        void Draw(int x, int y);
 
134
 
 
135
        /// Event handling
 
136
        virtual void HandleDerivedEvent(const unsigned int id);
 
137
 
 
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;
 
148
 
 
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();
 
153
 
 
154
 
 
155
        /// Gets the current state
 
156
        SoldierState GetState() const { return state; }
157
157
};
158
158
 
159
159
#endif // !NOF_ACTIVESOLDIER_H_