Mover.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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. #ifdef _D3XP
  214. void Event_SetGuiStates();
  215. #endif
  216. };
  217. /*
  218. ===============================================================================
  219. Binary movers.
  220. ===============================================================================
  221. */
  222. typedef enum {
  223. MOVER_POS1,
  224. MOVER_POS2,
  225. MOVER_1TO2,
  226. MOVER_2TO1
  227. } moverState_t;
  228. class idMover_Binary : public idEntity {
  229. public:
  230. CLASS_PROTOTYPE( idMover_Binary );
  231. idMover_Binary();
  232. ~idMover_Binary();
  233. void Spawn( void );
  234. void Save( idSaveGame *savefile ) const;
  235. void Restore( idRestoreGame *savefile );
  236. virtual void PreBind( void );
  237. virtual void PostBind( void );
  238. void Enable( bool b );
  239. void InitSpeed( idVec3 &mpos1, idVec3 &mpos2, float mspeed, float maccelTime, float mdecelTime );
  240. void InitTime( idVec3 &mpos1, idVec3 &mpos2, float mtime, float maccelTime, float mdecelTime );
  241. void GotoPosition1( void );
  242. void GotoPosition2( void );
  243. void Use_BinaryMover( idEntity *activator );
  244. void SetGuiStates( const char *state );
  245. void UpdateBuddies( int val );
  246. idMover_Binary * GetActivateChain( void ) const { return activateChain; }
  247. idMover_Binary * GetMoveMaster( void ) const { return moveMaster; }
  248. void BindTeam( idEntity *bindTo );
  249. void SetBlocked( bool b );
  250. bool IsBlocked( void );
  251. idEntity * GetActivator( void ) const;
  252. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  253. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  254. void SetPortalState( bool open );
  255. protected:
  256. idVec3 pos1;
  257. idVec3 pos2;
  258. moverState_t moverState;
  259. idMover_Binary * moveMaster;
  260. idMover_Binary * activateChain;
  261. int soundPos1;
  262. int sound1to2;
  263. int sound2to1;
  264. int soundPos2;
  265. int soundLoop;
  266. float wait;
  267. float damage;
  268. int duration;
  269. int accelTime;
  270. int decelTime;
  271. idEntityPtr<idEntity> activatedBy;
  272. int stateStartTime;
  273. idStr team;
  274. bool enabled;
  275. int move_thread;
  276. int updateStatus; // 1 = lock behaviour, 2 = open close status
  277. idStrList buddies;
  278. idPhysics_Parametric physicsObj;
  279. qhandle_t areaPortal; // 0 = no portal
  280. bool blocked;
  281. #ifdef _D3XP
  282. bool playerOnly;
  283. #endif
  284. idList< idEntityPtr<idEntity> > guiTargets;
  285. void MatchActivateTeam( moverState_t newstate, int time );
  286. void JoinActivateTeam( idMover_Binary *master );
  287. void UpdateMoverSound( moverState_t state );
  288. void SetMoverState( moverState_t newstate, int time );
  289. moverState_t GetMoverState( void ) const { return moverState; }
  290. void FindGuiTargets( void );
  291. void SetGuiState( const char *key, const char *val ) const;
  292. void Event_SetCallback( void );
  293. void Event_ReturnToPos1( void );
  294. void Event_Use_BinaryMover( idEntity *activator );
  295. void Event_Reached_BinaryMover( void );
  296. void Event_MatchActivateTeam( moverState_t newstate, int time );
  297. void Event_Enable( void );
  298. void Event_Disable( void );
  299. void Event_OpenPortal( void );
  300. void Event_ClosePortal( void );
  301. void Event_FindGuiTargets( void );
  302. void Event_InitGuiTargets( void );
  303. static void GetMovedir( float dir, idVec3 &movedir );
  304. };
  305. class idDoor : public idMover_Binary {
  306. public:
  307. CLASS_PROTOTYPE( idDoor );
  308. idDoor( void );
  309. ~idDoor( void );
  310. void Spawn( void );
  311. void Save( idSaveGame *savefile ) const;
  312. void Restore( idRestoreGame *savefile );
  313. virtual void Think( void );
  314. virtual void PreBind( void );
  315. virtual void PostBind( void );
  316. virtual void Hide( void );
  317. virtual void Show( void );
  318. bool IsOpen( void );
  319. bool IsNoTouch( void );
  320. #ifdef _D3XP
  321. bool AllowPlayerOnly( idEntity *ent );
  322. #endif
  323. int IsLocked( void );
  324. void Lock( int f );
  325. void Use( idEntity *other, idEntity *activator );
  326. void Close( void );
  327. void Open( void );
  328. void SetCompanion( idDoor *door );
  329. private:
  330. float triggersize;
  331. bool crusher;
  332. bool noTouch;
  333. bool aas_area_closed;
  334. idStr buddyStr;
  335. idClipModel * trigger;
  336. idClipModel * sndTrigger;
  337. int nextSndTriggerTime;
  338. idVec3 localTriggerOrigin;
  339. idMat3 localTriggerAxis;
  340. idStr requires;
  341. int removeItem;
  342. idStr syncLock;
  343. int normalAxisIndex; // door faces X or Y for spectator teleports
  344. idDoor * companionDoor;
  345. void SetAASAreaState( bool closed );
  346. void GetLocalTriggerPosition( const idClipModel *trigger );
  347. void CalcTriggerBounds( float size, idBounds &bounds );
  348. void Event_Reached_BinaryMover( void );
  349. void Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
  350. void Event_PartBlocked( idEntity *blockingEntity );
  351. void Event_Touch( idEntity *other, trace_t *trace );
  352. void Event_Activate( idEntity *activator );
  353. void Event_StartOpen( void );
  354. void Event_SpawnDoorTrigger( void );
  355. void Event_SpawnSoundTrigger( void );
  356. void Event_Close( void );
  357. void Event_Open( void );
  358. void Event_Lock( int f );
  359. void Event_IsOpen( void );
  360. void Event_Locked( void );
  361. void Event_SpectatorTouch( idEntity *other, trace_t *trace );
  362. void Event_OpenPortal( void );
  363. void Event_ClosePortal( void );
  364. };
  365. class idPlat : public idMover_Binary {
  366. public:
  367. CLASS_PROTOTYPE( idPlat );
  368. idPlat( void );
  369. ~idPlat( void );
  370. void Spawn( void );
  371. void Save( idSaveGame *savefile ) const;
  372. void Restore( idRestoreGame *savefile );
  373. virtual void Think( void );
  374. virtual void PreBind( void );
  375. virtual void PostBind( void );
  376. private:
  377. idClipModel * trigger;
  378. idVec3 localTriggerOrigin;
  379. idMat3 localTriggerAxis;
  380. void GetLocalTriggerPosition( const idClipModel *trigger );
  381. void SpawnPlatTrigger( idVec3 &pos );
  382. void Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
  383. void Event_PartBlocked( idEntity *blockingEntity );
  384. void Event_Touch( idEntity *other, trace_t *trace );
  385. };
  386. /*
  387. ===============================================================================
  388. Special periodic movers.
  389. ===============================================================================
  390. */
  391. class idMover_Periodic : public idEntity {
  392. public:
  393. CLASS_PROTOTYPE( idMover_Periodic );
  394. idMover_Periodic( void );
  395. void Spawn( void );
  396. void Save( idSaveGame *savefile ) const;
  397. void Restore( idRestoreGame *savefile );
  398. virtual void Think( void );
  399. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  400. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  401. protected:
  402. idPhysics_Parametric physicsObj;
  403. float damage;
  404. void Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
  405. void Event_PartBlocked( idEntity *blockingEntity );
  406. };
  407. class idRotater : public idMover_Periodic {
  408. public:
  409. CLASS_PROTOTYPE( idRotater );
  410. idRotater( void );
  411. void Spawn( void );
  412. void Save( idSaveGame *savefile ) const;
  413. void Restore( idRestoreGame *savefile );
  414. private:
  415. idEntityPtr<idEntity> activatedBy;
  416. void Event_Activate( idEntity *activator );
  417. };
  418. class idBobber : public idMover_Periodic {
  419. public:
  420. CLASS_PROTOTYPE( idBobber );
  421. idBobber( void );
  422. void Spawn( void );
  423. private:
  424. };
  425. class idPendulum : public idMover_Periodic {
  426. public:
  427. CLASS_PROTOTYPE( idPendulum );
  428. idPendulum( void );
  429. void Spawn( void );
  430. private:
  431. };
  432. class idRiser : public idMover_Periodic {
  433. public:
  434. CLASS_PROTOTYPE( idRiser );
  435. idRiser( void );
  436. void Spawn( void );
  437. private:
  438. void Event_Activate( idEntity *activator );
  439. };
  440. #endif /* !__GAME_MOVER_H__ */