person.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. // person.h
  19. // Project: Postal
  20. //
  21. // History:
  22. //
  23. // 04/28/97 BRH Started this generic enemy/victim class that will use
  24. // logic in CDoofus and an information strucutre in
  25. // Personatorium to determine the abilities and desired
  26. // logic for this person.
  27. //
  28. // 04/29/97 BRH Added m_ePersonType value which is the only thing that
  29. // needs to be loaded and saved.
  30. //
  31. // 05/09/97 BRH Moved took out m_lNextGroanTime and just used m_lTimer
  32. // since it is not being used in the Writhing state.
  33. //
  34. // 05/11/97 BRH Added an override to Logic_Writhing so that I can
  35. // do a special case for the cop since he crawls along
  36. // the ground.
  37. //
  38. // 05/19/97 JMI Added ms_u16IdLogAI.
  39. //
  40. // 05/19/97 JMI Added m_szLogicFile, m_sShowState, and Render() override.
  41. //
  42. // 05/19/97 BRH Added logic table pointer. Changed the string for the
  43. // logic file from a char* to an RString so it can be
  44. // loaded and saved easily.
  45. //
  46. // 05/20/97 BRH Added logic table variables as friend classes so their
  47. // Get functions can access the protected members via the
  48. // CPerson pointer.
  49. //
  50. // 06/14/97 BRH Added functions to choose and play various sound effects
  51. // using the sounds defined in the personatorium for each
  52. // person type.
  53. //
  54. // 06/18/97 JMI Changed PlaySoundWrithing() to return the duration of the
  55. // played sample.
  56. //
  57. // MJR Added ResetLogAI() to reset AI logging feature.
  58. //
  59. // 06/27/97 JMI Now hooks EditRender().
  60. //
  61. // 07/06/97 BRH Added another friend class for the logic table
  62. //
  63. // 07/17/97 JMI Changed RSnd*'s to SampleMaster::SoundInstances.
  64. // Now uses new SampleMaster interface for volume and play
  65. // instance reference.
  66. //
  67. // 08/03/97 BRH Added logic table friend class.
  68. //
  69. // 08/12/97 BRH Added m_bHitComment flag so that the comment made
  70. // when shot is only said once, and noises are used
  71. // for the rest of the shot reactions.
  72. //
  73. // 08/29/97 BRH Added a static variable for the logic tables to use
  74. // to set set the state of all of the kids for the
  75. // ending level.
  76. //
  77. ////////////////////////////////////////////////////////////////////////////////
  78. #ifndef PERSON_H
  79. #define PERSON_H
  80. #include "RSPiX.h"
  81. #include "realm.h"
  82. #include "doofus.h"
  83. #include "personatorium.h"
  84. #include "logtab.h"
  85. // CPerson is the class for the enemy guys
  86. class CPerson : public CDoofus
  87. {
  88. friend class CLogTabVar_TargetDist;
  89. friend class CLogTabVar_GetAction;
  90. friend class CLogTabVar_SetAction;
  91. friend class CLogTabVar_PopoutAvailable;
  92. friend class CLogTabVar_RunShootAvailable;
  93. friend class CLogTabVar_SafetyAvailable;
  94. friend class CLogTabVar_PylonAvailable;
  95. friend class CLogTabVar_DudeHealth;
  96. friend class CLogTabVar_IsTriggered;
  97. friend class CLogTabVar_UserState1;
  98. friend class CLogTabVar_RecentlyShot;
  99. friend class CLogTabVar_IsPanic;
  100. friend class CLogTabVar_HelpCall;
  101. friend class CLogTabVar_RecentlyStuck;
  102. friend class CLogTabVar_UserGlobal;
  103. //---------------------------------------------------------------------------
  104. // Types, enums, etc.
  105. //---------------------------------------------------------------------------
  106. protected:
  107. //---------------------------------------------------------------------------
  108. // Variables
  109. //---------------------------------------------------------------------------
  110. public:
  111. RString m_rstrLogicName;
  112. protected:
  113. // General position, motion and time variables
  114. // Store what type of person you are
  115. Personatorium::Index m_ePersonType;
  116. // Logic Table for this person's behavior
  117. CLogTab<CPerson*>* m_pLogicTable;
  118. // Logic filename.
  119. RString m_rstrLogicFile;
  120. // If TRUE, the guy's state is shown by his hotspot.
  121. short m_sShowState;
  122. // This is a high level state variable for logic tables.
  123. short m_sUserState1;
  124. // This is set once the person has used their 1 shot comment, then
  125. // it will only use the noises after that.
  126. bool m_bHitComment;
  127. // Tracks file counter so we know when to load/save "common" data
  128. static short ms_sFileCount;
  129. // This is the one CPerson that can log its AI table transitions or
  130. // CIdBank::IdNil.
  131. static U16 ms_u16IdLogAI;
  132. // "Constant" values that we want to be able to tune using the editor
  133. static double ms_dLongRange; // Squared distance (500 pixels away)
  134. static double ms_dInRangeLow; // Squared distance to be in range with weapon
  135. static double ms_dInRangeHigh; // Squared distance to be in range with weapon
  136. static double ms_dThrowHorizVel; // Horizontal throw velocity
  137. static double ms_dMaxCrawlVel; // Speed at which cop crawls when writhing
  138. static long ms_lRandomAvoidTime; // Time to wander before looking again
  139. static long ms_lReseekTime; // Do a 'find' again
  140. static long ms_lWatchWaitTime; // Time to watch shot go
  141. static long ms_lReselectDudeTime;// Time to go without finding a dude
  142. // before calling SelectDude() to find
  143. // possibly a closer one.
  144. static long ms_lMinCommentTime; // Min time before making a random comment
  145. static long ms_lCommentTimeVariance;// Random amount added on to comment timer.
  146. public:
  147. static short ms_sLogTabUserGlobal;// Global state set and read by logic tables
  148. //---------------------------------------------------------------------------
  149. // Constructor(s) / destructor
  150. //---------------------------------------------------------------------------
  151. protected:
  152. // Constructor
  153. CPerson(CRealm* pRealm)
  154. : CDoofus(pRealm, CPersonID)
  155. {
  156. m_sSuspend = 0;
  157. m_dRot = 0;
  158. m_dX = m_dY = m_dZ = m_dVel = m_dAcc = 0;
  159. m_ePersonType = Personatorium::Grenader;
  160. m_eWeaponType = CThing::CGrenadeID;
  161. m_panimCur = m_panimPrev = NULL;
  162. m_sprite.m_pthing = this;
  163. m_rstrLogicFile = "res/logics/default.lgk";
  164. m_sShowState = FALSE;
  165. m_sUserState1 = 0; // Uninitialized
  166. m_bHitComment = false;
  167. }
  168. public:
  169. // Destructor
  170. ~CPerson()
  171. {
  172. // Remove sprite from scene (this is safe even if it was already removed!)
  173. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  174. m_pRealm->m_smashatorium.Remove(&m_smash);
  175. // Free resources
  176. FreeResources();
  177. }
  178. //---------------------------------------------------------------------------
  179. // Required static functions
  180. //---------------------------------------------------------------------------
  181. public:
  182. // Construct object
  183. static short Construct( // Returns 0 if successfull, non-zero otherwise
  184. CRealm* pRealm, // In: Pointer to realm this object belongs to
  185. CThing** ppNew) // Out: Pointer to new object
  186. {
  187. short sResult = 0;
  188. *ppNew = new CPerson(pRealm);
  189. if (*ppNew == 0)
  190. {
  191. sResult = -1;
  192. TRACE("CPerson::Construct(): Couldn't construct CPerson (that's a bad thing)\n");
  193. }
  194. return sResult;
  195. }
  196. //---------------------------------------------------------------------------
  197. // Required virtual functions (implimenting them as inlines doesn't pay!)
  198. //---------------------------------------------------------------------------
  199. public:
  200. // Load object (should call base class version!)
  201. short Load( // Returns 0 if successfull, non-zero otherwise
  202. RFile* pFile, // In: File to load from
  203. bool bEditMode, // In: True for edit mode, false otherwise
  204. short sFileCount, // In: File count (unique per file, never 0)
  205. ULONG ulFileVersion); // In: Version of file format to load.
  206. // Save object (should call base class version!)
  207. short Save( // Returns 0 if successfull, non-zero otherwise
  208. RFile* pFile, // In: File to save to
  209. short sFileCount); // In: File count (unique per file, never 0)
  210. // Startup object
  211. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  212. // Shutdown object
  213. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  214. // Init - set up object before running
  215. short Init(void);
  216. // Update object
  217. void Update(void);
  218. // Render object.
  219. void Render(void);
  220. // Called by editor to init new object at specified position
  221. short EditNew( // Returns 0 if successfull, non-zero otherwise
  222. short sX, // In: New x coord
  223. short sY, // In: New y coord
  224. short sZ); // In: New z coord
  225. // Called by editor to modify object
  226. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  227. // Called by editor to update object
  228. void EditUpdate(void);
  229. // Called by editor to render object.
  230. void EditRender(void);
  231. // Function to choose and play the writhing sound effect
  232. virtual SampleMaster::SoundInstance PlaySoundWrithing(
  233. long* plDuration); // Out: Duration of sample, if not NULL.
  234. // Function to choose and play the Shot sound effect
  235. virtual SampleMaster::SoundInstance PlaySoundShot(void);
  236. // Function to choose and play the Blown up sound effect
  237. virtual SampleMaster::SoundInstance PlaySoundBlownup(void);
  238. // Funciton to choose and play the Burning sound effect
  239. virtual SampleMaster::SoundInstance PlaySoundBurning(void);
  240. // Function to choose and play the shooting comment
  241. virtual SampleMaster::SoundInstance PlaySoundShooting(void);
  242. // Function to choose and play the dying sound.
  243. virtual SampleMaster::SoundInstance PlaySoundDying(void);
  244. // Function to choose and play the Random comments
  245. virtual SampleMaster::SoundInstance PlaySoundRandom(void);
  246. //---------------------------------------------------------------------------
  247. // Static functions
  248. //---------------------------------------------------------------------------
  249. public:
  250. static void ResetLogAI(void)
  251. {
  252. // Reset AI logging feature.
  253. ms_u16IdLogAI = CIdBank::IdNil;
  254. }
  255. //---------------------------------------------------------------------------
  256. // Internal functions
  257. //---------------------------------------------------------------------------
  258. protected:
  259. // Get all required resources
  260. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  261. // Free all resources
  262. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  263. // Special case logic for the cop writhing since he crawls on the ground.
  264. virtual void Logic_Writhing(void);
  265. };
  266. #endif //PERSON_H
  267. ////////////////////////////////////////////////////////////////////////////////
  268. // EOF
  269. ////////////////////////////////////////////////////////////////////////////////