1 /* 2 * Copyright 2010-2014 OpenXcom Developers. 3 * 4 * This file is part of OpenXcom. 5 * 6 * OpenXcom is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * OpenXcom is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #ifndef OPENXCOM_ALIENBAISTATE_H 20 #define OPENXCOM_ALIENBAISTATE_H 21 22 #include "BattleAIState.h" 23 #include "Position.h" 24 #include <vector> 25 26 namespace OpenXcom 27 { 28 29 class SavedBattleGame; 30 class BattleUnit; 31 class BattlescapeState; 32 class Node; 33 34 /** 35 * This class is used by the BattleUnit AI. 36 */ 37 class AlienBAIState : public BattleAIState 38 { 39 protected: 40 BattleUnit *_aggroTarget; 41 int _knownEnemies, _visibleEnemies, _spottingEnemies; 42 int _escapeTUs, _ambushTUs, _reserveTUs; 43 BattleAction *_escapeAction, *_ambushAction, *_attackAction, *_patrolAction, *_psiAction; 44 bool _rifle, _melee, _blaster; 45 bool _traceAI, _wasHit, _didPsi; 46 int _AIMode, _intelligence, _closestDist; 47 Node *_fromNode, *_toNode; 48 std::vector<int> _reachable, _reachableWithAttack; 49 public: 50 /// Creates a new AlienBAIState linked to the game and a certain unit. 51 AlienBAIState(SavedBattleGame *save, BattleUnit *unit, Node *node); 52 /// Cleans up the AlienBAIState. 53 ~AlienBAIState(); 54 /// Loads the AI state from YAML. 55 void load(const YAML::Node& node); 56 /// Saves the AI state to YAML. 57 YAML::Node save() const; 58 /// Enters the state. 59 void enter(); 60 /// Exits the state. 61 void exit(); 62 /// Runs state functionality every AI cycle. 63 void think(BattleAction *action); 64 /// Sets the "unit was hit" flag true. 65 void setWasHit(); 66 /// Gets whether the unit was hit. 67 bool getWasHit() const; 68 /// setup a patrol objective. 69 void setupPatrol(); 70 /// setup an ambush objective. 71 void setupAmbush(); 72 /// setup a combat objective. 73 void setupAttack(); 74 /// setup an escape objective. 75 void setupEscape(); 76 /// count how many xcom/civilian units are known to this unit. 77 int countKnownTargets() const; 78 /// count how many known XCom units are able to see this unit. 79 int getSpottingUnits(Position pos) const; 80 /// Selects the nearest target we can see, and return the number of viable targets. 81 int selectNearestTarget(); 82 /// Selects the closest known xcom unit for ambushing. 83 bool selectClosestKnownEnemy(); 84 /// Selects a random known target. 85 bool selectRandomTarget(); 86 /// Selects the nearest reachable point relative to a target. 87 bool selectPointNearTarget(BattleUnit *target, int maxTUs) const; 88 /// re-evaluate our situation, and make a decision from our available options. 89 void evaluateAIMode(); 90 /// Selects a suitable position from which to attack. 91 bool findFirePoint(); 92 /// Decides if we should throw a grenade/launch a missile to this position. 93 bool explosiveEfficacy(Position targetPos, BattleUnit *attackingUnit, int radius, int diff, bool grenade = false) const; 94 /// Attempts to take a melee attack/charge an enemy we can see. 95 void meleeAction(); 96 /// Attempts to fire a waypoint projectile at an enemy we, or one of our teammates sees. 97 void wayPointAction(); 98 /// Attempts to fire at an enemy we can see. 99 void projectileAction(); 100 /// Selects a fire method. 101 void selectFireMethod(); 102 /// Attempts to throw a grenade at an enemy (or group of enemies) we can see. 103 void grenadeAction(); 104 /// Performs a psionic attack. 105 bool psiAction(); 106 /// Performs a melee attack action. 107 void meleeAttack(); 108 bool validTarget(BattleUnit* unit, bool assessDanger, bool includeCivs) const; 109 }; 110 111 } 112 113 #endif 114