1 /* 2 * Shotgun Debugger 3 * Copyright 2005 Game Creation Society 4 * 5 * Programmed by Matt Sarnoff 6 * http://www.contrib.andrew.cmu.edu/~msarnoff 7 * http://www.gamecreation.org 8 * 9 * enemies.h - header file for enemy AI routines 10 * 11 * This program is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation; either version 2 14 * of the License, or (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 24 */ 25 26 #ifndef _ENEMIES_H_ 27 #define _ENEMIES_H_ 28 29 #include "sdb.h" 30 31 enum AI_STATES {ASLEEP, AWAKE, MOVING, ATTACKING}; 32 enum AI_TASKS {AIT_STOP, AIT_INVESTIGATE, AIT_ATTACK}; 33 34 class AI 35 { 36 public: AI()37 AI() { set(ASLEEP, 1, -1, 0, 0, 0); } AI(int obj,int tgt)38 AI(int obj, int tgt) { set(AWAKE, obj, tgt, 0, 0, 0); } AI(int obj,int tgt,int st,float sigr,float ad,float fov)39 AI(int obj, int tgt, int st, float sigr, float ad, float fov) { set(st, obj, tgt, sigr, ad, fov); } 40 void set(int st, int obj, int tgt, float sigr, float ad, float fov); update()41 virtual void update() {} 42 43 void angleCalculations(bool targetOrNode); 44 void distanceCalculation(bool targetOrNode); 45 bool wallOccludeCalculation(); 46 47 float getAngle(Vector2D pos); 48 float getAngleDiff(float a1, float a2); 49 float getDistance(Vector2D pos); 50 51 void setNodePriorities(Vector2D pos); 52 void setChildNodePriorities(vector<int> children, int priority); 53 State()54 int State() { return state; } Object()55 int Object() { return object; } Target()56 int Target() { return target; } 57 58 void setMoveTarget(Vector2D tgtPos, int tsk); 59 void updateMoveTarget(); 60 setState(int st)61 void setState(int st) { state = st; } 62 63 void sendAlertSignal(double dst); 64 65 //protected: 66 int state; // Asleep, awake, attacking 67 int object; // Object this AI controls 68 int target; // This AI's target 69 70 // Properties 71 float signalRadius; 72 float alertDistance; 73 float fieldOfVision; 74 75 bool hasMoveTarget; 76 Vector2D moveTarget; 77 int nodeTarget; 78 float targetReacquireTimer; 79 Vector2D ultimateMoveTarget; 80 vector<int> nodePriorities; 81 bool movingToNode; 82 83 float angleToTarget; 84 float angleDiff; 85 float distToTarget; 86 87 int task; 88 89 bool doSound; 90 }; 91 92 class KamikazeAI : public AI 93 { 94 public: KamikazeAI()95 KamikazeAI() : AI() { idleActionTimer = 0; } KamikazeAI(int obj,int tgt,int st,float sigr,float ad,float fov)96 KamikazeAI(int obj, int tgt, int st, float sigr, float ad, float fov) : AI(obj, tgt, st, sigr, ad, fov) { idleActionTimer = alertTimer = alertRotateSpeed = 0; } 97 98 void move(); 99 void update(); 100 101 void idleAnimations(); 102 void alertCheck(); 103 void lineOfSightBehavior(); 104 void attack(); 105 void nodeFollowBehavior(); 106 void targetDetect(); 107 108 float idleActionTimer; 109 float alertRotateSpeed; 110 float alertTimer; 111 }; 112 113 class TurretAI : public AI 114 { 115 public: TurretAI()116 TurretAI() : AI() { idleRotateDirection = 0; idleRotateLength = 1.75; setIdleRotation(); } TurretAI(int obj,int tgt,int st,float sigr,float ad,float fov)117 TurretAI(int obj, int tgt, int st, float sigr, float ad, float fov) : AI(obj, tgt, st, sigr, ad, fov) { idleRotateDirection = 0; idleRotateLength = 1.75; setIdleRotation(); } 118 119 void update(); 120 void setIdleRotation(); 121 private: 122 float idleRotateDirection; 123 float idleRotateTimer; 124 float idleRotateLength; 125 float attackTimer; 126 }; 127 128 class SlaveTurretAI : public AI 129 { 130 public: SlaveTurretAI()131 SlaveTurretAI() : AI() {} SlaveTurretAI(int obj,int tgt,int st,float sigr,float ad,float fov)132 SlaveTurretAI(int obj, int tgt, int st, float sigr, float ad, float fov) : AI(obj, tgt, st, sigr, ad, fov) {} 133 134 void update(); 135 }; 136 137 class HunterAI : public KamikazeAI 138 { 139 public: HunterAI()140 HunterAI() : KamikazeAI() { shootTimer = shotBurstLength = angleInaccuracy = inaccuracyTimer = pauseLength = pauseTimer = 0; } HunterAI(int obj,int tgt,int st,float sigr,float ad,float fov,float plm,float plr,float pdm,float pdr,float slm,float slr,float sdm,float sdr,float cdist,float aim,float ac)141 HunterAI(int obj, int tgt, int st, float sigr, float ad, float fov, float plm, float plr, float pdm, float pdr, float slm, float slr, float sdm, float sdr, float cdist, float aim, float ac) : KamikazeAI(obj, tgt, st, sigr, ad, fov) 142 { shootTimer = shotBurstLength = angleInaccuracy = inaccuracyTimer = pauseLength = pauseTimer = 0; pauseLengthMin = plm; 143 pauseLengthRand = plr; pauseDelayMin = pdm; pauseDelayRand = pdr; shootLengthMin = slm; shootLengthRand = slr; 144 shootDelayMin = sdm; shootDelayRand = sdr; closestDistance = cdist; angleInaccuracyMax = aim; angleCompensation = ac; strafePreference = frand()*1.0-0.5; anger = 1; } 145 146 void update(); 147 void move(); 148 void lineOfSightBehavior(); 149 void targetDetect(); 150 void alertCheck(); 151 152 // Properties 153 float pauseLengthRand, pauseLengthMin; 154 float pauseDelayRand, pauseDelayMin; 155 float shootLengthRand, shootLengthMin; 156 float shootDelayRand, shootDelayMin; 157 float closestDistance; 158 float angleInaccuracyMax; 159 float strafePreference; 160 161 float shootTimer; 162 float shotBurstLength; 163 float angleInaccuracy; 164 float angleCompensation; 165 float inaccuracyTimer; 166 float pauseLength; 167 float pauseTimer; 168 float anger; 169 }; 170 171 172 #endif 173