1 /*************************************************************************** 2 * Mechanized Assault and Exploration Reloaded Projectfile * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the * 16 * Free Software Foundation, Inc., * 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 ***************************************************************************/ 19 20 #ifndef game_logic_attackjobH 21 #define game_logic_attackjobH 22 23 #include <vector> 24 #include <memory> 25 26 #include "utility/position.h" 27 28 class cMap; 29 class cPlayer; 30 class cNetMessage; 31 class cFx; 32 class cMenu; 33 class cServer; 34 class cClient; 35 class cUnit; 36 37 class cAttackJob 38 { 39 private: 40 static const int ROTATION_SPEED = 10; //rotate aggressor every X game time ticks 41 static const int FIRE_DELAY = 10; 42 static const int IMPACT_DELAY = 10; 43 static const int DESTROY_DELAY = 30; 44 45 46 int aggressorID; 47 int aggressorPlayerNr; 48 cPosition aggressorPosition; 49 int attackMode; 50 int muzzleType; 51 int attackPoints; 52 cPosition targetPosition; 53 54 cServer* const server; 55 cClient* const client; 56 std::vector<int> destroyedTargets; //not synced. only needed on server 57 std::vector<int> lockedTargets; //not synced. TODO: maybe necessary 58 59 int fireDir; 60 61 int counter; 62 enum eAJStates { S_ROTATING, S_PLAYING_MUZZLE, S_FIRING, S_EXPLODING, S_FINISHED }; 63 eAJStates state; 64 65 int calcFireDir(); 66 int calcTimeForRotation(); 67 cUnit* getAggressor(); 68 69 void lockTarget(); 70 void fire(); 71 std::unique_ptr<cFx> createMuzzleFx (cUnit* unit); 72 bool impact(); 73 bool impactCluster(); 74 bool impactSingle (const cPosition& position, std::vector<cUnit*>* avoidTargets = nullptr); 75 void destroyTarget(); 76 77 public: 78 /** 79 * selects a target unit from a map field, depending on the attack mode. 80 */ 81 static cUnit* selectTarget (const cPosition& position, char attackMode, const cMap& map, cPlayer* owner); 82 static void runAttackJobs (std::vector<cAttackJob*>& attackJobs); 83 84 cAttackJob (cServer* server, cUnit* aggressor, const cPosition& targetPosition); 85 cAttackJob (cClient* client, cNetMessage& message); 86 ~cAttackJob(); 87 88 std::unique_ptr<cNetMessage> serialize() const; 89 void run(); 90 bool finished() const; 91 }; 92 93 #endif // game_logic_attackjobH 94