18
26
#include <SDL_types.h>
27
/** This is the structure that describes the course of the fight. It is later
28
* read by a fight dialog to reconstruct what happened.
36
//! A description of a round of casualties during a Fight.
38
* This is the structure that describes the events of the fight. It is
39
* played back by a fight dialog to reconstruct and show what transpired.
32
int turn; //!< fight round of this attack
33
Uint32 id; //!< id of the attacked army
34
int damage; //!< damage done to the army
43
//! The round number of the battle.
45
//! The id of the army who was attacked in this event.
47
//! The amount of damage that the army sustained.
38
/** This class is solely responsible for the _calculation_ of the fight.
39
* It gets the participating stacks and damages the units within according
40
* to the calculation. Furthermore, it creates a history of the fight, which
41
* can later be used by the fight dialog to reconstruct the fight or be sent
42
* over the network. For the graphical display, see the FightDialog class.
44
* Two things should be noted. First, the fight can include more than the
45
* initial two stacks, since all stacks around the defender are considered
46
* as potential "contributors". Second, irrespective of that, a fight is
47
* always considered as "won", if the defending stack was destroyed and
48
* "lost" if the attacking stack was crushed.
52
//! Calculate the outcome of a battle.
54
* This class is solely responsible for the _calculation_ of the fight.
55
* It gets the participating stacks and damages the units within according
56
* to the calculation. Furthermore, it creates a history of the fight, which
57
* can later be used by the fight dialog to reconstruct the fight or be sent
58
* over the network. For the graphical display, see the FightDialog class.
60
* Two things should be noted. First, the fight can include more than the
61
* initial two stacks, since all stacks around the defender are considered
62
* as potential "contributors". Second, irrespective of that, a fight is
63
* always considered as "won", if the defending stack was destroyed and
64
* "lost" if the attacking stack was crushed.
54
69
//! The three possibilities how a fight can end
55
enum Result {DRAW = 0, ATTACKER_WON = 1, DEFENDER_WON = 2};
56
enum FightType {FOR_KICKS = 0, FOR_KEEPS = 1};
58
/** Initializes a fight between two stacks
60
* @param attacker the attacking stack
61
* @param defender the defending stack
62
* @param type optionally heal all stacks afterwards
71
//! There was no winner.
73
* Although it is in the enumeration, every fight should always
74
* have a winner. No draws allowed because MAX_ROUNDS is 0.
78
//! The attacking list of stacks won the battle.
81
//! The defending list of stacks won the battle.
85
//! The kind of fight. Whether the outcome is realized or not.
87
//! The fight doesn't mean anything, it's just to see who would win.
89
* @note This value is used to assist in the implementation of the
90
* `Miltary Advisor' feature.
94
//! The fight is real. If an army dies, it stays dead.
98
//! Make a new fight between two lists of stacks.
100
* @param attacker The list of attacking stacks.
101
* @param defender The list of defending stacks
102
* @param type Optionally heal all stacks afterwards.
64
104
Fight(Stack* attacker, Stack* defender, FightType type = FOR_KEEPS);
106
// construct from serialized action
107
Fight(std::list<Stack*> attackers, std::list<Stack*> defenders,
108
std::list<FightItem> history);
68
//! Does the actual fight
113
//! Determine the outcome of the fight.
115
* This method fills out a set of FightItem events in d_actions.
117
* @param intense Whether or not to Use 24 sided dice instead of
118
* 20 sided dice. Makes battles harder to win when
69
121
void battle(bool intense);
72
//! Returns the result of the fight
123
void battleFromHistory();
125
//! Returns the result of the fight.
73
126
Result getResult() const {return d_result;}
75
//! Returns the list of things that happened in chronological order
128
//! Returns the list of things that happened in chronological order.
76
129
std::list<FightItem> getCourseOfEvents() const {return d_actions;};
78
//! Returns the participating attacker stacks
131
//! Returns the participating attacker stacks.
79
132
std::list<Stack*> getAttackers() const {return d_attackers;}
81
//! Returns the participating defender stacks
134
//! Returns the participating defender stacks.
82
135
std::list<Stack*> getDefenders() const {return d_defenders;}
137
//! Get the modified strength bonus of the given Army unit.
138
Uint32 getModifiedStrengthBonus(Army *a);
86
//! number of rounds the fight lasts
87
//! if this is 0, then there is no maximum.
141
//! The number of rounds the fight lasts.
143
* @note If this is 0, then there is no maximum.
88
145
static const int MAX_ROUNDS = 0;
90
//! number of movement points needed to do a fight (TODO: needs to be used)
91
//FIXME: use this constant
92
static const int MOVES_FOR_FIGHT = 3;
94
//! turn a list of stacks into an ordered list of armies
95
//! this is used for calculation and display purposes
96
static void orderArmies(std::list<Stack*> stacks, std::vector<Army*> &armies);
147
//! Turn a list of stacks into an ordered list of armies.
149
* @note This is used for calculation and display purposes.
151
static void orderArmies(std::list<Stack*> stacks,
152
std::vector<Army*> &armies);
154
std::map<Uint32, Uint32> getInitialHPs() { return initial_hps; }
99
/** Does one fight round.
101
* @return false if the maximum number of fight rounds has been
102
* exceeded or one side has lost.
157
//! Calculates one round of the fight.
159
* @return false if the maximum number of fight rounds has been
160
* exceeded or one side has lost.
106
//! Calculates the attack/defense bonus of the armies
164
//! Calculates the attack/defense bonus of the armies.
107
165
void calculateBonus();
167
//! Calculates the base strength of the armies fighting in the battle.
108
168
void calculateBaseStrength(std::list<Fighter*> fighters);
170
//! Add the bonuses provided by terrain.
109
171
void calculateTerrainModifiers(std::list<Fighter*> fighters);
173
//! Add the bonuses by opponents.
110
174
void calculateModifiedStrengths (std::list<Fighter*>friendly,
111
175
std::list<Fighter*>enemy,
112
176
bool friendlyIsDefending,
113
177
Hero *strongestHero);
179
//! Subtract stack bonuses of the opponent.
114
180
void calculateFinalStrengths (std::list<Fighter*> friendly,
115
181
std::list<Fighter*> enemy);
117
/** This function just has two armies fight against each other. It
118
* applies the boni and several special boni to attacker and defender
119
* and calculates (rather rolls) the result.
121
* @param attacker the attacking army
122
* @param defender the defending army
184
* This function just has two armies fight against each other. It
185
* applies the bonuses and several special bonuses to attacker and
186
* defender and calculates the result.
188
* @param attacker The attacking army.
189
* @param defender The defending army.
124
191
void fightArmies(Fighter* attacker, Fighter* defender);
126
//! removes a fighter from the fighting lists (d_att_close etc.)
193
//! Removes an army from the fight.
127
194
void remove(Fighter* f);
196
void fillInInitialHPs();
129
201
std::list<Stack*> d_attackers;
130
204
std::list<Stack*> d_defenders;
206
//!The attackers in the fight.
132
207
std::list<Fighter*> d_att_close;
209
//! The defenders in the fight.
133
210
std::list<Fighter*> d_def_close;
212
std::map<Uint32, Uint32> initial_hps;
214
//! The list of fight events that gets calculated.
135
215
std::list<FightItem> d_actions;
217
//! The round of the fight.
220
//! The result of the fight.
223
//! The kind of fight.
139
224
FightType d_type;
226
//! Whether or not we're rolling 24-sided dice or 20 sided dice.
140
227
bool d_intense_combat;