-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRM_Manager.cpp
416 lines (361 loc) · 11.9 KB
/
RM_Manager.cpp
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/*
This file is part of Jedi Academy.
Jedi Academy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Jedi Academy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jedi Academy. If not, see <http://www.gnu.org/licenses/>.
*/
// Copyright 2001-2013 Raven Software
/************************************************************************************************
*
* RM_Manager.cpp
*
* Implements the CRMManager class. The CRMManager class manages the arioche system.
*
************************************************************************************************/
#include "../server/exe_headers.h"
#include "RM_Headers.h"
#include "../server/server.h"
CRMObjective *CRMManager::mCurObjective=0;
/************************************************************************************************
* TheRandomMissionManager
* Pointer to only active CRMManager class
*
************************************************************************************************/
CRMManager *TheRandomMissionManager;
/************************************************************************************************
* CRMManager::CRMManager
* constructor
*
* inputs:
*
* return:
*
************************************************************************************************/
CRMManager::CRMManager(void)
{
mLandScape = NULL;
mTerrain = NULL;
mMission = NULL;
mCurPriority = 1;
mUseTimeLimit = false;
}
/************************************************************************************************
* CRMManager::~CRMManager
* destructor
*
* inputs:
*
* return:
*
************************************************************************************************/
CRMManager::~CRMManager(void)
{
#ifndef FINAL_BUILD
Com_Printf ("... Shutting down TheRandomMissionManager\n");
#endif
#ifndef DEDICATED
CM_TM_Free();
#endif
if (mMission)
{
delete mMission;
mMission = NULL;
}
}
/************************************************************************************************
* CRMManager::SetLandscape
* Sets the landscape and terrain object used to load a mission
*
* inputs:
* landscape - landscape object
*
* return:
* none
*
************************************************************************************************/
void CRMManager::SetLandScape(CCMLandScape *landscape)
{
mLandScape = landscape;
mTerrain = landscape->GetRandomTerrain();
}
/************************************************************************************************
* CRMManager::LoadMission
* Loads the mission using the mission name stored in the ar_mission cvar
*
* inputs:
* none
*
* return:
* none
*
************************************************************************************************/
bool CRMManager::LoadMission ( qboolean IsServer )
{
char instances[MAX_QPATH];
char mission[MAX_QPATH];
char course[MAX_QPATH];
char map[MAX_QPATH];
char temp[MAX_QPATH];
#ifndef FINAL_BUILD
Com_Printf ("--------- Random Mission Manager ---------\n\n");
Com_Printf ("RMG version : 0.01\n\n");
#endif
if (!mTerrain)
{
return false;
}
// Grab the arioche variables
Cvar_VariableStringBuffer("rmg_usetimelimit", temp, MAX_QPATH);
if (Q_stricmp(temp, "yes") == 0)
{
mUseTimeLimit = true;
}
Cvar_VariableStringBuffer("rmg_instances", instances, MAX_QPATH);
Cvar_VariableStringBuffer("RMG_mission", temp, MAX_QPATH);
Cvar_VariableStringBuffer("rmg_map", map, MAX_QPATH);
sprintf(mission, "%s_%s", temp, map);
Cvar_VariableStringBuffer("rmg_course", course, MAX_QPATH);
// dump existing mission, if any
if (mMission)
{
delete mMission;
mMission = NULL;
}
// Create a new mission file
mMission = new CRMMission ( mTerrain );
// Load the mission using the arioche variables
if ( !mMission->Load ( mission, instances, course ) )
{
return false;
}
if (mUseTimeLimit)
{
Cvar_Set("rmg_timelimit", va("%d", mMission->GetTimeLimit()));
}
else
{
Cvar_Set("rmg_timelimit", "0");
}
if (IsServer)
{ // set the names of the teams
CGenericParser2 parser;
//CGPGroup* root;
Cvar_VariableStringBuffer("RMG_terrain", temp, MAX_QPATH);
/*
// Create the parser for the mission file
if(Com_ParseTextFile(va("ext_data/rmg/%s.teams", temp), parser))
{
root = parser.GetBaseParseGroup()->GetSubGroups();
if (0 == stricmp(root->GetName(), "teams"))
{
SV_SetConfigstring( CS_GAMETYPE_REDTEAM, root->FindPairValue ( "red", "marine" ));
SV_SetConfigstring( CS_GAMETYPE_BLUETEAM, root->FindPairValue ( "blue", "thug" ));
}
parser.Clean();
}
*/
//rww - This is single player, no such thing.
}
// Must have a valid landscape before we can spawn the mission
assert ( mLandScape );
#ifndef FINAL_BUILD
Com_Printf ("------------------------------------------\n");
#endif
return true;
}
/************************************************************************************************
* CRMManager::IsMissionComplete
* Determines whether or not all the arioche objectives have been met
*
* inputs:
* none
*
* return:
* true: all objectives have been completed
* false: one or more of the objectives has not been met
*
************************************************************************************************/
bool CRMManager::IsMissionComplete(void)
{
if ( NULL == mMission->GetCurrentObjective ( ) )
{
return true;
}
return false;
}
/************************************************************************************************
* CRMManager::HasTimeExpired
* Determines whether or not the time limit (if one) has expired
*
* inputs:
* none
*
* return:
* true: time limit has expired
* false: time limit has not expired
*
************************************************************************************************/
bool CRMManager::HasTimeExpired(void)
{
/* if (mMission->GetTimeLimit() == 0 || !mUseTimeLimit)
{ // no time limit set
return false;
}
if (mMission->GetTimeLimit() * 1000 * 60 > level.time - level.startTime)
{ // we are still under our time limit
return false;
}
// over our time limit!
return true;*/
return false;
}
/************************************************************************************************
* CRMManager::UpdateStatisticCvars
* Updates the statistic cvars with data from the game
*
* inputs:
* none
*
* return:
* none
*
************************************************************************************************/
void CRMManager::UpdateStatisticCvars ( void )
{
/* // No player set then nothing more to do
if ( mPlayer )
{
float accuracy;
// Calculate the accuracy
accuracy = (float)mPlayer->client->ps.persistant[PERS_SHOTS_HIT];
accuracy /= (float)mPlayer->client->ps.persistant[PERS_SHOTS];
accuracy *= 100.0f;
// set the accuracy cvar
gi.Cvar_Set ( "ar_pl_accuracy", va("%d%%",(int)accuracy) );
// Set the # of kills cvar
gi.Cvar_Set ( "ar_kills", va("%d", mPlayer->client->ps.persistant[PERS_SCORE] ) );
int hours;
int mins;
int seconds;
int tens;
int millisec = (level.time - level.startTime);
seconds = millisec / 1000;
hours = seconds / (60 * 60);
seconds -= (hours * 60 * 60);
mins = seconds / 60;
seconds -= mins * 60;
tens = seconds / 10;
seconds -= tens * 10;
gi.Cvar_Set ( "ar_duration", va("%dhr %dmin %dsec", hours, mins, seconds ) );
WpnID wpnID = TheWpnSysMgr().GetFavoriteWeapon ( );
gi.Cvar_Set ( "ar_fav_wp", CWeaponSystem::GetWpnName ( wpnID ) );
// show difficulty
char difficulty[MAX_QPATH];
gi.Cvar_VariableStringBuffer("g_skill", difficulty, MAX_QPATH);
strupr(difficulty);
gi.Cvar_Set ( "ar_diff", va("&GENERIC_%s&",difficulty) );
// compute rank
float compositeRank = 1;
int rankMax = 3; // max rank less 1
float timeRank = mUseTimeLimit ? (1.0f - (mins / (float)mMission->GetTimeLimit())) : 0;
float killRank = mPlayer->client->ps.persistant[PERS_SCORE] / (float)GetCharacterManager().GetAllSize();
killRank = (killRank > 0) ? killRank : 1.0f;
float accuRank = (accuracy > 0) ? accuracy*0.01f : 1.0f;
float weapRank = 1.0f - CWeaponSystem::GetRank(wpnID);
compositeRank = ((timeRank + killRank + accuRank + weapRank) / 3.0f) * rankMax + 1;
if (compositeRank > 4)
compositeRank = 4;
gi.Cvar_Set ( "ar_rank", va("&RMG_RANK%d&",((int)compositeRank)) );
}*/
}
/************************************************************************************************
* CRMManager::CompleteMission
* Does end-of-mission stuff (pause game, end screen, return to menu)
* <Description> *
* Input *
* <Variable>: <Description> *
* Output / Return *
* <Variable>: <Description> *
************************************************************************************************/
void CRMManager::CompleteMission(void)
{
UpdateStatisticCvars ( );
mMission->CompleteMission();
}
/************************************************************************************************
* CRMManager::FailedMission
* Does end-of-mission stuff (pause game, end screen, return to menu)
* <Description> *
* Input *
* TimeExpired: indicates if the reason failed was because of time
* Output / Return *
* <Variable>: <Description> *
************************************************************************************************/
void CRMManager::FailedMission(bool TimeExpired)
{
UpdateStatisticCvars ( );
mMission->FailedMission(TimeExpired);
}
/************************************************************************************************
* CRMManager::CompleteObjective
* Marks the given objective as completed
*
* inputs:
* obj: objective to set as completed
*
* return:
* none
*
************************************************************************************************/
void CRMManager::CompleteObjective ( CRMObjective *obj )
{
assert ( obj );
mMission->CompleteObjective ( obj );
}
/************************************************************************************************
* CRMManager::Preview
* previews the random mission genration information
*
* inputs:
* from: origin being previed from
*
* return:
* none
*
************************************************************************************************/
void CRMManager::Preview ( const vec3_t from )
{
// Dont bother if we havent reached our timer yet
/* if ( level.time < mPreviewTimer )
{
return;
}
// Let the mission do all the previewing
mMission->Preview ( from );
// Another second
mPreviewTimer = level.time + 1000;*/
}
/************************************************************************************************
* CRMManager::Preview
* previews the random mission genration information
*
* inputs:
* from: origin being previed from
*
* return:
* none
*
************************************************************************************************/
bool CRMManager::SpawnMission ( qboolean IsServer )
{
// Spawn the mission
mMission->Spawn ( mTerrain, IsServer );
return true;
}