doofus.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  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 along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // doofus.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 01/13/97 BRH Started this file from CDude and modified it
  23. // to do some enemy logic using the same assets
  24. // as the sample 2D guy.
  25. //
  26. // 03/13/97 JMI Load now takes a version number.
  27. //
  28. // 04/22/97 BRH Moved common variables like the animations and previous
  29. // state and animation variables to the base class since
  30. // all of the enemies had their own versions. Added logic
  31. // functions that can be called from a derrived class.
  32. //
  33. // 04/24/97 BRH Added TryClearDirection function that uses the
  34. // IsPathClear() funciton to try 3 directions to see if they
  35. // are clear.
  36. //
  37. // 04/25/97 JMI Added m_animWrithing.
  38. //
  39. // 05/06/97 BRH Added a detection smash that is much larger than the
  40. // normal collision smash. This one is use to detect pylons
  41. // in the area.
  42. //
  43. // 05/07/97 BRH Added pylon pointers for Popout and Run/Shoot logic to make
  44. // it eaiser to know where to go.
  45. //
  46. // 05/09/97 BRH Incorporated some more logic from CPerson into CDoofus.
  47. //
  48. // 05/11/97 BRH Made the logic routines virtual functions so that the
  49. // derived classes can make their own for special case
  50. // purposes.
  51. //
  52. // 05/12/97 BRH Added destination state so that an overall goal state
  53. // could be set and held on to even when interrupted by
  54. // intermediate states like Popout or moving.
  55. //
  56. // 05/18/97 BRH Added some logic routines for the victims to use.
  57. //
  58. // 05/20/97 BRH Changed logic tables to use Suggested actions rather
  59. // than changing the states directly. Added an Action
  60. // enum to Doofus for the logic variables to use. Also
  61. // Added current and suggested action values to the doofus,
  62. // and an logic table evaluation timer.
  63. //
  64. // 05/23/97 BRH Added TryClearShot function to check for clear shooting
  65. // angle.
  66. //
  67. // 05/25/97 BRH Added the m_ShootAngle variable and an override for
  68. // ShootWeapon that uses this angle to aim the weapon.
  69. //
  70. // 05/26/97 BRH Added an overload to ShootWeapon that uses the
  71. // m_dShootAngle for aiming. Also it sets the CSmash bits
  72. // so that enemy bullets don't hit other enemies.
  73. //
  74. // 05/31/97 JMI Replaced m_pDude with m_idDude. The problem was that, by
  75. // just using a pointer to the dude, we never found out when
  76. // the dude was gone (deleted). Although this is rare for
  77. // CDudes, it does happen. For example, in the beginning of
  78. // a level all CDudes that do not have an associated player
  79. // are sent a Delete msg. They do not process this message
  80. // until their respective Update() calls. If a CDoofus
  81. // derived guy happened to be placed in the level before a
  82. // CDude (that is, the CDoofus' Update() got called before the
  83. // CDude's), and the CDoofus happened to point its m_pDude at
  84. // this CDude (that was destined to soon be deleted), later
  85. // when referencing the pointer to the freed and/or reallocated
  86. // memory, the CDoofus could cause a protection fault or math
  87. // overflow (due to invalid values returned by
  88. // m_pDude->GetX, Y, Z() with the non-CDude 'this' pointer).
  89. //
  90. // 06/02/97 BRH Added AdvanceHold action and state so that once he reaches
  91. // the end of the advancement, he goes into this hold state
  92. // rather than Engage automatically. This way the logic
  93. // table can have more control over the next state.
  94. //
  95. // 06/10/97 BRH Added Crouch and Search animations for idle animation.
  96. //
  97. // 06/14/97 BRH Added virtual sound effect functions that can be defined
  98. // also at the Person level to choose the sound effect
  99. // from the personatorium. Also added comment timer and
  100. // comment counter to regulate the number of comments made
  101. // so they don't get too repetative.
  102. //
  103. // 06/17/97 BRH Added a timer value for the sounds playing to store
  104. // the estimated finish time of the current sample, rather
  105. // than using the IsSamplePlaying() which screws up the
  106. // network mode.
  107. //
  108. // 06/18/97 BRH Added an override function for PrepareWeapon so that the
  109. // Shooting sounds can be played.
  110. //
  111. // 06/18/97 JMI Changed PlaySoundWrithing() to return the duration of the
  112. // played sample.
  113. //
  114. // 07/06/97 BRH Added static panic flag to the doofus for the victims to
  115. // use. It will be cleared at the beginning of the level
  116. // and will be set by the first victim to get shot so that
  117. // all of the other victims will know to run around scared.
  118. // Also added a few logic routines for victims.
  119. //
  120. // 07/09/97 BRH Added walk and panic actions for victim logic tables.
  121. //
  122. // 07/10/97 BRH Added madness and march actions for victim and protestor
  123. // logic.
  124. //
  125. // 07/11/97 BRH Added call to inline Cheater() to disable game if necessary
  126. //
  127. // 07/17/97 BRH Added Logic_DelayShoot so that you can choose to put
  128. // the guy into a shooting state but wait for a timer to
  129. // expire.
  130. //
  131. // 07/17/97 JMI Commented out m_prsndIsPlaying and m_psmidIsPlaying since
  132. // they are not used. If they are needed in the future,
  133. // m_prsndIsPlaying should be a SampleMaster::SoundInstance
  134. // instead of an RSnd*.
  135. // Changed RSnd*'s to SampleMaster::SoundInstances.
  136. //
  137. // 07/23/97 BRH Added tunable values for three different timeouts.
  138. //
  139. // 07/25/97 BRH Integrated the cookie check into Cheater.
  140. //
  141. // 08/02/97 BRH Added a few functions for avoiding fire.
  142. //
  143. // 08/02/97 BRH Added YellForHelp function which will alert others within
  144. // line of sight that you have been shot, then they can
  145. // decide to take action. Added OnHelpMsg function to handle
  146. // the call for help.
  147. //
  148. // 08/06/97 JMI Added m_ptransExecutionTarget link point for execution
  149. // sphere. Also, added PositionSmash() to provide overridable
  150. // method for updating the collision sphere.
  151. //
  152. // 08/07/97 JMI Added ms_awdWeapons[], ms_apszWeaponResNames[], and
  153. // GetResources() and FreeResources() for loading these anims.
  154. // Also, added ms_lWeaponResRefCount so we could know when the
  155. // weapons were no longer needed.
  156. //
  157. // 08/08/97 JMI Added more weapons: UZI, AutoRifle, SmallPistol, Dynamite.
  158. //
  159. // 08/08/97 BRH Added Logic_MarchBegin function for the marching.
  160. //
  161. // 08/10/97 JMI Moved CDoofus() and ~CDoofus() into doofus.cpp.
  162. // Added m_bRegisteredBirth which is true once we have
  163. // registered our birth with the realm.
  164. //
  165. // 08/10/97 JMI Moved NoWeapon up to enum value 0 and created a new one
  166. // to take its -1 place as an invalid weapon (InvalidWeapon).
  167. // Also, added block in PrepareWeapon() for the NoWeapon case.
  168. // Also, moved prepare weapon from the .H to the .CPP.
  169. //
  170. // 08/11/97 JMI Added fallback weapon type, m_eFallbackWeaponType, which
  171. // can signify a weapon to use when there is no weapon anim
  172. // for the current weapon type. Whew.
  173. // Also, changed incorrectly name ms_awtType2Id to
  174. // ms_awtId2Type mapping.
  175. //
  176. // 08/17/97 BRH Added m_sStuckCounter to detect situations where the
  177. // enemy is trying to move in engage mode, but has got
  178. // stuck in some narrow terrain and should go back to the
  179. // bouys.
  180. //
  181. // 08/18/97 BRH Added virtual WhileHoldingWeapon override for Doofus so
  182. // that for the higher difficulty settings where the guys
  183. // aim after preparing weapon, they can do it every frame
  184. // in between so that they don't end up flipping around
  185. // quick when they shoot the weapon, especially the rocket
  186. // man which has a long shoot-prepare animation.
  187. //
  188. // 08/21/97 BRH Added a blood pool counter so that the blood could be cut
  189. // down a little bit.
  190. //
  191. ////////////////////////////////////////////////////////////////////////////////
  192. #ifndef DOOFUS_H
  193. #define DOOFUS_H
  194. #include "RSPiX.h"
  195. #include "realm.h"
  196. #include "navnet.h"
  197. #include "bouy.h"
  198. #include "dude.h"
  199. #include "pylon.h"
  200. #include "CompileOptions.h"
  201. // CDoofus is the class for the enemy guys
  202. class CDoofus : public CCharacter
  203. {
  204. //---------------------------------------------------------------------------
  205. // Types, enums, etc.
  206. //---------------------------------------------------------------------------
  207. public:
  208. typedef enum // Suggested logic actions basec on
  209. { // evaluation of situation
  210. Action_Guard, // Stay in place and check for proximity to Dude
  211. Action_Advance, // Advance toward your target Dude
  212. Action_Retreat, // Retreat away from the area
  213. Action_Engage, // Shoot and move, shoot and move
  214. Action_Popout, // Hide at pylon until triggered, then popout & shoot
  215. Action_RunShoot, // Hide at pylon until triggered, then run to other pylon
  216. Action_Hide, // Hide at safe place pylon
  217. Action_AdvanceHold, // You are as close as you can get on the bouy network
  218. Action_Walk, // Walk around - victims
  219. Action_Panic, // Panic - victims
  220. Action_March, // March along a bouy network nearby.
  221. Action_Madness, // Run all over - not on bouy network.
  222. Action_Help, // Help when you hear a call for help
  223. // Add actions before this
  224. NumActions
  225. } Action;
  226. // This describes a weapon scheme that can be used as an index
  227. // into ms_awdWeapons[].
  228. typedef enum
  229. {
  230. InvalidWeapon = -1,
  231. NoWeapon,
  232. Rocket,
  233. Grenade,
  234. Napalm,
  235. Firebomb,
  236. ProximityMine,
  237. TimedMine,
  238. RemoteControlMine,
  239. BouncingBettyMine,
  240. Flamer,
  241. Pistol,
  242. MachineGun,
  243. ShotGun,
  244. Heatseeker,
  245. Assault,
  246. DeathWad,
  247. DoubleBarrel,
  248. Uzi,
  249. AutoRifle,
  250. SmallPistol,
  251. Dynamite,
  252. NumWeaponTypes
  253. } WeaponType;
  254. typedef struct
  255. {
  256. char* pszName;
  257. char* pszResName;
  258. ClassIDType id;
  259. } WeaponDetails;
  260. //---------------------------------------------------------------------------
  261. // Variables
  262. //---------------------------------------------------------------------------
  263. protected:
  264. // General position, motion and time variables
  265. U16 m_idDude; // The target CDude
  266. // Animations
  267. CAnim3D m_animStand; // Standing animation
  268. CAnim3D m_animRun; // Running animation
  269. CAnim3D m_animShoot; // Shoot gun animation
  270. CAnim3D m_animShootRun; // Shoot while running
  271. CAnim3D m_animShootRunR0; // Shoot at 45 degree right angle
  272. CAnim3D m_animShootRunR1; // Shoot at 90 degree right angle
  273. CAnim3D m_animShootRunBack; // Shoot backwards
  274. CAnim3D m_animShootRunL0; // Shoot at 45 degree left angle
  275. CAnim3D m_animShootRunL1; // Shoot at 90 degree left angle
  276. CAnim3D m_animShot; // Get shot animation
  277. CAnim3D m_animDie; // Die Die!
  278. CAnim3D m_animWrithing; // Writhing in predeathness.
  279. CAnim3D m_animExecuted; // Death by Execution
  280. CAnim3D m_animOnfire; // Running around on fire
  281. CAnim3D m_animWalk; // Walk animation - mostly for victims
  282. CAnim3D m_animCrouch; // Crouch down when idle
  283. CAnim3D m_animSearch; // Look around when idle
  284. // Navigation Net control
  285. CNavigationNet* m_pNavNet; // The network I should use
  286. U16 m_u16NavNetID; // My network's ID
  287. UCHAR m_ucDestBouyID; // Destination bouy
  288. UCHAR m_ucNextBouyID; // Next bouy to go to
  289. UCHAR m_ucSpecialBouy0ID; // Starting bouy for special cases like marching
  290. UCHAR m_ucSpecialBouy1ID; // Ending bouy for special cases like marching
  291. CBouy* m_pNextBouy; // pointer to next bouy to go to.
  292. short m_sNextX; // Position of next Bouy
  293. short m_sNextZ; // Position of next Bouy
  294. short m_sRotateDir; // Direction to rotate when avoiding obstacles
  295. long m_lAlignTimer; // Recheck position to bouy every so often
  296. long m_lEvalTimer; // Reevaluate state every so often
  297. long m_lShotTimeout; // Only do Shot animation every so often
  298. long m_lStuckTimeout; // time given to recovery from stuck state
  299. long m_lShootTimer; // Limit number of shots from a gun.
  300. long m_lCommentTimer; // Time between random comments
  301. short m_usCommentCounter; // Number of comments
  302. CDoofus::Action m_eSuggestedAction; // Suggested logic action
  303. CDoofus::Action m_eCurrentAction; // Currently running action
  304. CCharacter::State m_eDestinationState; // Final state you wish to achieve
  305. CCharacter::State m_ePreviousState;
  306. CCharacter::State m_eNextState; // This can be used to make states like Shoot more
  307. // reusable. Several states can go to State Shoot and
  308. // then when it is done, it can go to this next state
  309. // so that it can be part of several different state loops
  310. CAnim3D* m_panimPrev; // Previous state's animation
  311. // Channel of execution points for 'writhing' anim/state.
  312. ChanTransform* m_ptransExecutionTarget;
  313. CSmash m_smashDetect; // Smash used to detect pylons - has large radius
  314. CSmash m_smashAvoid; // Smash used to avoid fire
  315. CPylon* m_pPylonStart; // Starting pylon for popout or run/shoot
  316. CPylon* m_pPylonEnd; // Ending pylon for popout or run/shoot
  317. short m_sDistRemaining; // Distance to new position for fighting.
  318. bool m_bPylonSafeAvailable;
  319. bool m_bPylonPopoutAvailable;
  320. bool m_bPylonRunShootAvailable;
  321. bool m_bPanic; // Has been alerted to panic or not.
  322. double m_dAnimRot; // Animation rotation, used to face the animation
  323. // in one direction while moving in another direction.
  324. double m_dShootAngle;
  325. long m_lIdleTimer; // Timer for idle animations.
  326. bool m_bAnimUp; // Run animation up or down for idle animation. (crouch)
  327. long m_lSampleTimeIsPlaying; // Expected time for this sample
  328. bool m_bRecentlyStuck; // Flag for when you get stuck on a wall.
  329. bool m_bCivilian; // Flag for civilian/hostile
  330. bool m_bRegisteredBirth; // true, once we've registered our birth with the realm.
  331. long m_lGuardTimeout; // Tunable personatorium value with doofus default
  332. long m_lShootTimeout; // Tunable time between shots - based on difficulty level
  333. long m_lRunShootInterval; // Tunable personatorium value with doofus default.
  334. long m_lShotReactionTimeout; // Tunable personatorium value with doofus default
  335. long m_lLastHelpCallTime; // Last time someone called for help
  336. CSprite3 m_spriteWeapon; // Sprite for weapon.
  337. ClassIDType m_eFallbackWeaponType; // Fallback weapon type or TotalIDs for none.
  338. short m_sStuckCounter; // Number of times he tried to move in the current state
  339. USHORT m_usBloodCounter; // Counter to limit the blood pools.
  340. SampleMaster::SoundInstance m_siPlaying; // Sound instance that is playing - in case it needs to be stopped
  341. // Tracks file counter so we know when to load/save "common" data
  342. static short ms_sFileCount;
  343. // "Constant" values that we want to be able to tune using the editor
  344. static double ms_dAccUser; // Acceleration due to user
  345. static double ms_dAccDrag; // Acceleration due to drag (always towards 0)
  346. static double ms_dMaxVelFore; // Maximum forward velocity
  347. static double ms_dMaxVelBack; // Maximum backward velocity
  348. static double ms_dDegPerSec; // Degrees of rotation per second
  349. static double ms_dOffScreenDistance;
  350. static double ms_dGuardDistance; // Sq distance before he begins attacking.
  351. static double ms_dThrowHorizVel; // Horizontal throw velocity
  352. static double ms_dMinFightDistance; // Min distance for fighting
  353. static double ms_dMedFightDistance; // Median distance for fighting
  354. static double ms_dMaxFightDistance; // Max distance for fighting
  355. static double ms_dMinFightDistanceSQ;
  356. static double ms_dMedFightDistanceSQ;
  357. static double ms_dMaxFightDistanceSQ;
  358. static double ms_dMarchVelocity; // How fast to walk when marching.
  359. static long ms_lDefaultAlignTime;// How often to recalibrate angle to bouy
  360. static long ms_lGuardTimeoutMin; // How often to check for CDudes proximity
  361. static long ms_lGuardTimeoutInc; // Amount of time between for each level of difficulty
  362. static long ms_lShootTimeoutMin; // How often to wait between shots, min
  363. static long ms_lShootTimeoutInc; // Variance between shot times based on difficulty level
  364. static long ms_lDetectionRadius; // Radius of detection sphere
  365. static long ms_lRunShootInterval;// Time to run between shooting
  366. static long ms_lReseekTime; // Time to go before seeking the dude's position again
  367. static long ms_lShotTimeout; // Time to go before doing full shot anim when shot
  368. // this will give him time to escape.
  369. static long ms_lAvoidRadius; // Radius of fire avoidance smash
  370. static long ms_lYellRadius; // Radius of alerting smash
  371. static long ms_lHelpTimeout; // Time to react to a call for help.
  372. static long ms_lDelayShootTimeout;//time before shooting
  373. static long ms_lHelpingTimeout; // time before shooting when helping
  374. static long ms_lStuckRecoveryTime;//time to allow recovery from stuck position
  375. static U32 ms_u32CollideBitsInclude; // Default weapon collision bits
  376. static U32 ms_u32CollideBitsDontcare; // Default weapon collision bits
  377. static U32 ms_u32CollideBitsExclude; // Default weapon collision bits
  378. static short ms_sStuckLimit; // Number of retrys before changing states to get unstuck
  379. static CAnim3D ms_aanimWeapons[NumWeaponTypes]; // Weapon animations.
  380. static long ms_lWeaponResRefCount; // Current ref count on ms_aanimWeapons[].
  381. static WeaponDetails ms_awdWeapons[NumWeaponTypes]; // Weapon details (descriptions,
  382. // res names, etc.).
  383. static WeaponType ms_awtId2Type[TotalIDs]; // Maps a CThing ID to a WeaponType enum.
  384. public:
  385. static char* ms_apszActionNames[];// Names of the logic actions
  386. //---------------------------------------------------------------------------
  387. // Constructor(s) / destructor
  388. //---------------------------------------------------------------------------
  389. protected:
  390. // Constructor
  391. CDoofus(CRealm* pRealm, ClassIDType id);
  392. public:
  393. // Destructor
  394. ~CDoofus();
  395. //---------------------------------------------------------------------------
  396. // Required static functions
  397. //---------------------------------------------------------------------------
  398. public:
  399. // Construct object
  400. static short Construct( // Returns 0 if successfull, non-zero otherwise
  401. CRealm* pRealm, // In: Pointer to realm this object belongs to
  402. CThing** ppNew) // Out: Pointer to new object
  403. {
  404. return 0;
  405. }
  406. //---------------------------------------------------------------------------
  407. // Required virtual functions (implimenting them as inlines doesn't pay!)
  408. //---------------------------------------------------------------------------
  409. public:
  410. // Load object (should call base class version!)
  411. virtual short Load( // Returns 0 if successfull, non-zero otherwise
  412. RFile* pFile, // In: File to load from
  413. bool bEditMode, // In: True for edit mode, false otherwise
  414. short sFileCount, // In: File count (unique per file, never 0)
  415. ULONG ulFileVersion); // In: Version of file format to load.
  416. // Save object (should call base class version!)
  417. virtual short Save( // Returns 0 if successfull, non-zero otherwise
  418. RFile* pFile, // In: File to save to
  419. short sFileCount); // In: File count (unique per file, never 0)
  420. // Startup object
  421. virtual short Startup(void); // Returns 0 if successfull, non-zero otherwise
  422. // Called by editor to init new object at specified position
  423. virtual short EditNew( // Returns 0 if successfull, non-zero otherwise
  424. short sX, // In: New x coord
  425. short sY, // In: New y coord
  426. short sZ); // In: New z coord
  427. // Called by editor to render object
  428. virtual void EditRender(void);
  429. // Override to swap the animation and direction rotations temporarily
  430. virtual void Render(void);
  431. // Derived classes should use their own Update function
  432. virtual void Update(void);
  433. // Guard the area until a CDude is nearby
  434. virtual void Logic_Guard(void);
  435. // When a CDude is nearby, keep an eye on him and attack
  436. // if he gets aggressive
  437. virtual void Logic_Patrol(void);
  438. // Find a CDude and use the network to get him wherever he is
  439. virtual void Logic_Hunt(void);
  440. // Stay in Hunt mode, looking for a closer bouy
  441. virtual void Logic_HuntHold(void);
  442. // Find the next bouy en route to the final destination
  443. virtual void Logic_MoveNext(void);
  444. // Detect nearby pylons and see what logic they suggest
  445. virtual void Logic_PylonDetect(void);
  446. // Start Hide sequence by going to the 'cover' pylon
  447. virtual void Logic_HideBegin(void);
  448. // Hide here and keep checking for a different Action suggestion
  449. virtual void Logic_Hide(void);
  450. // Start popout sequence by going to the 'cover' pylon
  451. virtual void Logic_PopBegin(void);
  452. // Wait for Dude to come in range to popout on him.
  453. virtual void Logic_PopWait(void);
  454. // Popout from a popout bouy and shoot, then return to cover
  455. virtual void Logic_Popout(void);
  456. // Run and Shoot and seek cover between two bouys
  457. virtual void Logic_RunShoot(void);
  458. // Run and Shoot begin
  459. virtual void Logic_RunShootBegin(void);
  460. // Run and Shoot wait - wait at endpoints before going again
  461. virtual void Logic_RunShootWait(void);
  462. // Stay at a SafeSpot bouy if while the CDude is facing you
  463. virtual void Logic_BeSafe(void);
  464. // Once injured or in a dangerous situation, you may choose
  465. // to run for the hills
  466. virtual void Logic_Retreat(void);
  467. // Firefight - you are in a shootout, so shoot & move
  468. virtual void Logic_Firefight(void);
  469. // Engage logic - Get into position and start fighting
  470. virtual void Logic_Engage(void);
  471. // Shoot the weapon - this state uses the m_eNextState variable
  472. // to know where to go after the shot is fired and the animation
  473. // is over
  474. virtual void Logic_Shoot(void);
  475. // Shoot while running - uses m_eNextState to know where to go
  476. // after shot is fired and the animation is over.
  477. virtual void Logic_ShootRun(void);
  478. // Shot - what you do when you get shot
  479. virtual void Logic_Shot(void);
  480. // Blownup - what you do when someone blows you up
  481. virtual void Logic_BlownUp(void);
  482. // Burning - what you do when you are on fire
  483. virtual void Logic_Burning(void);
  484. // Die - what you do when you are dying
  485. virtual void Logic_Die(void);
  486. // Writhing on the ground in pain
  487. virtual void Logic_Writhing(void);
  488. // Setup to get into position for fighting
  489. virtual void Logic_PositionSet(void);
  490. // Move into position for fighting
  491. virtual void Logic_PositionMove(void);
  492. // Wait for timer to expire, then shoot
  493. virtual void Logic_DelayShoot(void);
  494. // Victim panic - pick a random bouy to run to
  495. virtual void Logic_PanicBegin(void);
  496. // Victim panic again once you reach the destination
  497. virtual void Logic_PanicContinue(void);
  498. // Victim walk - pick a random bouy to walk to
  499. virtual void Logic_WalkBegin(void);
  500. // Victim walk again once you reach the destination
  501. virtual void Logic_WalkContinue(void);
  502. // Avoid fire - wait for fire danger to disappear before
  503. // going back to your previous state.
  504. virtual void Logic_AvoidFire(void);
  505. // When someone nearby gets shot and 'yells for help', this
  506. // is the reaction state that can be set so that you can shoot
  507. // from where you are without screwing up your current state.
  508. virtual void Logic_Helping(void);
  509. // Start a march - like a protest. Pick one endpoint bouy and then
  510. // MarchNext until you get there, then pick the other one.
  511. virtual void Logic_MarchBegin(void);
  512. // This can be called when a timer expires, or if a situation
  513. // changes, etc. It will take into consideration the current state,
  514. // position of CDude, and enemy attributes and sometimes random
  515. // numbers to pick a state for the guy.
  516. bool ReevaluateState(void);
  517. // Overloaded version of ShootWeapon to use m_dShootAngle
  518. // and which sets the smash bits so enemy bullets won't hit other
  519. // enemies.
  520. virtual CWeapon* ShootWeapon(
  521. CSmash::Bits bitsInclude = CSmash::Character,
  522. CSmash::Bits bitsDontcare = 0,
  523. CSmash::Bits bitsExclude = CSmash::Bad | CSmash::SpecialBarrel);
  524. // Function to choose and play the writhing sound effect
  525. virtual SampleMaster::SoundInstance PlaySoundWrithing(
  526. long* plDuration) // Out: Duration of sample, if not NULL.
  527. {
  528. if (plDuration != NULL)
  529. {
  530. *plDuration = 0;
  531. }
  532. return 0;
  533. }
  534. // Function to choose and play the Shot sound effect
  535. virtual SampleMaster::SoundInstance PlaySoundShot(void)
  536. {return 0;};
  537. // Function to choose and play the Blown up sound effect
  538. virtual SampleMaster::SoundInstance PlaySoundBlownup(void)
  539. {return 0;};
  540. // Funciton to choose and play the Burning sound effect
  541. virtual SampleMaster::SoundInstance PlaySoundBurning(void)
  542. {return 0;};
  543. // Function to choose and play the shooting comment
  544. virtual SampleMaster::SoundInstance PlaySoundShooting(void)
  545. {return 0;};
  546. // Function to choose and play the dying sound.
  547. virtual SampleMaster::SoundInstance PlaySoundDying(void)
  548. {return 0;};
  549. // Function to choose and play the Random comments
  550. virtual SampleMaster::SoundInstance PlaySoundRandom(void)
  551. {return 0;};
  552. // Prepare current weapon (ammo).
  553. // This should be done when the character starts its shoot animation.
  554. virtual // Override to implement additional functionality.
  555. // Call base class to get default functionality.
  556. CWeapon* PrepareWeapon(void); // Returns the weapon ptr or NULL.
  557. // Implements basic functionality while holding and preparing to release
  558. // a weapon. Shows the weapon when the event hits 1 and releases the
  559. // weapon via ShootWeapon() when the event hits 2.
  560. virtual // Override to implement additional functionality.
  561. // Call base class to get default functionality.
  562. bool WhileHoldingWeapon( // Returns true when weapon is released.
  563. U32 u32BitsInclude, // In: Collision bits passed to ShootWeapon
  564. U32 u32BitsDontcare, // In: Collision bits passed to ShootWeapon
  565. U32 u32BitsExclude); // In: Collision bits passed to ShootWeapon
  566. //---------------------------------------------------------------------------
  567. // Internal functions
  568. //---------------------------------------------------------------------------
  569. protected:
  570. // Get the bouy that the CDude is closest to
  571. short SelectDudeBouy(void); // Returns 0 if successful, non-zero otherwise
  572. // Return a valid random bouy or 0 if no bouys exist.
  573. UCHAR SelectRandomBouy(void);
  574. // Set a pointer to the CDude you are tracking for other CDude related
  575. // functions like FindDirection and SQDistanceToDude
  576. short SelectDude(void); // Returns 0 if successful, non-zero if no Dudes found
  577. // Find the angle to the selected CDude
  578. short FindDirection(void);
  579. // If Alignment timer is up, recalc the direction to the bouy.
  580. void AlignToBouy(void);
  581. // Find the squared distance to the CDude (to avoid sqrt)
  582. double SQDistanceToDude(void);
  583. // Attempt 3 paths
  584. bool TryClearDirection(double* pdRot, short sVariance);
  585. // Check shooting angle before firing to make sure no
  586. // walls are in the way.
  587. bool TryClearShot(double dRot, short sVariance);
  588. // Check for fire in your path and change to a safe state rather
  589. // than blindly running into the fire.
  590. bool AvoidFire(void); // Returns true if there is a fire danger
  591. // When you get shot call this function which will alert other enemies
  592. // in the area in line of sight so that they can choose to react.
  593. void YellForHelp(void);
  594. // Handles a Shot_Message.
  595. virtual // Override to implement additional functionality.
  596. // Call base class to get default functionality.
  597. void OnShotMsg( // Returns nothing.
  598. Shot_Message* pshotmsg); // In: Message to handle.
  599. // Handles an Explosion_Message.
  600. virtual // Override to implement additional functionality.
  601. // Call base class to get default functionality.
  602. void OnExplosionMsg( // Returns nothing.
  603. Explosion_Message* pexplosionmsg); // In: Message to handle.
  604. // Handles a Burn_Message.
  605. virtual // Override to implement additional functionality.
  606. // Call base class to get default functionality.
  607. void OnBurnMsg( // Returns nothing.
  608. Burn_Message* pburnmsg); // In: Message to handle.
  609. // Handles an ObjectDelete_Message.
  610. virtual // Override to implement additional functionality.
  611. // Call base class to get default functionality.
  612. void OnDeleteMsg( // Returns nothing.
  613. ObjectDelete_Message* pdeletemsg); // In: Message to handle.
  614. // Handles a Help_Message
  615. virtual // Override to implement additional functionality
  616. // Call base class to get default functionality
  617. void OnHelpMsg( // Returns nothing
  618. Help_Message* phelpmsg);
  619. // Override for CCharacter::OnDead
  620. virtual void OnDead(void);
  621. // Run an idle animation and switch them up every so often
  622. void RunIdleAnimation(void);
  623. // Position our smash approriately.
  624. virtual // Override to implement additional functionality.
  625. // Call base class to get default functionality
  626. void PositionSmash(void);
  627. // Check for cheaters and make the game interesting
  628. inline void Cheater(void)
  629. {
  630. #if 0 //!PLATFORM_UNIX // This isn't cheating, this is beta expiration. --ryan.
  631. if (g_lRegValue < 0 || g_lExpValue < 0 || g_lCookieMonster == SAFE_DATE)
  632. {
  633. GameMessage msg;
  634. CThing* pThing = NULL;
  635. msg.msg_Burn.eType = typeBurn;
  636. msg.msg_Burn.sPriority = 0;
  637. msg.msg_Burn.sDamage = 1000;
  638. msg.msg_Burn.u16ShooterID = GetInstanceID();;
  639. CListNode<CThing>* pNext = m_pRealm->m_everythingHead.m_pnNext;
  640. while (pNext->m_powner != NULL)
  641. {
  642. pThing = pNext->m_powner;
  643. SendThingMessage(&msg, pThing);
  644. pNext = pNext->m_pnNext;
  645. }
  646. }
  647. #endif
  648. }
  649. // Look up a WeaponDetails by CThing class ID.
  650. inline WeaponDetails* GetWeaponDetails( // Returns ptr to details or NULL, if none.
  651. ClassIDType id) // In: ID to look up.
  652. {
  653. ASSERT(id <= TotalIDs);
  654. WeaponDetails* pwd = NULL;
  655. if (id < TotalIDs)
  656. {
  657. WeaponType wt = ms_awtId2Type[id];
  658. if (wt != InvalidWeapon)
  659. {
  660. pwd = &(ms_awdWeapons[wt]);
  661. }
  662. }
  663. else
  664. {
  665. pwd = &(ms_awdWeapons[NoWeapon]);
  666. }
  667. return pwd;
  668. }
  669. // Look up a weapon animation by CThing class ID.
  670. inline CAnim3D* GetWeaponAnim( // Returns ptr to anim or NULL, if none.
  671. ClassIDType id) // In: ID to look up.
  672. {
  673. ASSERT(id <= TotalIDs);
  674. CAnim3D* panim = NULL;
  675. if (id < TotalIDs)
  676. {
  677. WeaponType wt = ms_awtId2Type[id];
  678. if (wt != InvalidWeapon)
  679. {
  680. panim = &(ms_aanimWeapons[wt]);
  681. }
  682. }
  683. else
  684. {
  685. panim = &(ms_aanimWeapons[NoWeapon]);
  686. }
  687. return panim;
  688. }
  689. // A way for the base class to get resources. If you are going to use
  690. // any of this class's resources (e.g., ms_aanimWeapons[]), call this
  691. // when getting your resources.
  692. short GetResources(void);
  693. // A way for the base class to release resources. If you are going to use
  694. // any of this class's resources (e.g., ms_aanimWeapons[]), call this
  695. // when releasing your resources.
  696. void ReleaseResources(void);
  697. };
  698. #endif //DOOFUS_H
  699. ////////////////////////////////////////////////////////////////////////////////
  700. // EOF
  701. ////////////////////////////////////////////////////////////////////////////////