~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

Viewing changes to src/fight.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2001, 2002, 2003 Michael Bartl
 
2
// Copyright (C) 2001, 2002, 2004, 2005, 2006 Ulf Lorenz
 
3
// Copyright (C) 2004 Bryan Duff
 
4
// Copyright (C) 2006 Andrea Paternesi
 
5
// Copyright (C) 2007, 2008 Ben Asselstine
 
6
// Copyright (C) 2008 Ole Laursen
 
7
//
1
8
//  This program is free software; you can redistribute it and/or modify
2
9
//  it under the terms of the GNU General Public License as published by
3
10
//  the Free Software Foundation; either version 2 of the License, or
10
17
//
11
18
//  You should have received a copy of the GNU General Public License
12
19
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
21
//  02110-1301, USA.
14
22
 
15
23
#ifndef FIGHT_H
16
24
#define FIGHT_H
18
26
#include <SDL_types.h>
19
27
#include <list>
20
28
#include <vector>
 
29
#include <map>
21
30
 
22
31
class Stack;
23
32
class Fighter;
24
33
class Hero;
25
34
class Army;
26
35
 
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.
29
 
  */
 
36
//! A description of a round of casualties during a Fight.
 
37
/** 
 
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.
 
40
 */
30
41
struct FightItem
31
42
{
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.
 
44
  int turn;
 
45
  //! The id of the army who was attacked in this event.
 
46
  Uint32 id;
 
47
  //! The amount of damage that the army sustained.
 
48
  int damage;
35
49
};
36
50
 
37
51
 
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.
43
 
  *
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.
49
 
  */
50
 
 
 
52
//! Calculate the outcome of a battle.
 
53
/** 
 
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.
 
59
 *
 
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.
 
65
 */
51
66
class Fight
52
67
{
53
68
    public:
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};
57
 
 
58
 
        /** Initializes a fight between two stacks
59
 
          * 
60
 
          * @param attacker         the attacking stack
61
 
          * @param defender         the defending stack
62
 
          * @param type             optionally heal all stacks afterwards
63
 
          */
 
70
        enum Result {
 
71
          //! There was no winner.
 
72
          /**
 
73
           * Although it is in the enumeration, every fight should always
 
74
           * have a winner.  No draws allowed because MAX_ROUNDS is 0.
 
75
           */
 
76
          DRAW = 0, 
 
77
 
 
78
          //! The attacking list of stacks won the battle.
 
79
          ATTACKER_WON = 1, 
 
80
 
 
81
          //! The defending list of stacks won the battle.
 
82
          DEFENDER_WON = 2
 
83
        };
 
84
 
 
85
        //! The kind of fight.  Whether the outcome is realized or not.
 
86
        enum FightType {
 
87
          //! The fight doesn't mean anything, it's just to see who would win.
 
88
          /**
 
89
           * @note This value is used to assist in the implementation of the
 
90
           *       `Miltary Advisor' feature.
 
91
           */
 
92
          FOR_KICKS = 0, 
 
93
 
 
94
          //! The fight is real.  If an army dies, it stays dead.
 
95
          FOR_KEEPS = 1
 
96
        };
 
97
 
 
98
        //! Make a new fight between two lists of stacks.
 
99
        /**
 
100
         * @param attacker         The list of attacking stacks.
 
101
         * @param defender         The list of defending stacks
 
102
         * @param type             Optionally heal all stacks afterwards.
 
103
         */
64
104
        Fight(Stack* attacker, Stack* defender, FightType type = FOR_KEEPS);
 
105
 
 
106
        // construct from serialized action
 
107
        Fight(std::list<Stack*> attackers, std::list<Stack*> defenders,
 
108
              std::list<FightItem> history);
 
109
        
 
110
        //! Destructor.
65
111
        ~Fight();
66
112
 
67
 
        
68
 
        //! Does the actual fight
 
113
        //! Determine the outcome of the fight.
 
114
        /**
 
115
         * This method fills out a set of FightItem events in d_actions.
 
116
         *
 
117
         * @param intense   Whether or not to Use 24 sided dice instead of 
 
118
         *                  20 sided dice.  Makes battles harder to win when 
 
119
         *                  set to True.
 
120
         */
