Mover.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code 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. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_MOVER_H__
  21. #define __GAME_MOVER_H__
  22. extern const idEventDef EV_TeamBlocked;
  23. extern const idEventDef EV_PartBlocked;
  24. extern const idEventDef EV_ReachedPos;
  25. extern const idEventDef EV_ReachedAng;
  26. /*
  27. ===============================================================================
  28. General movers.
  29. ===============================================================================
  30. */
  31. class idMover : public idEntity {
  32. public:
  33. CLASS_PROTOTYPE( idMover );
  34. idMover( void );
  35. void Spawn( void );
  36. void Save( idSaveGame *savefile ) const;
  37. void Restore( idRestoreGame *savefile );
  38. virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  39. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  40. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  41. virtual void Hide( void );
  42. virtual void Show( void );
  43. void SetPortalState( bool open );
  44. protected:
  45. typedef enum {
  46. ACCELERATION_STAGE,
  47. LINEAR_STAGE,
  48. DECELERATION_STAGE,
  49. FINISHED_STAGE
  50. } moveStage_t;
  51. typedef enum {
  52. MOVER_NONE,
  53. MOVER_ROTATING,
  54. MOVER_MOVING,
  55. MOVER_SPLINE
  56. } moverCommand_t;
  57. //
  58. // mover directions. make sure to change script/doom_defs.script if you add any, or change their order
  59. //
  60. typedef enum {
  61. DIR_UP = -1,
  62. DIR_DOWN = -2,
  63. DIR_LEFT = -3,
  64. DIR_RIGHT = -4,
  65. DIR_FORWARD = -5,
  66. DIR_BACK = -6,
  67. DIR_REL_UP = -7,
  68. DIR_REL_DOWN = -8,
  69. DIR_REL_LEFT = -9,
  70. DIR_REL_RIGHT = -10,
  71. DIR_REL_FORWARD = -11,
  72. DIR_REL_BACK = -12
  73. } moverDir_t;
  74. typedef struct {
  75. moveStage_t stage;
  76. int acceleration;
  77. int movetime;
  78. int deceleration;
  79. idVec3 dir;
  80. } moveState_t;
  81. typedef struct {
  82. moveStage_t stage;
  83. int acceleration;
  84. int movetime;
  85. int deceleration;
  86. idAngles rot;
  87. } rotationState_t;
  88. idPhysics_Parametric physicsObj;
  89. void Event_OpenPortal( void );
  90. void Event_ClosePortal( void );
  91. void Event_PartBlocked( idEntity *blockingEntity );
  92. void MoveToPos( const idVec3 &pos);
  93. void UpdateMoveSound( moveStage_t stage );
  94. void UpdateRotationSound( moveStage_t stage );
  95. void SetGuiStates( const char *state );
  96. void FindGuiTargets( void );
  97. void SetGuiState( const char *key, const char *val ) const;
  98. virtual void DoneMoving( void );
  99. virtual void DoneRotating( void );
  100. virtual void BeginMove( idThread *thread = NULL );
  101. virtual void BeginRotation( idThread *thread, bool stopwhendone );
  102. moveState_t move;
  103. private:
  104. rotationState_t rot;
  105. int move_thread;
  106. int rotate_thread;
  107. idAngles dest_angles;
  108. idAngles angle_delta;
  109. idVec3 dest_position;
  110. idVec3 move_delta;
  111. float move_speed;
  112. int move_time;
  113. int deceltime;
  114. int acceltime;
  115. bool stopRotation;
  116. bool useSplineAngles;
  117. idEntityPtr<idEntity> splineEnt;
  118. moverCommand_t lastCommand;
  119. float damage;
  120. qhandle_t areaPortal; // 0 = no portal
  121. idList< idEntityPtr<idEntity> > guiTargets;
  122. void VectorForDir( float dir, idVec3 &vec );
  123. idCurve_Spline<idVec3> *GetSpline( idEntity *splineEntity ) const;
  124. void Event_SetCallback( void );
  125. void Event_TeamBlocked( idEntity *blockedPart, idEntity *blockingEntity );
  126. void Event_StopMoving( void );
  127. void Event_StopRotating( void );
  128. void Event_UpdateMove( void );
  129. void Event_UpdateRotation( void );
  130. void Event_SetMoveSpeed( float speed );
  131. void Event_SetMoveTime( float time );
  132. void Event_SetDecelerationTime( float time );
  133. void Event_SetAccellerationTime( float time );
  134. void Event_MoveTo( idEntity *ent );
  135. void Event_MoveToPos( idVec3 &pos );
  136. void Event_MoveDir( float angle, float distance );
  137. void Event_MoveAccelerateTo( float speed, float time );
  138. void Event_MoveDecelerateTo( float speed, float time );
  139. void Event_RotateDownTo( int axis, float angle );
  140. void Event_RotateUpTo( int axis, float angle );
  141. void Event_RotateTo( idAngles &angles );
  142. void Event_Rotate( idAngles &angles );
  143. void Event_RotateOnce( idAngles &angles );
  144. void Event_Bob( float speed, float phase, idVec3 &depth );
  145. void Event_Sway( float speed, float phase, idAngles &depth );
  146. void Event_SetAccelSound( const char *sound );
  147. void Event_SetDecelSound( const char *sound );
  148. void Event_SetMoveSound( const char *sound );
  149. void Event_FindGuiTargets( void );
  150. void Event_InitGuiTargets( void );
  151. void Event_EnableSplineAngles( void );
  152. void Event_DisableSplineAngles( void );
  153. void Event_RemoveInitialSplineAngles( void );
  154. void Event_StartSpline( idEntity *splineEntity );
  155. void Event_StopSpline( void );
  156. void Event_Activate( idEntity *activator );
  157. void Event_PostRestore( int start, int total, int accel, int decel, int useSplineAng );
  158. void Event_IsMoving( void );
  159. void Event_IsRotating( void );
  160. };
  161. class idSplinePath : public idEntity {
  162. public:
  163. CLASS_PROTOTYPE( idSplinePath );
  164. idSplinePath();
  165. void Spawn( void );
  166. };
  167. struct floorInfo_s {
  168. idVec3 pos;
  169. idStr door;
  170. int floor;
  171. };
  172. class idElevator : public idMover {
  173. public:
  174. CLASS_PROTOTYPE( idElevator );
  175. idElevator( void );
  176. void Spawn();
  177. void Save( idSaveGame *savefile ) const;
  178. void Restore( idRestoreGame *savefile );
  179. virtual bool HandleSingleGuiCommand( idEntity *entityGui, idLexer *src );
  180. void Event_GotoFloor( int floor );
  181. floorInfo_s * GetFloorInfo( int floor );
  182. protected:
  183. virtual void DoneMoving( void );
  184. virtual void BeginMove( idThread *thread = NULL );
  185. void SpawnTrigger( const idVec3 &pos );
  186. void GetLocalTriggerPosition();
  187. void Event_Touch( idEntity *other, trace_t *trace );
  188. private:
  189. typedef enum {
  190. INIT,
  191. IDLE,
  192. WAITING_ON_DOORS
  193. } elevatorState_t;
  194. elevatorState_t state;
  195. idList<floorInfo_s> floorInfo;
  196. int currentFloor;
  197. int pendingFloor;
  198. int lastFloor;
  199. bool controlsDisabled;
  200. float returnTime;
  201. int returnFloor;
  202. int lastTouchTime;
  203. class idDoor * GetDoor( const char *name );
  204. void Think( void );
  205. void OpenInnerDoor( void );
  206. void OpenFloorDoor( int floor );
  207. void CloseAllDoors( void );
  208. void DisableAllDoors( void );
  209. void EnableProperDoors( void );
  210. void Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
  211. void Event_Activate( idEntity *activator );
  212. void Event_PostFloorArrival();
  213. };
  214. /*
  215. ===============================================================================
  216. Binary movers.
  217. ===============================================================================
  218. */
  219. typedef enum {
  220. MOVER_POS1,
  221. MOVER_POS2,
  222. MOVER_1TO2,
  223. MOVER_2TO1
  224. } moverState_t;
  225. class idMover_Binary : public idEntity {
  226. public:
  227. CLASS_PROTOTYPE( idMover_Binary );
  228. idMover_Binary();
  229. ~idMover_Binary();
  230. void Spawn( void );
  231. void Save( idSaveGame *savefile ) const;
  232. void Restore( idRestoreGame *savefile );
  233. virtual void PreBind( void );
  234. virtual void PostBind( void );
  235. void Enable( bool b );
  236. void InitSpeed( idVec3 &mpos1, idVec3 &mpos2, float mspeed, float maccelTime, float mdecelTime );
  237. void InitTime( idVec3 &mpos1, idVec3 &mpos2, float mtime, float maccelTime, float mdecelTime );
  238. void GotoPosition1( void );
  239. void GotoPosition2( void );
  240. void Use_BinaryMover( idEntity *activator );
  241. void SetGuiStates( const char *state );
  242. void UpdateBuddies( int val );
  243. idMover_Binary * GetActivateChain( void ) const { return activateChain; }
  244. idMover_Binary * GetMoveMaster( void ) const { return moveMaster; }
  245. void BindTeam( idEntity *bindTo );
  246. void SetBlocked( bool b );
  247. bool IsBlocked( void );
  248. idEntity * GetActivator( void ) const;
  249. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  250. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  251. void SetPortalState( bool open );
  252. protected:
  253. idVec3 pos1;
  254. idVec3 pos2;
  255. moverState_t moverState;
  256. idMover_Binary * moveMaster;
  257. idMover_Binary * activateChain;
  258. int soundPos1;
  259. int sound1to2;
  260. int sound2to1;
  261. int soundPos2;
  262. int soundLoop;
  263. float wait;
  264. float damage;
  265. int duration;
  266. int accelTime;
  267. int decelTime;
  268. idEntityPtr<idEntity> activatedBy;
  269. int stateStartTime;
  270. idStr team;
  271. bool enabled;
  272. int move_thread;
  273. int updateStatus; // 1 = lock behaviour, 2 = open close status
  274. idStrList buddies;
  275. idPhysics_Parametric physicsObj;
  276. qhandle_t areaPortal; // 0 = no portal
  277. bool blocked;
  278. idList< idEntityPtr<idEntity> > guiTargets;
  279. void MatchActivateTeam( moverState_t newstate, int time );
  280. void JoinActivateTeam( idMover_Binary *master );
  281. void UpdateMoverSound( moverState_t state );
  282. void SetMoverState( moverState_t newstate, int time );
  283. moverState_t GetMoverState( void ) const { return moverState; }
  284. void FindGuiTargets( void );
  285. void SetGuiState( const char *key, const char *val ) const;
  286. void Event_SetCallback( void );
  287. void Event_ReturnToPos1( void );
  288. void Event_Use_BinaryMover( idEntity *activator );
  289. void Event_Reached_BinaryMover( void );
  290. void Event_MatchActivateTeam( moverState_t newstate, int time );
  291. void Event_Enable( void );
  292. void Event_Disable( void );
  293. void Event_OpenPortal( void );
  294. void Event_ClosePortal( void );
  295. void Event_FindGuiTargets( void );
  296. void Event_InitGuiTargets( void );
  297. static void GetMovedir( float dir, idVec3 &movedir );
  298. };
  299. class idDoor : public idMover_Binary {
  300. public:
  301. CLASS_PROTOTYPE( idDoor );
  302. idDoor( void );
  303. ~idDoor( void );
  304. void Spawn( void );
  305. void Save( idSaveGame *savefile ) const;
  306. void Restore( idRestoreGame *savefile );
  307. virtual void Think( void );
  308. virtual void PreBind( void );
  309. virtual void PostBind( void );
  310. virtual void Hide( void );
  311. virtual void Show( void );
  312. bool IsOpen( void );
  313. bool IsNoTouch( void );
  314. int IsLocked( void );
  315. void Lock( int f );
  316. void Use( idEntity *other, idEntity *activator );
  317. void Close( void );
  318. void Open( void );
  319. void SetCompanion( idDoor *door );
  320. private:
  321. float triggersize;
  322. bool crusher;
  323. bool noTouch;
  324. bool aas_area_closed;
  325. idStr buddyStr;
  326. idClipModel * trigger;
  327. idClipModel * sndTrigger;
  328. int nextSndTriggerTime;
  329. idVec3 localTriggerOrigin;
  330. idMat3 localTriggerAxis;
  331. idStr requires;
  332. int removeItem;
  333. idStr syncLock;
  334. int normalAxisIndex; // door faces X or Y for spectator teleports
  335. idDoor * companionDoor;
  336. void SetAASAreaState( bool closed );
  337. void GetLocalTriggerPosition( const idClipModel *trigger );
  338. void CalcTriggerBounds( float size, idBounds &bounds );
  339. void Event_Reached_BinaryMover( void );
  340. void Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
  341. void Event_PartBlocked( idEntity *blockingEntity );
  342. void Event_Touch( idEntity *other, trace_t *trace );
  343. void Event_Activate( idEntity *activator );
  344. void Event_StartOpen( void );
  345. void Event_SpawnDoorTrigger( void );
  346. void Event_SpawnSoundTrigger( void );
  347. void Event_Close( void );
  348. void Event_Open( void );
  349. void Event_Lock( int f );
  350. void Event_IsOpen( void );
  351. void Event_Locked( void );
  352. void Event_SpectatorTouch( idEntity *other, trace_t *trace );
  353. void Event_OpenPortal( void );
  354. void Event_ClosePortal( void );
  355. };
  356. class idPlat : public idMover_Binary {
  357. public:
  358. CLASS_PROTOTYPE( idPlat );
  359. idPlat( void );
  360. ~idPlat( void );
  361. void Spawn( void );
  362. void Save( idSaveGame *savefile ) const;
  363. void Restore( idRestoreGame *savefile );
  364. virtual void Think( void );
  365. virtual void PreBind( void );
  366. virtual void PostBind( void );
  367. private:
  368. idClipModel * trigger;
  369. idVec3 localTriggerOrigin;
  370. idMat3 localTriggerAxis;
  371. void GetLocalTriggerPosition( const idClipModel *trigger );
  372. void SpawnPlatTrigger( idVec3 &pos );
  373. void Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
  374. void Event_PartBlocked( idEntity *blockingEntity );
  375. void Event_Touch( idEntity *other, trace_t *trace );
  376. };
  377. /*
  378. ===============================================================================
  379. Special periodic movers.
  380. ===============================================================================
  381. */
  382. class idMover_Periodic : public idEntity {
  383. public:
  384. CLASS_PROTOTYPE( idMover_Periodic );
  385. idMover_Periodic( void );
  386. void Spawn( void );
  387. void Save( idSaveGame *savefile ) const;
  388. void Restore( idRestoreGame *savefile );
  389. virtual void Think( void );
  390. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  391. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  392. protected:
  393. idPhysics_Parametric physicsObj;
  394. float damage;
  395. void Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
  396. void Event_PartBlocked( idEntity *blockingEntity );
  397. };
  398. class idRotater : public idMover_Periodic {
  399. public:
  400. CLASS_PROTOTYPE( idRotater );
  401. idRotater( void );
  402. void Spawn( void );
  403. void Save( idSaveGame *savefile ) const;
  404. void Restore( idRestoreGame *savefile );
  405. private:
  406. idEntityPtr<idEntity> activatedBy;
  407. void Event_Activate( idEntity *activator );
  408. };
  409. class idBobber : public idMover_Periodic {
  410. public:
  411. CLASS_PROTOTYPE( idBobber );
  412. idBobber( void );
  413. void Spawn( void );
  414. private:
  415. };
  416. class idPendulum : public idMover_Periodic {
  417. public:
  418. CLASS_PROTOTYPE( idPendulum );
  419. idPendulum( void );
  420. void Spawn( void );
  421. private:
  422. };
  423. class idRiser : public idMover_Periodic {
  424. public:
  425. CLASS_PROTOTYPE( idRiser );
  426. idRiser( void );
  427. void Spawn( void );
  428. private:
  429. void Event_Activate( idEntity *activator );
  430. };
  431. #endif /* !__GAME_MOVER_H__ */