Advanced Strategic Command
attack.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of Advanced Strategic Command; http://www.asc-hq.de
8  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; see the file COPYING. If not, write to the
22  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  Boston, MA 02111-1307 USA
24 */
25 
26 
27 
28 #ifndef attackH
29 #define attackH
30 
31 #include "typen.h"
32 #include "vehicletype.h"
33 #include "vehicle.h"
34 #include "buildings.h"
35 #include "objects.h"
36 #include "explosivemines.h"
37 
38 #include "actions/context.h"
39 
40 
43 {
44  virtual bool checkHemming ( Vehicle* d_eht, int direc );
45  protected:
47  public:
48 
49  static const int experienceIcons = 24;
50 
52  float strength_experience ( int experience );
53  float strength_damage ( int damage );
54  float strength_attackbonus ( int abonus );
55  float strength_hemming ( int ax, int ay, Vehicle* d_eht );
56  float defense_experience ( int experience );
57  float defense_defensebonus ( int defensebonus );
58  static float getHemmingFactor ( int relDir ); // 0 <= reldir <= sidenum-2
59  int getIconIndex(int experience, bool offensive );
60  virtual ~AttackFormula() {} ;
61 };
62 
63 
64 
65 class tunitattacksobject;
66 class tmineattacksunit;
68 class tunitattacksunit;
69 
71 {
72  public:
73  virtual void visit( tunitattacksobject& battle ) = 0;
74  virtual void visit( tmineattacksunit& battle ) = 0;
75  virtual void visit( tunitattacksbuilding& battle ) = 0;
76  virtual void visit( tunitattacksunit& battle ) = 0;
77  virtual ~FightVisitor()
78  {}
79  ;
80 };
81 
82 
83 class tfight : public AttackFormula
84 {
85  protected:
86  tfight ( GameMap* gamemap) : AttackFormula( gamemap ) {};
87  int dist;
88 
89  public:
90  struct tavalues
91  {
93  {}
94  ;
95  int strength;
96  int armor;
97  int damage;
102  float hemming;
103  int weapnum;
105  int color;
107  int kamikaze;
108  int height;
110  }
111  av, dv;
112 
114  void calc ( void ) ;
115 
117  virtual void setresult( const Context& context ) = 0;
118 
119  virtual void visit ( FightVisitor& visitor ) = 0;
120 
121  virtual int getAttackingPlayer() = 0;
122  virtual int getDefendingPlayer() = 0;
123 
124 };
125 
127 {
128  protected:
130 
133  {
134  return _attackingunit->getOwner();
135  };
136  public:
138  {
139  return _attackingunit;
140  };
141 };
142 
144 {
145  Vehicle* _attackedunit;
146 
147  Vehicle** _pattackingunit;
148  Vehicle** _pattackedunit;
149 
150  int _respond;
151  bool reactionfire;
152 
153  protected:
154 
155  public:
160  tunitattacksunit ( Vehicle* &attackingunit, Vehicle* &attackedunit, bool respond = true, int weapon = -1, bool reactionfire = false );
161  void setup ( Vehicle* &attackingunit, Vehicle* &attackedunit, bool respond, int weapon );
162  void setresult( const Context& context );
163 
164  void visit ( FightVisitor& visitor )
165  {
166  visitor.visit( *this );
167  };
169  {
170  return _attackedunit;
171  };
172 
174  {
175  return _attackedunit->getOwner();
176  };
177 
178 };
179 
181 {
182  Building* _attackedbuilding;
183  int _x, _y;
184  public:
186  {
187  return _attackingunit->getOwner();
188  };
190  {
191  return _attackedbuilding->getOwner();
192  };
193 
197  tunitattacksbuilding ( Vehicle* attackingunit, int x, int y, int weapon = -1);
198  void setup ( Vehicle* attackingunit, int x, int y, int weapon );
199  void setresult( const Context& context );
200 
201  void visit ( FightVisitor& visitor )
202  {
203  visitor.visit( *this );
204  };
206  {
207  return _attackedbuilding;
208  };
209 };
210 
211 
212 class tmineattacksunit : public tfight
213 {
214  MapField* _mineposition;
215  Vehicle* _attackedunit;
216  int _minenum;
217  Vehicle** _pattackedunit;
218 
219  MapCoordinate position;
220 
221  public:
223  {
224  return 8;
225  };
227  {
228  return _attackedunit->getOwner();
229  };
230 
231 
237  tmineattacksunit ( const MapCoordinate& mineposition, int minenum, Vehicle* &attackedunit );
238  void setup ( const MapCoordinate& position, int minenum, Vehicle* &attackedunit );
239  void setresult( const Context& context );
240 
241  Mine* getFirstMine();
242 
243  void visit ( FightVisitor& visitor )
244  {
245  visitor.visit( *this );
246  };
247 
249  {
250  return _attackedunit;
251  };
252 };
253 
255 {
256  MapField* targetField;
257  Object* _obji;
258  int _x, _y;
259 
260  public:
262  {
263  return _attackingunit->getOwner();
264  };
266  {
267  return 8;
268  };
269 
276  tunitattacksobject ( Vehicle* attackingunit, int obj_x, int obj_y, int weapon = -1 );
277  void setup ( Vehicle* attackingunit, int obj_x, int obj_y, int weapon );
278  void setresult( const Context& context );
279 
281  {
282  return _obji;
283  };
284  void visit ( FightVisitor& visitor )
285  {
286  visitor.visit( *this );
287  };
288 };
289 
292 {
293  public:
294  int count;
295  int strength[16];
296  int num[16];
297  int typ[16];
298 
299  enum Target { nothing, vehicle, building, object } target;
300 };
301 
302 
303 
304 
306 extern AttackWeap* attackpossible( const Vehicle* attacker, int x, int y);
307 
308 
309 
322 extern bool attackpossible2u( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL, int targetheight = -1); // distance is not evaluated
323 
324 
337 extern bool attackpossible28( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL, int targetHeight = -1); // distance is fixed as 1 field
338 
339 
347 extern bool attackpossible2n( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL );
348 
350 extern bool vehicleplattfahrbar( const Vehicle* vehicle, const MapField* field );
351 
352 
354 class WeapDist
355 {
356  public:
357  static float getWeaponStrength ( const SingleWeapon* weap, int targetFieldWeather = 0, int dist =-1, int attacker_height =-1, int defender_height = -1, int reldiff = -1 );
358 };
359 
360 
361 #endif
362 
363 
364 
static const int experienceIcons
Definition: attack.h:49
int defensebonus
Definition: attack.h:100
enum AttackWeap::Target target
UnitAttacksSomething(GameMap *gamemap)
Definition: attack.h:129
Building * getTarget()
Definition: attack.h:205
struct tfight::tavalues dv
void setup(Vehicle *attackingunit, int obj_x, int obj_y, int weapon)
Definition: attack.cpp:732
the core formula, which weighs the different factory that go into the calculation ...
Definition: attack.h:42
Structure to store the weapons which a unit can use to perform an attack.
Definition: attack.h:291
struct tfight::tavalues av
virtual void visit(FightVisitor &visitor)=0
int strength[16]
Definition: attack.h:295
float hemming
Definition: attack.h:102
void visit(FightVisitor &visitor)
Definition: attack.h:243
int getOwner() const
returns the number of the player this vehicle/building belongs to
Vehicle * getTarget()
Definition: attack.h:168
virtual int getDefendingPlayer()=0
Vehicle * getTarget()
Definition: attack.h:248
void visit(FightVisitor &visitor)
Definition: attack.h:164
virtual ~FightVisitor()
Definition: attack.h:77
int getAttackingPlayer()
Definition: attack.h:185
float strength_damage(int damage)
Definition: attack.cpp:116
virtual int getAttackingPlayer()=0
int getDefendingPlayer()
Definition: attack.h:226
tunitattacksunit(Vehicle *&attackingunit, Vehicle *&attackedunit, bool respond=true, int weapon=-1, bool reactionfire=false)
Definition: attack.cpp:279
The buildings which a placed on the map.
a single field of the map
Definition: mapfield.h:26
int getIconIndex(int experience, bool offensive)
Definition: attack.cpp:156
void calc(void)
Performs the calculation of the attack. The result is only stored in the av and dv structures and is ...
Definition: attack.cpp:178
int experience_offensive
Definition: attack.h:98
int getDefendingPlayer()
Definition: attack.h:265
void visit(FightVisitor &visitor)
Definition: attack.h:201
AttackFormula(GameMap *gamemap)
Definition: attack.cpp:49
void setup(Vehicle *attackingunit, int x, int y, int weapon)
Definition: attack.cpp:516
void setresult(const Context &context)
Writes the result of the attack calculation to the actual units.
Definition: attack.cpp:815
GameMap * gamemap
Definition: attack.h:46
tunitattacksobject(Vehicle *attackingunit, int obj_x, int obj_y, int weapon=-1)
Definition: attack.cpp:726
int getDefendingPlayer()
Definition: attack.h:189
tunitattacksbuilding(Vehicle *attackingunit, int x, int y, int weapon=-1)
Definition: attack.cpp:509
int getAttackingPlayer()
Definition: attack.h:132
void setresult(const Context &context)
Writes the result of the attack calculation to the actual units.
Definition: attack.cpp:693
void visit(FightVisitor &visitor)
Definition: attack.h:284
Coordinate on the twodimensional map.
Definition: typen.h:202
int dist
Definition: attack.h:86
static float getWeaponStrength(const SingleWeapon *weap, int targetFieldWeather=0, int dist=-1, int attacker_height=-1, int defender_height=-1, int reldiff=-1)
Definition: attack.cpp:1092
bool attackpossible2u(const Vehicle *attacker, const Vehicle *target, AttackWeap *attackweap=NULL, int targetheight=-1)
Is attacker able to attack target ? Distance is not evaluated.
Definition: attack.cpp:939
float strength_experience(int experience)
Definition: attack.cpp:121
void setresult(const Context &context)
Writes the result of the attack calculation to the actual units.
Definition: attack.cpp:596
void setresult(const Context &context)
Writes the result of the attack calculation to the actual units.
Definition: attack.cpp:445
A single weapon of a #Vehicletype.
Definition: vehicletype.h:100
int num[16]
Definition: attack.h:296
Vehicle * _attackingunit
Definition: attack.h:129
float strength_attackbonus(int abonus)
Definition: attack.cpp:143
virtual void visit(tunitattacksobject &battle)=0
int getAttackingPlayer()
Definition: attack.h:261
Definition: attack.h:83
int count
Definition: attack.h:294
Some very old system to calculate the weapon efficiency over a given distance.
Definition: attack.h:354
int typ[16]
Definition: attack.h:297
int getAttackingPlayer()
Definition: attack.h:222
Mine and Objects which can be placed on a map field.
virtual ~AttackFormula()
Definition: attack.h:60
int experience_defensive
Definition: attack.h:99
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
an instance of an object type (ObjectType) on the map
Definition: objects.h:46
static float getHemmingFactor(int relDir)
Definition: attack.cpp:79
bool attackpossible28(const Vehicle *attacker, const Vehicle *target, AttackWeap *attackweap=NULL, int targetHeight=-1)
Is attacker able to attack target ? Distance is assumed one field.
Definition: attack.cpp:983
Vehicle * getAttackingUnit()
Definition: attack.h:137
int getDefendingPlayer()
Definition: attack.h:173
void setup(const MapCoordinate &position, int minenum, Vehicle *&attackedunit)
Definition: attack.cpp:618
void setup(Vehicle *&attackingunit, Vehicle *&attackedunit, bool respond, int weapon)
Definition: attack.cpp:286
virtual void setresult(const Context &context)=0
Writes the result of the attack calculation to the actual units.
float defense_defensebonus(int defensebonus)
Definition: attack.cpp:150
tfight(GameMap *gamemap)
Definition: attack.h:86
Mine * getFirstMine()
Definition: attack.cpp:716
bool vehicleplattfahrbar(const Vehicle *vehicle, const MapField *field)
Can the vehicle drive across the field and destroy any unit there by moving over them?
Definition: attack.cpp:1069
AttackWeap * attackpossible(const Vehicle *attacker, int x, int y)
Is attacker able to attack anything in field x/y ?
Definition: attack.cpp:842
float strength_hemming(int ax, int ay, Vehicle *d_eht)
Definition: attack.cpp:95
bool attackpossible2n(const Vehicle *attacker, const Vehicle *target, AttackWeap *attackweap=NULL)
Is attacker able to attack target ? Actual distance used.
Definition: attack.cpp:1026
float defense_experience(int experience)
Definition: attack.cpp:132
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
Object * getTarget()
Definition: attack.h:280
tmineattacksunit(const MapCoordinate &mineposition, int minenum, Vehicle *&attackedunit)
Definition: attack.cpp:612