File: attack.h

package info (click to toggle)
asc 2.6.1.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 81,740 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 604; perl: 138
file content (361 lines) | stat: -rw-r--r-- 10,972 bytes parent folder | download | duplicates (5)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*! \file attack.h
    \brief Interface for all the fighting routines of ASC. 
*/


/*
    This file is part of Advanced Strategic Command; http://www.asc-hq.de
    Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; see the file COPYING. If not, write to the 
    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
    Boston, MA  02111-1307  USA
*/



#ifndef attackH
#define attackH

#include "typen.h"
#include "vehicletype.h"
#include "vehicle.h"
#include "buildings.h"
#include "objects.h"
#include "explosivemines.h"

#include "actions/context.h"


//! the core formula, which weighs the different factory that go into the calculation 
class AttackFormula
{
      virtual bool checkHemming ( Vehicle* d_eht, int direc );
   protected:
      GameMap* gamemap;
   public:
      AttackFormula( GameMap* gamemap );
      float strength_experience ( int experience );
      float strength_damage ( int damage );
      float strength_attackbonus ( int abonus );
      float strength_hemming ( int  ax,  int ay,  Vehicle* d_eht );
      float defense_experience ( int experience );
      float defense_defensebonus ( int defensebonus );
      static float getHemmingFactor ( int relDir );  // 0 <= reldir <= sidenum-2
      virtual ~AttackFormula()
      {}
      ;
};



class tunitattacksobject;
class tmineattacksunit;
class tunitattacksbuilding;
class tunitattacksunit;

class FightVisitor
{
   public:
      virtual void visit( tunitattacksobject& battle ) = 0;
      virtual void visit( tmineattacksunit& battle ) = 0;
      virtual void visit( tunitattacksbuilding& battle ) = 0;
      virtual void visit( tunitattacksunit& battle ) = 0;
      virtual ~FightVisitor()
      {}
      ;
};


class tfight : public AttackFormula
{
   protected:
      tfight ( GameMap* gamemap) : AttackFormula( gamemap ) {};
      int dist;

   public:
      struct tavalues
      {
         tavalues() : weapontype(-1)
         {}
         ;
         int strength;
         int armor;
         int damage;
         int experience;
         int defensebonus;
         int attackbonus;
         float hemming;
         int weapnum;
         int weapcount;
         int color;
         int initiative;
         int kamikaze;
         int height;
         int weapontype;
      }
      av, dv;

      //! Performs the calculation of the attack. The result is only stored in the av and dv structures and is not written to the map
      void calc ( void ) ;

      //! Writes the result of the attack calculation to the actual units.
      virtual void setresult( const Context& context ) = 0;

      virtual void visit ( FightVisitor& visitor ) = 0;

      virtual int getAttackingPlayer() = 0;
      virtual int getDefendingPlayer() = 0;
      
};

class UnitAttacksSomething : public tfight
{
   protected:
      UnitAttacksSomething( GameMap* gamemap ) : tfight( gamemap ) {};
      
      Vehicle* _attackingunit;
      int getAttackingPlayer()
      {
         return _attackingunit->getOwner();
      };
   public:
      Vehicle* getAttackingUnit()
      {
         return _attackingunit;
      };
};

class tunitattacksunit : public UnitAttacksSomething
{
      Vehicle* _attackedunit;

      Vehicle** _pattackingunit;
      Vehicle** _pattackedunit;

      int _respond;
      bool reactionfire;

   protected:

   public:
      /*! Calculates the fight if one unit attacks another units.
          \param respond Does the unit that is being attacked retalliate ?
          \param weapon  The number of the weapon which the attacking unit attacks with. If it is -1, the best weapon is chosen.
      */
      tunitattacksunit ( Vehicle* &attackingunit, Vehicle* &attackedunit, bool respond = true, int weapon = -1, bool reactionfire = false );
      void setup ( Vehicle* &attackingunit, Vehicle* &attackedunit, bool respond, int weapon );
      void setresult( const Context& context );

      void visit ( FightVisitor& visitor )
      {
         visitor.visit( *this );
      };
      Vehicle* getTarget()
      {
         return _attackedunit;
      };

      int getDefendingPlayer()
      {
         return _attackedunit->getOwner();
      };
      
};

class tunitattacksbuilding : public UnitAttacksSomething
{
      Building* _attackedbuilding;
      int _x, _y;
   public:
      int getAttackingPlayer()
      {
         return _attackingunit->getOwner();
      };
      int getDefendingPlayer()
      {
         return _attackedbuilding->getOwner();
      };

      /*! Calculates the fight if one unit attacks the building at coordinate x/y.
          \param weapon  The number of the weapon which the attacking unit attacks with. If it is -1, the best weapon is chosen.
      */
      tunitattacksbuilding ( Vehicle* attackingunit, int x, int y, int weapon = -1);
      void setup ( Vehicle* attackingunit, int x, int y, int weapon );
      void setresult( const Context& context );

