summaryrefslogtreecommitdiffstats
path: root/game/code/mission/mission.h
blob: 892a5101b1ae3c15f582331c11ddfe98f4991702 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
//=============================================================================
// Copyright (C) 2002 Radical Entertainment Ltd.  All rights reserved.
//
// File:        mission.h
//
// Description: Blahblahblah
//
// History:     15/04/2002 + Created -- NAME
//
//=============================================================================

#ifndef MISSION_H
#define MISSION_H

//========================================
// Nested Includes
//========================================

#include <events/eventlistener.h>

#include <events/eventenum.h>

#include <memory/srrmemory.h>

#include <mission/missionstage.h>

#include <string.h>


//========================================
// Forward References
//========================================

class Vehicle;
class CarStartLocator;
class ZoneEventLocator;
class BonusObjective;
class StatePropCollectible;
class AnimatedIcon;

//=============================================================================
//
// Synopsis:    Controls the flow through a mission by sequentially leading
//              the player through one or more stages.  Upon the completion
//              of a stage, the next stage becomes active, and so on until
//              all stages (and thus the mission) are complete.
//
//=============================================================================

class Mission : public EventListener
{
public:

    enum { MAX_BONUS_OBJECTIVES = 3 };

    Mission();
    ~Mission();

    // Gets the index in the text bible of the name of this mission
    char* GetName() { return( &mcName[ 0 ] ); }
    void SetName( char* name );

    // Stages in this mission
    void SetNumStages( int num ) { mNumMissionStages = num; }
    int GetNumStages() { return( mNumMissionStages ); }

    MissionStage* GetStage( int index );
    void SetStage( int index, MissionStage* stage );

	
    MissionStage* GetCurrentStage();
    int GetCurrentStageIndex() const { return( mCurrentStage ); }

    // loads and initializes all the stages
	virtual void Initialize( GameMemoryAllocator heap );

    // finalizes and dumps all the stages
	virtual void Finalize();


    // These two methods finalize the current stage then move
    // to and initialize some other stage
	void SetToStage( int index, bool resetting = false );
	virtual void NextStage();
	virtual void PrevStage();

    // Resets the current mission stage
	void ResetStage();

    // fake event listener
	virtual void HandleEvent( EventEnum id, void* pEventData );

    // The GamePlayManager should call this for every frame
    // the mission is active
	void Update( unsigned int elapsedTime );
    
    //
    // Adds a vehicle for this mission only
    //
    //void AddVehicle( Vehicle* vehicle );
    //Vehicle* GetVehicleByName( char* name );

    //
    // Accessors for the time left in the mission
    //
    int GetMissionTimeLeftInSeconds();
    int GetMissionTimeLeftInMilliSeconds();

    // Resets the entire mission. Use with caution!
    void Reset( bool JumpStage = false );
    void ResetPlayer();
    void InitDynaLoad();

    bool DialogueCharactersTeleported();

    enum MissionState
    {
        STATE_WAITING,
        STATE_INPROGRESS,
        STATE_FAILED,
        STATE_SUCCESS,
        NUM_STATES
    };

    MissionState GetState() { return( mState ); }

    // Returns true iff every stage in this mission is complete
	bool IsComplete();
    
    //methods called from the missionscriptloader these shouldnt be called by any thing other missionscriptloader
    //since are for setup.
    void SetVehicleRestart( CarStartLocator* loc ) { mVehicleRestart = loc; };
    void SetPlayerRestart( Locator* loc ) { mPlayerRestart = loc; };
    void SetRestartDynaload( const char* loadString, const char* interior = NULL ) ;
    void LoadStreetRaceProps(const char* loadString );
    void UnloadStreetRaceProps (const char* loadString);

    
    //higher level methods for code use
    void InitStreetRacePropLoad();
    void InitStreetRacePropUnload();
   
   

    void SetSundayDrive() { mSundayDrive = true; };
    bool IsSundayDrive() const { return mSundayDrive; };
    void SetResetToStage( int stage ) { mResetToStage = stage; };
    void SetBonusMission();
    bool IsBonusMission();
    bool IsRaceMission(); //determines if this mission is a special road race
    bool IsWagerMission();

    void AddBonusObjective( BonusObjective* bo );
    void StartBonusObjectives();

 
    void SetForcedCar( bool isForced );
    bool IsForcedCar() const { return mIsForcedCar; };

    void SetMissionTime( int timeMilliseconds );

    void CreateStatePropCollectible( const char* statepropname, const char* locator, int collisionattributes );
    void AttachStatePropCollectible( const char* statepropname, const char* vehicleName, int collisionattributes );

    bool GetSwappedCarsFlag();
    void SetSwappedCarsFlag(bool flag);

    void SpecialCaseStageBackup( unsigned int num ) { mChangingStages = true; mJumpBackStage = true; mJumpBackBy = num; };

