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