      void visit ( FightVisitor& visitor )
      {
         visitor.visit( *this );
      };
      Building* getTarget()
      {
         return _attackedbuilding;
      };
};


class tmineattacksunit : public tfight
{
      MapField* _mineposition;
      Vehicle* _attackedunit;
      int _minenum;
      Vehicle** _pattackedunit;

      MapCoordinate position;
      
   public:
      int getAttackingPlayer()
      {
         return 8;
      };
      int getDefendingPlayer()
      {
         return _attackedunit->getOwner();
      };


      /*! Calculates the fight if a unit drives onto a mine.
          \param mineposition The field on which the mine was placed
          \param minenum The number of a specific mine which explodes. If -1 , all mines on this field which are able to attack the unit will explode.
          \param attackedunit The unit which moved onto the minefield.
      */
      tmineattacksunit ( const MapCoordinate& mineposition, int minenum, Vehicle* &attackedunit );
      void setup ( const MapCoordinate& position, int minenum, Vehicle* &attackedunit );
      void setresult( const Context& context );

      Mine* getFirstMine();

      void visit ( FightVisitor& visitor )
      {
         visitor.visit( *this );
      };

      Vehicle* getTarget()
      {
         return _attackedunit;
      };
};

class tunitattacksobject : public UnitAttacksSomething
{
      MapField*       targetField;
      Object*      _obji;
      int _x, _y;

   public:
      int getAttackingPlayer()
      {
         return _attackingunit->getOwner();
      };
      int getDefendingPlayer()
      {
         return 8;
      };

      /*! Calculates the fight if one unit attacks the objects at coordinate x/y.
          \param attackingunit the attacking unit
          \param obj_x the X coordinate of the object on the map
          \param obj_y the Y coordinate of the object on the map
          \param weapon  The number of the weapon which the attacking unit attacks with. If it is -1, the best weapon is chosen.
      */
      tunitattacksobject ( Vehicle* attackingunit, int obj_x, int obj_y, int weapon = -1 );
      void setup ( Vehicle* attackingunit, int obj_x, int obj_y, int weapon );
      void setresult( const Context& context );
      
      Object* getTarget()
      {
         return _obji;
      };
      void visit ( FightVisitor& visitor )
      {
         visitor.visit( *this );
      };
};

//! Structure to store the weapons which a unit can use to perform an attack. \sa attackpossible
class AttackWeap
{
   public:
      int          count;
      int          strength[16];
      int          num[16];
      int          typ[16];

      enum Target { nothing, vehicle, building, object } target;
};




//! \brief Is attacker able to attack anything in field x/y ?
extern AttackWeap* attackpossible( const Vehicle* attacker, int x, int y);



/*! \brief Is attacker able to attack target ? Distance is not evaluated.
 
     The distance is not evaluated. The routine is used for the movement routines for example,
     because the current distance of units A and B is not relevant for the check whether unit
     A can move across the field where B is standing.
 
     \param attacker the attacking unit
     \param target   the unit that is being attacked
     \param attackweap if != NULL, detailed information about the weapons which can perform
                          the attack are written to attackweap
     \param targetHeight if != -1 , assume the target unit was on this height (bitmapped!)
 */
extern bool attackpossible2u( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL, int targetheight = -1);      // distance is not evaluated


/*! \brief Is attacker able to attack target ? Distance is assumed one field.
 
     The distance is assumed to be 1 field. The routine is used for the movement routines for 
     example, because units moving next to enemies get a movement malus.
     Does not evaluate any diplomatic states
 
     \param attacker the attacking unit
     \param target   the unit that is being attacked
     \param attackweap if != NULL, detailed information about the weapons which can perform
                          the attack are written to attackweap
     \param targetHeight if != -1 , assume the target unit was on this height (bitmapped!)
*/
extern bool attackpossible28( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL, int targetHeight = -1);       // distance is fixed as 1 field


/*! \brief Is attacker able to attack target ? Actual distance used.
 
     \param attacker the attacking unit
     \param target   the unit that is being attacked
     \param attackweap if != NULL, detailed information about the weapons which can perform
                          the attack are written to attackweap
*/
extern bool attackpossible2n( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL );

//! Can the vehicle drive across the field and destroy any unit there by moving over them?
extern bool vehicleplattfahrbar( const Vehicle* vehicle, const MapField* field );


//! Some very old system to calculate the weapon efficiency over a given distance.
class WeapDist
{
   public:
      static float getWeaponStrength ( const SingleWeapon* weap, int targetFieldWeather = 0, int dist =-1, int attacker_height =-1, int defender_height = -1, int reldiff = -1 );
};


#endif