]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/Mover.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / d3xp / 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 #ifdef _D3XP
266         void                                    Event_SetGuiStates();
267 #endif
268
269 };
270
271
272 /*
273 ===============================================================================
274
275   Binary movers.
276
277 ===============================================================================
278 */
279
280 typedef enum {
281         MOVER_POS1,
282         MOVER_POS2,
283         MOVER_1TO2,
284         MOVER_2TO1
285 } moverState_t;
286
287 class idMover_Binary : public idEntity {
288 public:
289         CLASS_PROTOTYPE( idMover_Binary );
290
291                                                         idMover_Binary();
292                                                         ~idMover_Binary();
293
294         void                                    Spawn( void );
295
296         void                                    Save( idSaveGame *savefile ) const;
297         void                                    Restore( idRestoreGame *savefile );
298
299         virtual void                    PreBind( void );
300         virtual void                    PostBind( void );
301
302         void                                    Enable( bool b );
303         void                                    InitSpeed( idVec3 &mpos1, idVec3 &mpos2, float mspeed, float maccelTime, float mdecelTime );
304         void                                    InitTime( idVec3 &mpos1, idVec3 &mpos2, float mtime, float maccelTime, float mdecelTime );
305         void                                    GotoPosition1( void );
306         void                                    GotoPosition2( void );
307         void                                    Use_BinaryMover( idEntity *activator );
308         void                                    SetGuiStates( const char *state );
309         void                                    UpdateBuddies( int val );
310         idMover_Binary *                GetActivateChain( void ) const { return activateChain; }
311         idMover_Binary *                GetMoveMaster( void ) const { return moveMaster; }
312         void                                    BindTeam( idEntity *bindTo );
313         void                                    SetBlocked( bool b );
314         bool                                    IsBlocked( void );
315         idEntity *                              GetActivator( void ) const;
316
317         virtual void                    WriteToSnapshot( idBitMsgDelta &msg ) const;
318         virtual void                    ReadFromSnapshot( const idBitMsgDelta &msg );
319
320         void                                    SetPortalState( bool open );
321
322 protected:
323         idVec3                                  pos1;
324         idVec3                                  pos2;
325         moverState_t                    moverState;
326         idMover_Binary *                moveMaster;
327         idMover_Binary *                activateChain;
328         int                                             soundPos1;
329         int                                             sound1to2;
330         int                                             sound2to1;
331         int                                             soundPos2;
332         int                                             soundLoop;
333         float                                   wait;
334         float                                   damage;
335         int                                             duration;
336         int                                             accelTime;
337         int                                             decelTime;
338         idEntityPtr<idEntity>   activatedBy;
339         int                                             stateStartTime;
340         idStr                                   team;
341         bool                                    enabled;
342         int                                             move_thread;
343         int                                             updateStatus;           // 1 = lock behaviour, 2 = open close status
344         idStrList                               buddies;
345         idPhysics_Parametric    physicsObj;
346         qhandle_t                               areaPortal;                     // 0 = no portal
347         bool                                    blocked;
348 #ifdef _D3XP
349         bool                                    playerOnly;
350 #endif
351         idList< idEntityPtr<idEntity> > guiTargets;
352
353         void                                    MatchActivateTeam( moverState_t newstate, int time );
354         void                                    JoinActivateTeam( idMover_Binary *master );
355
356         void                                    UpdateMoverSound( moverState_t state );
357         void                                    SetMoverState( moverState_t newstate, int time );
358         moverState_t                    GetMoverState( void ) const { return moverState; }
359         void                                    FindGuiTargets( void );
360         void                                    SetGuiState( const char *key, const char *val ) const;
361
362         void                                    Event_SetCallback( void );
363         void                                    Event_ReturnToPos1( void );
364         void                                    Event_Use_BinaryMover( idEntity *activator );
365         void                                    Event_Reached_BinaryMover( void );
366         void                                    Event_MatchActivateTeam( moverState_t newstate, int time );
367         void                                    Event_Enable( void );
368         void                                    Event_Disable( void );
369         void                                    Event_OpenPortal( void );
370         void                                    Event_ClosePortal( void );
371         void                                    Event_FindGuiTargets( void );
372         void                                    Event_InitGuiTargets( void );
373
374         static void                             GetMovedir( float dir, idVec3 &movedir );
375 };
376
377 class idDoor : public idMover_Binary {
378 public:
379         CLASS_PROTOTYPE( idDoor );
380
381                                                         idDoor( void );
382                                                         ~idDoor( void );
383
384         void                                    Spawn( void );
385
386         void                                    Save( idSaveGame *savefile ) const;
387         void                                    Restore( idRestoreGame *savefile );
388
389         virtual void                    Think( void );
390         virtual void                    PreBind( void );
391         virtual void                    PostBind( void );
392         virtual void                    Hide( void );
393         virtual void                    Show( void );
394
395         bool                                    IsOpen( void );
396         bool                                    IsNoTouch( void );
397 #ifdef _D3XP
398         bool                                    AllowPlayerOnly( idEntity *ent );
399 #endif
400         int                                             IsLocked( void );
401         void                                    Lock( int f );
402         void                                    Use( idEntity *other, idEntity *activator );
403         void                                    Close( void );
404         void                                    Open( void );
405         void                                    SetCompanion( idDoor *door );
406
407 private:
408         float                                   triggersize;
409         bool                                    crusher;
410         bool                                    noTouch;
411         bool                                    aas_area_closed;
412         idStr                                   buddyStr;
413         idClipModel *                   trigger;
414         idClipModel *                   sndTrigger;
415         int                                             nextSndTriggerTime;
416         idVec3                                  localTriggerOrigin;
417         idMat3                                  localTriggerAxis;
418         idStr                                   requires;
419         int                                             removeItem;
420         idStr                                   syncLock;
421         int                                             normalAxisIndex;                // door faces X or Y for spectator teleports
422         idDoor *                                companionDoor;
423
424         void                                    SetAASAreaState( bool closed );
425
426         void                                    GetLocalTriggerPosition( const idClipModel *trigger );
427         void                                    CalcTriggerBounds( float size, idBounds &bounds );
428
429         void                                    Event_Reached_BinaryMover( void );
430         void                                    Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
431         void                                    Event_PartBlocked( idEntity *blockingEntity );
432         void                                    Event_Touch( idEntity *other, trace_t *trace );
433         void                                    Event_Activate( idEntity *activator );
434         void                                    Event_StartOpen( void );
435         void                                    Event_SpawnDoorTrigger( void );
436         void                                    Event_SpawnSoundTrigger( void );
437         void                                    Event_Close( void );
438         void                                    Event_Open( void );
439         void                                    Event_Lock( int f );
440         void                                    Event_IsOpen( void );
441         void                                    Event_Locked( void );
442         void                                    Event_SpectatorTouch( idEntity *other, trace_t *trace );
443         void                                    Event_OpenPortal( void );
444         void                                    Event_ClosePortal( void );
445 };
446
447 class idPlat : public idMover_Binary {
448 public:
449         CLASS_PROTOTYPE( idPlat );
450
451                                                         idPlat( void );
452                                                         ~idPlat( void );
453
454         void                                    Spawn( void );
455
456         void                                    Save( idSaveGame *savefile ) const;
457         void                                    Restore( idRestoreGame *savefile );
458
459         virtual void                    Think( void );
460         virtual void                    PreBind( void );
461         virtual void                    PostBind( void );
462
463 private:
464         idClipModel *                   trigger;
465         idVec3                                  localTriggerOrigin;
466         idMat3                                  localTriggerAxis;
467
468         void                                    GetLocalTriggerPosition( const idClipModel *trigger );
469         void                                    SpawnPlatTrigger( idVec3 &pos );
470
471         void                                    Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
472         void                                    Event_PartBlocked( idEntity *blockingEntity );
473         void                                    Event_Touch( idEntity *other, trace_t *trace );
474 };
475
476
477 /*
478 ===============================================================================
479
480   Special periodic movers.
481
482 ===============================================================================
483 */
484
485 class idMover_Periodic : public idEntity {
486 public:
487         CLASS_PROTOTYPE( idMover_Periodic );
488
489                                                         idMover_Periodic( void );
490
491         void                                    Spawn( void );
492         
493         void                                    Save( idSaveGame *savefile ) const;
494         void                                    Restore( idRestoreGame *savefile );
495
496         virtual void                    Think( void );
497
498         virtual void                    WriteToSnapshot( idBitMsgDelta &msg ) const;
499         virtual void                    ReadFromSnapshot( const idBitMsgDelta &msg );
500
501 protected:
502         idPhysics_Parametric    physicsObj;
503         float                                   damage;
504
505         void                                    Event_TeamBlocked( idEntity *blockedEntity, idEntity *blockingEntity );
506         void                                    Event_PartBlocked( idEntity *blockingEntity );
507 };
508
509 class idRotater : public idMover_Periodic {
510 public:
511         CLASS_PROTOTYPE( idRotater );
512
513                                                         idRotater( void );
514
515         void                                    Spawn( void );
516
517         void                                    Save( idSaveGame *savefile ) const;
518         void                                    Restore( idRestoreGame *savefile );
519
520 private:
521         idEntityPtr<idEntity>   activatedBy;
522
523         void                                    Event_Activate( idEntity *activator );
524 };
525
526 class idBobber : public idMover_Periodic {
527 public:
528         CLASS_PROTOTYPE( idBobber );
529
530                                                         idBobber( void );
531
532         void                                    Spawn( void );
533
534 private:
535 };
536
537 class idPendulum : public idMover_Periodic {
538 public:
539         CLASS_PROTOTYPE( idPendulum );
540
541                                                         idPendulum( void );
542
543         void                                    Spawn( void );
544
545 private:
546 };
547
548 class idRiser : public idMover_Periodic {
549 public:
550         CLASS_PROTOTYPE( idRiser );
551
552         idRiser( void );
553
554         void                                    Spawn( void );
555
556 private:
557         void                                    Event_Activate( idEntity *activator );
558 };
559
560 #endif /* !__GAME_MOVER_H__ */