    void SetInitPedGroup( int initGroupId );

    void ShowHUD( bool isShowHUD );
    bool IsHUDVisible() const;
    bool CanMDKCar(Vehicle* pVehicle,MissionStage* pStage);

    void SetNumValidFailureHints( int numHints );
    int GetNumValidFailureHints() const;
    CarStartLocator* GetVehicleRestart () { return mVehicleRestart;};

    inline bool IsChangingStages() const { return mChangingStages; }

    bool GetCarryOverOutOfCarCondition() { return mbCarryOverOutOfCarCondition;};

    void SetCarryOverOutOfCarCondition(bool flag) { mbCarryOverOutOfCarCondition = flag;};

public:
    bool mIsStreetRace1Or2;

protected:
    void SetCurrentStageIndex( int index ) { mCurrentStage = index; }

    virtual void DoUpdate( int elapsedTime );
private:

    bool UnlockStage( MissionStage* stage );
    void SetupStageChange();
    void DoStageChange();


    static const int MAX_STAGES = 25;

    int mNumMissionStages;
    MissionStage* mMissionStages[ MAX_STAGES ];
    int mCurrentStage;
    int mResetMission;

    char mcName[16];

    GameMemoryAllocator mHeap;

    bool mbComplete;
    bool mbIsLastStage;
    
    int mMissionTimer;

    int mElapsedTimems;

    MissionState mState;
    MissionStage::MissionStageState mLastStageState;

    // TODO greg
    // this is soon to be history
    
    //static const int MAX_VEHICLES = 4;
    //int mNumVehicles;
    //Vehicle* mVehicles[ MAX_VEHICLES ];

    CarStartLocator* mVehicleRestart;
    Locator* mPlayerRestart;
    ZoneEventLocator* mDynaloadLoc;

    ZoneEventLocator* mStreetRacePropsLoad;    //Chuck: adding  these so we can load and unload street race barriers.
    ZoneEventLocator* mStreetRacePropsUnload;


    int mResetToStage;

    bool mSundayDrive  : 1;
    bool mBonusMisison : 1;

    BonusObjective* mBonusObjectives[ MAX_BONUS_OBJECTIVES ];
    unsigned int mNumBonusObjectives;

    bool mIsForcedCar;
    //Chuck Adding this so on retry the car gets auto repaired 
    bool mbAutoRepairCar;

    //Chuck: this variable used for forced missions so that the designers can swap
    // the forced car for the default vehicle.
    //if true that means that we have used a scripted sequence switched from the forced to our default 
    //and dont need to  swap in the default car at the end of the mission
    bool mbSwappedCars;

    //flag for carrying over get out of car condition from stage to stage
    bool mbCarryOverOutOfCarCondition;



    //Flag to trigger the patty and selma screen after street race
    bool mbTriggerPattyAndSelmaScreen;

    int mFinalDelay;
    int mCompleteDelay;

    bool mChangingStages;

    bool mNoTimeUpdate;

    bool mJumpBackStage;
    char mJumpBackBy;

    int mNumStatePropCollectibles;
    StatePropCollectible** mStatePropCollectibles;

    AnimatedIcon* mDoorStars;
    int mInitPedGroupId;

    bool mShowHUD : 1;

    int mNumValidFailureHints;

};

//=============================================================================
// Mission::SetName
//=============================================================================
// Description: Comment
//
// Parameters:  ( char* name )
//
// Return:      void 
//
//=============================================================================
inline void Mission::SetName( char* name ) 
{ 
    strcpy( &mcName[ 0 ], name ); 
}

//=============================================================================
// Mission::SetStage
//=============================================================================
// Description: Comment
//
// Parameters:  ( int index, MissionStage* stage )
//
// Return:      inline 
//
//=============================================================================
inline void Mission::SetStage( int index, MissionStage* stage )
{ 
    rTuneAssertMsg( index < MAX_STAGES, "Too many stages, get Cary to increase the max!\n" );
    mMissionStages[ index ] = stage; 
}

//=============================================================================
// Mission::GetStage
//=============================================================================
// Description: Comment
//
// Parameters:  ( int index )
//
// Return:      inline 
//
//=============================================================================
inline MissionStage* Mission::GetStage( int index )
{ 
    if( index >= 0 && index < mNumMissionStages )
    {
        return( mMissionStages[ index ] );
    }
    else
    {
        return( NULL );
    }
}

//=============================================================================
// Mission::IsHUDVisible
//=============================================================================
// Description: Comment
//
// Parameters:  
//
// Return:      inline 
//
//=============================================================================
inline bool Mission::IsHUDVisible() const
{
    return mShowHUD;
}

inline void Mission::SetNumValidFailureHints( int numHints )
{
    mNumValidFailureHints = numHints;
}

inline int Mission::GetNumValidFailureHints() const
{
    return mNumValidFailureHints;
}

#endif //MISSION_H