attack.h

Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00008     Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00009  
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014  
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019  
00020     You should have received a copy of the GNU General Public License
00021     along with this program; see the file COPYING. If not, write to the 
00022     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00023     Boston, MA  02111-1307  USA
00024 */
00025 
00026 
00027 
00028 #ifndef attackH
00029 #define attackH
00030 
00031 #include "typen.h"
00032 #include "vehicletype.h"
00033 #include "vehicle.h"
00034 #include "buildings.h"
00035 #include "objects.h"
00036 #include "explosivemines.h"
00037 
00038 #include "actions/context.h"
00039 
00040 
00042 class AttackFormula
00043 {
00044       virtual bool checkHemming ( Vehicle* d_eht, int direc );
00045    protected:
00046       GameMap* gamemap;
00047    public:
00048       AttackFormula( GameMap* gamemap );
00049       float strength_experience ( int experience );
00050       float strength_damage ( int damage );
00051       float strength_attackbonus ( int abonus );
00052       float strength_hemming ( int  ax,  int ay,  Vehicle* d_eht );
00053       float defense_experience ( int experience );
00054       float defense_defensebonus ( int defensebonus );
00055       static float getHemmingFactor ( int relDir );  // 0 <= reldir <= sidenum-2
00056       virtual ~AttackFormula()
00057       {}
00058       ;
00059 };
00060 
00061 
00062 
00063 class tunitattacksobject;
00064 class tmineattacksunit;
00065 class tunitattacksbuilding;
00066 class tunitattacksunit;
00067 
00068 class FightVisitor
00069 {
00070    public:
00071       virtual void visit( tunitattacksobject& battle ) = 0;
00072       virtual void visit( tmineattacksunit& battle ) = 0;
00073       virtual void visit( tunitattacksbuilding& battle ) = 0;
00074       virtual void visit( tunitattacksunit& battle ) = 0;
00075       virtual ~FightVisitor()
00076       {}
00077       ;
00078 };
00079 
00080 
00081 class tfight : public AttackFormula
00082 {
00083    protected:
00084       tfight ( GameMap* gamemap) : AttackFormula( gamemap ) {};
00085       int dist;
00086 
00087    public:
00088       struct tavalues
00089       {
00090          tavalues() : weapontype(-1)
00091          {}
00092          ;
00093          int strength;
00094          int armor;
00095          int damage;
00096          int experience;
00097          int defensebonus;
00098          int attackbonus;
00099          float hemming;
00100          int weapnum;
00101          int weapcount;
00102          int color;
00103          int initiative;
00104          int kamikaze;
00105          int height;
00106          int weapontype;
00107       }
00108       av, dv;
00109 
00111       void calc ( void ) ;
00112 
00114       virtual void setresult( const Context& context ) = 0;
00115 
00116       virtual void visit ( FightVisitor& visitor ) = 0;
00117 
00118       virtual int getAttackingPlayer() = 0;
00119       virtual int getDefendingPlayer() = 0;
00120       
00121 };
00122 
00123 class UnitAttacksSomething : public tfight
00124 {
00125    protected:
00126       UnitAttacksSomething( GameMap* gamemap ) : tfight( gamemap ) {};
00127       
00128       Vehicle* _attackingunit;
00129       int getAttackingPlayer()
00130       {
00131          return _attackingunit->getOwner();
00132       };
00133    public:
00134       Vehicle* getAttackingUnit()
00135       {
00136          return _attackingunit;
00137       };
00138 };
00139 
00140 class tunitattacksunit : public UnitAttacksSomething
00141 {
00142       Vehicle* _attackedunit;
00143 
00144       Vehicle** _pattackingunit;
00145       Vehicle** _pattackedunit;
00146 
00147       int _respond;
00148       bool reactionfire;
00149 
00150    protected:
00151 
00152    public:
00157       tunitattacksunit ( Vehicle* &attackingunit, Vehicle* &attackedunit, bool respond = true, int weapon = -1, bool reactionfire = false );
00158       void setup ( Vehicle* &attackingunit, Vehicle* &attackedunit, bool respond, int weapon );
00159       void setresult( const Context& context );
00160 
00161       void visit ( FightVisitor& visitor )
00162       {
00163          visitor.visit( *this );
00164       };
00165       Vehicle* getTarget()
00166       {
00167          return _attackedunit;
00168       };
00169 
00170       int getDefendingPlayer()
00171       {
00172          return _attackedunit->getOwner();
00173       };
00174       
00175 };
00176 
00177 class tunitattacksbuilding : public UnitAttacksSomething
00178 {
00179       Building* _attackedbuilding;
00180       int _x, _y;
00181    public:
00182       int getAttackingPlayer()
00183       {
00184          return _attackingunit->getOwner();
00185       };
00186       int getDefendingPlayer()
00187       {
00188          return _attackedbuilding->getOwner();
00189       };
00190 
00194       tunitattacksbuilding ( Vehicle* attackingunit, int x, int y, int weapon = -1);
00195       void setup ( Vehicle* attackingunit, int x, int y, int weapon );
00196       void setresult( const Context& context );
00197 
00198       void visit ( FightVisitor& visitor )
00199       {
00200          visitor.visit( *this );
00201       };
00202       Building* getTarget()
00203       {
00204          return _attackedbuilding;
00205       };
00206 };
00207 
00208 
00209 class tmineattacksunit : public tfight
00210 {
00211       MapField* _mineposition;
00212       Vehicle* _attackedunit;
00213       int _minenum;
00214       Vehicle** _pattackedunit;
00215 
00216       MapCoordinate position;
00217       
00218    public:
00219       int getAttackingPlayer()
00220       {
00221          return 8;
00222       };
00223       int getDefendingPlayer()
00224       {
00225          return _attackedunit->getOwner();
00226       };
00227 
00228 
00234       tmineattacksunit ( const MapCoordinate& mineposition, int minenum, Vehicle* &attackedunit );
00235       void setup ( const MapCoordinate& position, int minenum, Vehicle* &attackedunit );
00236       void setresult( const Context& context );
00237 
00238       Mine* getFirstMine();
00239 
00240       void visit ( FightVisitor& visitor )
00241       {
00242          visitor.visit( *this );
00243       };
00244 
00245       Vehicle* getTarget()
00246       {
00247          return _attackedunit;
00248       };
00249 };
00250 
00251 class tunitattacksobject : public UnitAttacksSomething
00252 {
00253       MapField*       targetField;
00254       Object*      _obji;
00255       int _x, _y;
00256 
00257    public:
00258       int getAttackingPlayer()
00259       {
00260          return _attackingunit->getOwner();
00261       };
00262       int getDefendingPlayer()
00263       {
00264          return 8;
00265       };
00266 
00273       tunitattacksobject ( Vehicle* attackingunit, int obj_x, int obj_y, int weapon = -1 );
00274       void setup ( Vehicle* attackingunit, int obj_x, int obj_y, int weapon );
00275       void setresult( const Context& context );
00276       
00277       Object* getTarget()
00278       {
00279          return _obji;
00280       };
00281       void visit ( FightVisitor& visitor )
00282       {
00283          visitor.visit( *this );
00284       };
00285 };
00286 
00288 class AttackWeap
00289 {
00290    public:
00291       int          count;
00292       int          strength[16];
00293       int          num[16];
00294       int          typ[16];
00295 
00296       enum Target { nothing, vehicle, building, object } target;
00297 };
00298 
00299 
00300 
00301 
00303 extern AttackWeap* attackpossible( const Vehicle* attacker, int x, int y);
00304 
00305 
00306 
00319 extern bool attackpossible2u( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL, int targetheight = -1);      // distance is not evaluated
00320 
00321 
00334 extern bool attackpossible28( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL, int targetHeight = -1);       // distance is fixed as 1 field
00335 
00336 
00344 extern bool attackpossible2n( const Vehicle* attacker, const Vehicle* target, AttackWeap* attackweap = NULL );
00345 
00347 extern bool vehicleplattfahrbar( const Vehicle* vehicle, const MapField* field );
00348 
00349 
00351 class WeapDist
00352 {
00353    public:
00354       static float getWeaponStrength ( const SingleWeapon* weap, int targetFieldWeather = 0, int dist =-1, int attacker_height =-1, int defender_height = -1, int reldiff = -1 );
00355 };
00356 
00357 
00358 #endif
00359 
00360 
00361 

Generated on Mon May 21 01:26:28 2012 for Advanced Strategic Command by  doxygen 1.5.1