69
121
        void battle(bool intense);
70
122
 
71
 
 
72
 
        //! Returns the result of the fight
 
123
        void battleFromHistory();
 
124
        
 
125
        //! Returns the result of the fight.
73
126
        Result getResult() const {return d_result;}
74
127
 
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;};
77
130
        
78
 
        //! Returns the participating attacker stacks
 
131
        //! Returns the participating attacker stacks.
79
132
        std::list<Stack*> getAttackers() const {return d_attackers;}
80
133
 
81
 
        //! Returns the participating defender stacks
 
134
        //! Returns the participating defender stacks.
82
135
        std::list<Stack*> getDefenders() const {return d_defenders;}
83
136
        
 
137
        //! Get the modified strength bonus of the given Army unit.
 
138
        Uint32 getModifiedStrengthBonus(Army *a);
84
139
 
85
140
        // CONSTANTS
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.
 
142
        /**
 
143
         * @note If this is 0, then there is no maximum.
 
144
         */
88
145
        static const int MAX_ROUNDS = 0;
89
146
 
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;
93
 
 
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);
97
 
 
 
147
        //! Turn a list of stacks into an ordered list of armies.
 
148
        /**
 
149
         * @note This is used for calculation and display purposes.
 
150
         */
 
151
        static void orderArmies(std::list<Stack*> stacks, 
 
152
                                std::vector<Army*> &armies);
 
153
 
 
154
        std::map<Uint32, Uint32> getInitialHPs() { return initial_hps; }
 
155
        
98
156
    private:
99
 
        /** Does one fight round.
100
 
          *
101
 
          * @return false if the maximum number of fight rounds has been
102
 
          * exceeded or one side has lost.
103
 
          */
 
157
        //! Calculates one round of the fight.
 
158
        /** 
 
159
         * @return false if the maximum number of fight rounds has been
 
160
         * exceeded or one side has lost.
 
161
         */
104
162
        bool doRound();
105
163
 
106
 
        //! Calculates the attack/defense bonus of the armies
 
164
        //! Calculates the attack/defense bonus of the armies.
107
165
        void calculateBonus();
 
166
 
 
167
        //! Calculates the base strength of the armies fighting in the battle.
108
168
        void calculateBaseStrength(std::list<Fighter*> fighters);
 
169
 
 
170
        //! Add the bonuses provided by terrain.
109
171
        void calculateTerrainModifiers(std::list<Fighter*> fighters);
 
172
 
 
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);
 
178
 
 
179
        //! Subtract stack bonuses of the opponent.
114
180
        void calculateFinalStrengths (std::list<Fighter*> friendly, 
115
181
                                      std::list<Fighter*> enemy);
116
182
 
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.
120
 
          *
121
 
          * @param attacker     the attacking army
122
 
          * @param defender     the defending army
123
 
          */
 
183
        /** 
 
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.
 
187
         *
 
188
         * @param attacker     The attacking army.
 
189
         * @param defender     The defending army.
 
190
         */
124
191
        void fightArmies(Fighter* attacker, Fighter* defender);
125
192
 
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);
 
195
 
 
196
        void fillInInitialHPs();
 
197
        
128
198
        // DATA
 
199
 
 
200
        //! The attackers.
129
201
        std::list<Stack*> d_attackers;
 
202
 
 
203
        //! The defenders.
130
204
        std::list<Stack*> d_defenders;
131
205
        
 
206
        //!The attackers in the fight.
132
207
        std::list<Fighter*> d_att_close;
 
208
 
 
209
        //! The defenders in the fight.
133
210
        std::list<Fighter*> d_def_close;
 
211
 
 
212
        std::map<Uint32, Uint32> initial_hps;
134
213
        
 
214
        //! The list of fight events that gets calculated.
135
215
        std::list<FightItem> d_actions;
136
216
        
 
217
        //! The round of the fight.
137
218
        int d_turn;
 
219
 
 
220
        //! The result of the fight.
138
221
        Result d_result;
 
222
 
 
223
        //! The kind of fight.
139
224
        FightType d_type;
 
225
 
 
226
        //! Whether or not we're rolling 24-sided dice or 20 sided dice.
140
227
        bool d_intense_combat;
141
228
};
142
229