forked from APGRoboCop/foxbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfworld.cpp
991 lines (819 loc) · 28 KB
/
fworld.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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
/***
*
* Copyright (c) 1999, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
/*
===== world.cpp ========================================================
precaches and defs for entities and other data that must always be available.
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "nodes.h"
#include "soundent.h"
#include "client.h"
#include "decals.h"
#include "skill.h"
#include "effects.h"
#include "player.h"
#include "weapons.h"
#include "gamerules.h"
#include "teamplay_gamerules.h"
extern CGraph WorldGraph;
extern CSoundEnt* pSoundEnt;
extern CBaseEntity* g_pLastSpawn;
DLL_GLOBAL edict_t* g_pBodyQueueHead;
CGlobalState gGlobalState;
extern DLL_GLOBAL int gDisplayTitle;
extern void W_Precache(void);
extern DLL_GLOBAL Vector g_vecAttackDir;
CGraph WorldGraph;
MULTIDAMAGE gMultiDamage;
DLL_GLOBAL CGameRules* g_pGameRules;
DLL_GLOBAL short g_sModelIndexBloodDrop; // holds the sprite index for the initial blood
DLL_GLOBAL short g_sModelIndexBloodSpray; // holds the sprite index for splattered blood
//
// This must match the list in util.h
//
DLL_DECALLIST gDecals[] = {
{ "{shot1", 0 }, // DECAL_GUNSHOT1
{ "{shot2", 0 }, // DECAL_GUNSHOT2
{ "{shot3", 0 }, // DECAL_GUNSHOT3
{ "{shot4", 0 }, // DECAL_GUNSHOT4
{ "{shot5", 0 }, // DECAL_GUNSHOT5
{ "{lambda01", 0 }, // DECAL_LAMBDA1
{ "{lambda02", 0 }, // DECAL_LAMBDA2
{ "{lambda03", 0 }, // DECAL_LAMBDA3
{ "{lambda04", 0 }, // DECAL_LAMBDA4
{ "{lambda05", 0 }, // DECAL_LAMBDA5
{ "{lambda06", 0 }, // DECAL_LAMBDA6
{ "{scorch1", 0 }, // DECAL_SCORCH1
{ "{scorch2", 0 }, // DECAL_SCORCH2
{ "{blood1", 0 }, // DECAL_BLOOD1
{ "{blood2", 0 }, // DECAL_BLOOD2
{ "{blood3", 0 }, // DECAL_BLOOD3
{ "{blood4", 0 }, // DECAL_BLOOD4
{ "{blood5", 0 }, // DECAL_BLOOD5
{ "{blood6", 0 }, // DECAL_BLOOD6
{ "{yblood1", 0 }, // DECAL_YBLOOD1
{ "{yblood2", 0 }, // DECAL_YBLOOD2
{ "{yblood3", 0 }, // DECAL_YBLOOD3
{ "{yblood4", 0 }, // DECAL_YBLOOD4
{ "{yblood5", 0 }, // DECAL_YBLOOD5
{ "{yblood6", 0 }, // DECAL_YBLOOD6
{ "{break1", 0 }, // DECAL_GLASSBREAK1
{ "{break2", 0 }, // DECAL_GLASSBREAK2
{ "{break3", 0 }, // DECAL_GLASSBREAK3
{ "{bigshot1", 0 }, // DECAL_BIGSHOT1
{ "{bigshot2", 0 }, // DECAL_BIGSHOT2
{ "{bigshot3", 0 }, // DECAL_BIGSHOT3
{ "{bigshot4", 0 }, // DECAL_BIGSHOT4
{ "{bigshot5", 0 }, // DECAL_BIGSHOT5
{ "{spit1", 0 }, // DECAL_SPIT1
{ "{spit2", 0 }, // DECAL_SPIT2
{ "{bproof1", 0 }, // DECAL_BPROOF1
{ "{gargstomp", 0 }, // DECAL_GARGSTOMP1, // Gargantua stomp crack
{ "{smscorch1", 0 }, // DECAL_SMALLSCORCH1, // Small scorch mark
{ "{smscorch2", 0 }, // DECAL_SMALLSCORCH2, // Small scorch mark
{ "{smscorch3", 0 }, // DECAL_SMALLSCORCH3, // Small scorch mark
{ "{mommablob", 0 }, // DECAL_MOMMABIRTH // BM Birth spray
{ "{mommablob", 0 }, // DECAL_MOMMASPLAT // BM Mortar spray?? need decal
};
BOOL UTIL_ShouldShowBlood(int color)
{
if(color != DONT_BLEED) {
if(color == BLOOD_COLOR_RED) {
if(CVAR_GET_FLOAT("violence_hblood") != 0)
return TRUE;
} else {
if(CVAR_GET_FLOAT("violence_ablood") != 0)
return TRUE;
}
}
return FALSE;
}
void UTIL_BloodDecalTrace(TraceResult* pTrace, int bloodColor)
{
if(UTIL_ShouldShowBlood(bloodColor)) {
if(bloodColor == BLOOD_COLOR_RED)
UTIL_DecalTrace(pTrace, DECAL_BLOOD1 + RANDOM_LONG(0, 5));
else
UTIL_DecalTrace(pTrace, DECAL_YBLOOD1 + RANDOM_LONG(0, 5));
}
}
void UTIL_DecalTrace(TraceResult* pTrace, int decalNumber)
{
short entityIndex;
int index;
int message;
if(decalNumber < 0)
return;
index = gDecals[decalNumber].index;
if(index < 0)
return;
if(pTrace->flFraction == 1.0)
return;
// Only decal BSP models
if(pTrace->pHit) {
CBaseEntity* pEntity = CBaseEntity::Instance(pTrace->pHit);
if(pEntity && !pEntity->IsBSPModel())
return;
entityIndex = ENTINDEX(pTrace->pHit);
} else
entityIndex = 0;
message = TE_DECAL;
if(entityIndex != 0) {
if(index > 255) {
message = TE_DECALHIGH;
index -= 256;
}
} else {
message = TE_WORLDDECAL;
if(index > 255) {
message = TE_WORLDDECALHIGH;
index -= 256;
}
}
MESSAGE_BEGIN(MSG_BROADCAST, SVC_TEMPENTITY);
WRITE_BYTE(message);
WRITE_COORD(pTrace->vecEndPos.x);
WRITE_COORD(pTrace->vecEndPos.y);
WRITE_COORD(pTrace->vecEndPos.z);
WRITE_BYTE(index);
if(entityIndex)
WRITE_SHORT(entityIndex);
MESSAGE_END();
}
void UTIL_BloodDrips(const Vector& origin, const Vector& direction, int color, int amount)
{
if(!UTIL_ShouldShowBlood(color))
return;
if(color == DONT_BLEED || amount == 0)
return;
if(g_Language == LANGUAGE_GERMAN && color == BLOOD_COLOR_RED)
color = 0;
if(g_pGameRules->IsMultiplayer()) {
// scale up blood effect in multiplayer for better visibility
amount *= 2;
}
if(amount > 255)
amount = 255;
MESSAGE_BEGIN(MSG_PVS, SVC_TEMPENTITY, origin);
WRITE_BYTE(TE_BLOODSPRITE);
WRITE_COORD(origin.x); // pos
WRITE_COORD(origin.y);
WRITE_COORD(origin.z);
WRITE_SHORT(g_sModelIndexBloodSpray); // initial sprite model
WRITE_SHORT(g_sModelIndexBloodDrop); // droplet sprite models
WRITE_BYTE(color); // color index into host_basepal
WRITE_BYTE(min(max(3, amount / 10), 16)); // size
MESSAGE_END();
}
BOOL CBaseEntity::FVisible(CBaseEntity* pEntity)
{
return FALSE;
}
BOOL CBaseEntity::FVisible(const Vector& vecOrigin)
{
return FALSE;
}
void SpawnBlood(Vector vecSpot, int bloodColor, float flDamage)
{
UTIL_BloodDrips(vecSpot, g_vecAttackDir, bloodColor, (int)flDamage);
}
void ApplyMultiDamage(entvars_t* pevInflictor, entvars_t* pevAttacker)
{
Vector vecSpot1; // where blood comes from
Vector vecDir; // direction blood should go
TraceResult tr;
if(!gMultiDamage.pEntity)
return;
gMultiDamage.pEntity->TakeDamage(pevInflictor, pevAttacker, gMultiDamage.amount, gMultiDamage.type);
}
void AddMultiDamage(entvars_t* pevInflictor, CBaseEntity* pEntity, float flDamage, int bitsDamageType)
{
if(!pEntity)
return;
gMultiDamage.type |= bitsDamageType;
if(pEntity != gMultiDamage.pEntity) {
ApplyMultiDamage(pevInflictor, pevInflictor); // UNDONE: wrong attacker!
gMultiDamage.pEntity = pEntity;
gMultiDamage.amount = 0;
}
gMultiDamage.amount += flDamage;
}
void CBaseEntity::TraceAttack(entvars_t* pevAttacker,
float flDamage,
Vector vecDir,
TraceResult* ptr,
int bitsDamageType)
{
Vector vecOrigin = ptr->vecEndPos - vecDir * 4;
if(pev->takedamage) {
AddMultiDamage(pevAttacker, this, flDamage, bitsDamageType);
int blood = BloodColor();
if(blood != DONT_BLEED) {
SpawnBlood(vecOrigin, blood, flDamage); // a little surface blood.
TraceBleed(flDamage, vecDir, ptr, bitsDamageType);
}
}
}
void CBaseEntity::TraceBleed(float flDamage, Vector vecDir, TraceResult* ptr, int bitsDamageType)
{
if(BloodColor() == DONT_BLEED)
return;
if(flDamage == 0)
return;
if(!(bitsDamageType & (DMG_CRUSH | DMG_BULLET | DMG_SLASH | DMG_BLAST | DMG_CLUB | DMG_MORTAR)))
return;
// make blood decal on the wall!
TraceResult Bloodtr;
Vector vecTraceDir;
float flNoise;
int cCount;
int i;
/*
if ( !IsAlive() )
{
// dealing with a dead monster.
if ( pev->max_health <= 0 )
{
// no blood decal for a monster that has already decalled its limit.
return;
}
else
{
pev->max_health--;
}
}
*/
if(flDamage < 10) {
flNoise = 0.1;
cCount = 1;
} else if(flDamage < 25) {
flNoise = 0.2;
cCount = 2;
} else {
flNoise = 0.3;
cCount = 4;
}
for(i = 0; i < cCount; i++) {
vecTraceDir =
vecDir * -1; // trace in the opposite direction the shot came from (the direction the shot is going)
vecTraceDir.x += RANDOM_FLOAT(-flNoise, flNoise);
vecTraceDir.y += RANDOM_FLOAT(-flNoise, flNoise);
vecTraceDir.z += RANDOM_FLOAT(-flNoise, flNoise);
UTIL_TraceLine(ptr->vecEndPos, ptr->vecEndPos + vecTraceDir * -172, ignore_monsters, ENT(pev), &Bloodtr);
if(Bloodtr.flFraction != 1.0) {
UTIL_BloodDecalTrace(&Bloodtr, BloodColor());
}
}
}
/*
==============================================================================
BODY QUE
==============================================================================
*/
#define SF_DECAL_NOTINDEATHMATCH 2048
class CDecal : public CBaseEntity
{
public:
void Spawn(void);
void KeyValue(KeyValueData* pkvd);
void EXPORT StaticDecal(void);
void EXPORT TriggerDecal(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value);
};
// LINK_ENTITY_TO_CLASS( infodecal, CDecal );
// UNDONE: These won't get sent to joining players in multi-player
void CDecal::Spawn(void)
{
FILE* fp;
{
fp = fopen("bot.txt", "a");
fprintf(fp, "decal!\n");
fclose(fp);
}
/*if ( pev->skin < 0 || (gpGlobals->deathmatch && FBitSet( pev->spawnflags, SF_DECAL_NOTINDEATHMATCH )) )
{
REMOVE_ENTITY(ENT(pev));
return;
}
if ( FStringNull ( pev->targetname ) )
{
SetThink( StaticDecal );
// if there's no targetname, the decal will spray itself on as soon as the world is done spawning.
pev->nextthink = gpGlobals->time;
}
else
{
// if there IS a targetname, the decal sprays itself on when it is triggered.
SetThink ( SUB_DoNothing );
SetUse(TriggerDecal);
}*/
}
void CDecal::TriggerDecal(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value)
{
FILE* fp;
{
fp = fopen("bot.txt", "a");
fprintf(fp, "decal!\n");
fclose(fp);
}
// this is set up as a USE function for infodecals that have targetnames, so that the
// decal doesn't get applied until it is fired. (usually by a scripted sequence)
/*TraceResult trace;
int entityIndex;
UTIL_TraceLine( pev->origin - Vector(5,5,5), pev->origin + Vector(5,5,5), ignore_monsters, ENT(pev), &trace );
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY);
WRITE_BYTE( TE_BSPDECAL );
WRITE_COORD( pev->origin.x );
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_SHORT( (int)pev->skin );
entityIndex = (short)ENTINDEX(trace.pHit);
WRITE_SHORT( entityIndex );
if ( entityIndex )
WRITE_SHORT( (int)VARS(trace.pHit)->modelindex );
MESSAGE_END();
SetThink( SUB_Remove );
pev->nextthink = gpGlobals->time + 0.1;*/
}
void CDecal::StaticDecal(void)
{
FILE* fp;
{
fp = fopen("bot.txt", "a");
fprintf(fp, "decal!\n");
fclose(fp);
}
/*TraceResult trace;
int entityIndex, modelIndex;
UTIL_TraceLine( pev->origin - Vector(5,5,5), pev->origin + Vector(5,5,5), ignore_monsters, ENT(pev), &trace );
entityIndex = (short)ENTINDEX(trace.pHit);
if ( entityIndex )
modelIndex = (int)VARS(trace.pHit)->modelindex;
else
modelIndex = 0;
g_engfuncs.pfnStaticDecal( pev->origin, (int)pev->skin, entityIndex, modelIndex );
SUB_Remove();*/
}
void CDecal::KeyValue(KeyValueData* pkvd)
{
/*if (FStrEq(pkvd->szKeyName, "texture"))
{
pev->skin = DECAL_INDEX( pkvd->szValue );
// Found
if ( pev->skin >= 0 )
return;
ALERT( at_console, "Can't find decal %s\n", pkvd->szValue );
}
else
CBaseEntity::KeyValue( pkvd );*/
}
// Body queue class here.... It's really just CBaseEntity
/*class CCorpse : public CBaseEntity
{
virtual int ObjectCaps( void ) { return FCAP_DONT_SAVE; }
};
LINK_ENTITY_TO_CLASS( bodyque, CCorpse );
static void InitBodyQue(void)
{
string_t istrClassname = MAKE_STRING("bodyque");
g_pBodyQueueHead = CREATE_NAMED_ENTITY( istrClassname );
entvars_t *pev = VARS(g_pBodyQueueHead);
// Reserve 3 more slots for dead bodies
for ( int i = 0; i < 3; i++ )
{
pev->owner = CREATE_NAMED_ENTITY( istrClassname );
pev = VARS(pev->owner);
}
pev->owner = g_pBodyQueueHead;
}
//
// make a body que entry for the given ent so the ent can be respawned elsewhere
//
// GLOBALS ASSUMED SET: g_eoBodyQueueHead
//
void CopyToBodyQue(entvars_t *pev)
{
if (pev->effects & EF_NODRAW)
return;
entvars_t *pevHead = VARS(g_pBodyQueueHead);
pevHead->angles = pev->angles;
pevHead->model = pev->model;
pevHead->modelindex = pev->modelindex;
pevHead->frame = pev->frame;
pevHead->colormap = pev->colormap;
pevHead->movetype = MOVETYPE_TOSS;
pevHead->velocity = pev->velocity;
pevHead->flags = 0;
pevHead->deadflag = pev->deadflag;
pevHead->renderfx = kRenderFxDeadPlayer;
pevHead->renderamt = ENTINDEX( ENT( pev ) );
pevHead->effects = pev->effects | EF_NOINTERP;
//pevHead->goalstarttime = pev->goalstarttime;
//pevHead->goalframe = pev->goalframe;
//pevHead->goalendtime = pev->goalendtime ;
pevHead->sequence = pev->sequence;
pevHead->animtime = pev->animtime;
UTIL_SetOrigin(pevHead, pev->origin);
UTIL_SetSize(pevHead, pev->mins, pev->maxs);
g_pBodyQueueHead = pevHead->owner;
}
*/
CGlobalState::CGlobalState(void)
{
Reset();
}
void CGlobalState::Reset(void)
{
m_pList = NULL;
m_listCount = 0;
}
globalentity_t* CGlobalState::Find(string_t globalname)
{
if(!globalname)
return NULL;
globalentity_t* pTest;
const char* pEntityName = STRING(globalname);
pTest = m_pList;
while(pTest) {
if(FStrEq(pEntityName, pTest->name))
break;
pTest = pTest->pNext;
}
return pTest;
}
/*
// This is available all the time now on impulse 104, remove later
//#ifdef _DEBUG
void CGlobalState :: DumpGlobals( void )
{
static char *estates[] = { "Off", "On", "Dead" };
globalentity_t *pTest;
ALERT( at_console, "-- Globals --\n" );
pTest = m_pList;
while ( pTest )
{
ALERT( at_console, "%s: %s (%s)\n", pTest->name, pTest->levelName, estates[pTest->state] );
pTest = pTest->pNext;
}
}
//#endif
void CGlobalState :: EntityAdd( string_t globalname, string_t mapName, GLOBALESTATE state )
{
ASSERT( !Find(globalname) );
globalentity_t *pNewEntity = (globalentity_t *)calloc( sizeof( globalentity_t ), 1 );
ASSERT( pNewEntity != NULL );
pNewEntity->pNext = m_pList;
m_pList = pNewEntity;
strcpy( pNewEntity->name, STRING( globalname ) );
strcpy( pNewEntity->levelName, STRING(mapName) );
pNewEntity->state = state;
m_listCount++;
}
*/
void CGlobalState::EntitySetState(string_t globalname, GLOBALESTATE state)
{
globalentity_t* pEnt = Find(globalname);
if(pEnt)
pEnt->state = state;
}
/*
const globalentity_t *CGlobalState :: EntityFromTable( string_t globalname )
{
globalentity_t *pEnt = Find( globalname );
return pEnt;
}
GLOBALESTATE CGlobalState :: EntityGetState( string_t globalname )
{
globalentity_t *pEnt = Find( globalname );
if ( pEnt )
return pEnt->state;
return GLOBAL_OFF;
}
// Global Savedata for Delay
TYPEDESCRIPTION CGlobalState::m_SaveData[] =
{
DEFINE_FIELD( CGlobalState, m_listCount, FIELD_INTEGER ),
};
// Global Savedata for Delay
TYPEDESCRIPTION gGlobalEntitySaveData[] =
{
DEFINE_ARRAY( globalentity_t, name, FIELD_CHARACTER, 64 ),
DEFINE_ARRAY( globalentity_t, levelName, FIELD_CHARACTER, 32 ),
DEFINE_FIELD( globalentity_t, state, FIELD_INTEGER ),
};
int CGlobalState::Save( CSave &save )
{
int i;
globalentity_t *pEntity;
if ( !save.WriteFields( "GLOBAL", this, m_SaveData, ARRAYSIZE(m_SaveData) ) )
return 0;
pEntity = m_pList;
for ( i = 0; i < m_listCount && pEntity; i++ )
{
if ( !save.WriteFields( "GENT", pEntity, gGlobalEntitySaveData, ARRAYSIZE(gGlobalEntitySaveData) ) )
return 0;
pEntity = pEntity->pNext;
}
return 1;
}
int CGlobalState::Restore( CRestore &restore )
{
int i, listCount;
globalentity_t tmpEntity;
ClearStates();
if ( !restore.ReadFields( "GLOBAL", this, m_SaveData, ARRAYSIZE(m_SaveData) ) )
return 0;
listCount = m_listCount; // Get new list count
m_listCount = 0; // Clear loaded data
for ( i = 0; i < listCount; i++ )
{
if ( !restore.ReadFields( "GENT", &tmpEntity, gGlobalEntitySaveData, ARRAYSIZE(gGlobalEntitySaveData) )
)
return 0;
EntityAdd( MAKE_STRING(tmpEntity.name), MAKE_STRING(tmpEntity.levelName), tmpEntity.state );
}
return 1;
}
void CGlobalState::EntityUpdate( string_t globalname, string_t mapname )
{
globalentity_t *pEnt = Find( globalname );
if ( pEnt )
strcpy( pEnt->levelName, STRING(mapname) );
}
void CGlobalState::ClearStates( void )
{
globalentity_t *pFree = m_pList;
while ( pFree )
{
globalentity_t *pNext = pFree->pNext;
free( pFree );
pFree = pNext;
}
Reset();
}
*/
/*void SaveGlobalState( SAVERESTOREDATA *pSaveData )
{
CSave saveHelper( pSaveData );
gGlobalState.Save( saveHelper );
}
void RestoreGlobalState( SAVERESTOREDATA *pSaveData )
{
CRestore restoreHelper( pSaveData );
gGlobalState.Restore( restoreHelper );
}
void ResetGlobalState( void )
{
gGlobalState.ClearStates();
gInitHUD = TRUE; // Init the HUD on a new game / load game
}*/
// moved CWorld class definition to cbase.h
//=======================
// CWorld
//
// This spawns first when each level begins.
//=======================
/*
LINK_ENTITY_TO_CLASS( worldspawn, CWorld );
#define SF_WORLD_DARK 0x0001 // Fade from black at startup
#define SF_WORLD_TITLE 0x0002 // Display game title at startup
#define SF_WORLD_FORCETEAM 0x0004 // Force teams
extern DLL_GLOBAL BOOL g_fGameOver;
float g_flWeaponCheat;
void CWorld :: Spawn( void )
{
g_fGameOver = FALSE;
Precache( );
g_flWeaponCheat = CVAR_GET_FLOAT( "sv_cheats" ); // Is the impulse 101 command allowed?
}
void CWorld :: Precache( void )
{
g_pLastSpawn = NULL;
#if 1
CVAR_SET_STRING("sv_gravity", "800"); // 67ft/sec
CVAR_SET_STRING("sv_stepsize", "18");
#else
CVAR_SET_STRING("sv_gravity", "384"); // 32ft/sec
CVAR_SET_STRING("sv_stepsize", "24");
#endif
CVAR_SET_STRING("room_type", "0");// clear DSP
// Set up game rules
if (g_pGameRules)
{
delete g_pGameRules;
}
g_pGameRules = InstallGameRules( );
//!!!UNDONE why is there so much Spawn code in the Precache function? I'll just keep it here
///!!!LATER - do we want a sound ent in deathmatch? (sjb)
//pSoundEnt = CBaseEntity::Create( "soundent", g_vecZero, g_vecZero, edict() );
pSoundEnt = GetClassPtr( ( CSoundEnt *)NULL );
pSoundEnt->Spawn();
if ( !pSoundEnt )
{
ALERT ( at_console, "**COULD NOT CREATE SOUNDENT**\n" );
}
InitBodyQue();
// init sentence group playback stuff from sentences.txt.
// ok to call this multiple times, calls after first are ignored.
SENTENCEG_Init();
// init texture type array from materials.txt
TEXTURETYPE_Init();
// the area based ambient sounds MUST be the first precache_sounds
// player precaches
W_Precache (); // get weapon precaches
ClientPrecache();
// sounds used from C physics code
PRECACHE_SOUND("common/null.wav"); // clears sound channels
PRECACHE_SOUND( "items/suitchargeok1.wav" );//!!! temporary sound for respawning weapons.
PRECACHE_SOUND( "items/gunpickup2.wav" );// player picks up a gun.
PRECACHE_SOUND( "common/bodydrop3.wav" );// dead bodies hitting the ground (animation events)
PRECACHE_SOUND( "common/bodydrop4.wav" );
g_Language = (int)CVAR_GET_FLOAT( "sv_language" );
if ( g_Language == LANGUAGE_GERMAN )
{
PRECACHE_MODEL( "models/germangibs.mdl" );
}
else
{
PRECACHE_MODEL( "models/hgibs.mdl" );
PRECACHE_MODEL( "models/agibs.mdl" );
}
PRECACHE_SOUND ("weapons/ric1.wav");
PRECACHE_SOUND ("weapons/ric2.wav");
PRECACHE_SOUND ("weapons/ric3.wav");
PRECACHE_SOUND ("weapons/ric4.wav");
PRECACHE_SOUND ("weapons/ric5.wav");
//
// Setup light animation tables. 'a' is total darkness, 'z' is maxbright.
//
// 0 normal
LIGHT_STYLE(0, "m");
// 1 FLICKER (first variety)
LIGHT_STYLE(1, "mmnmmommommnonmmonqnmmo");
// 2 SLOW STRONG PULSE
LIGHT_STYLE(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
// 3 CANDLE (first variety)
LIGHT_STYLE(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
// 4 FAST STROBE
LIGHT_STYLE(4, "mamamamamama");
// 5 GENTLE PULSE 1
LIGHT_STYLE(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
// 6 FLICKER (second variety)
LIGHT_STYLE(6, "nmonqnmomnmomomno");
// 7 CANDLE (second variety)
LIGHT_STYLE(7, "mmmaaaabcdefgmmmmaaaammmaamm");
// 8 CANDLE (third variety)
LIGHT_STYLE(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
// 9 SLOW STROBE (fourth variety)
LIGHT_STYLE(9, "aaaaaaaazzzzzzzz");
// 10 FLUORESCENT FLICKER
LIGHT_STYLE(10, "mmamammmmammamamaaamammma");
// 11 SLOW PULSE NOT FADE TO BLACK
LIGHT_STYLE(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
// 12 UNDERWATER LIGHT MUTATION
// this light only distorts the lightmap - no contribution
// is made to the brightness of affected surfaces
LIGHT_STYLE(12, "mmnnmmnnnmmnn");
// styles 32-62 are assigned by the light program for switchable lights
// 63 testing
LIGHT_STYLE(63, "a");
for ( int i = 0; i < ARRAYSIZE(gDecals); i++ )
gDecals[i].index = DECAL_INDEX( gDecals[i].name );
// init the WorldGraph.
WorldGraph.InitGraph();
// make sure the .NOD file is newer than the .BSP file.
if ( !WorldGraph.CheckNODFile ( ( char * )STRING( gpGlobals->mapname ) ) )
{// NOD file is not present, or is older than the BSP file.
WorldGraph.AllocNodes ();
}
else
{// Load the node graph for this level
if ( !WorldGraph.FLoadGraph ( (char *)STRING( gpGlobals->mapname ) ) )
{// couldn't load, so alloc and prepare to build a graph.
ALERT ( at_console, "*Error opening .NOD file\n" );
WorldGraph.AllocNodes ();
}
else
{
ALERT ( at_console, "\n*Graph Loaded!\n" );
}
}
if ( pev->speed > 0 )
CVAR_SET_FLOAT( "sv_zmax", pev->speed );
else
CVAR_SET_FLOAT( "sv_zmax", 4096 );
if ( pev->netname )
{
ALERT( at_aiconsole, "Chapter title: %s\n", STRING(pev->netname) );
CBaseEntity *pEntity = CBaseEntity::Create( "env_message", g_vecZero, g_vecZero, NULL );
if ( pEntity )
{
pEntity->SetThink( SUB_CallUseToggle );
pEntity->pev->message = pev->netname;
pev->netname = 0;
pEntity->pev->nextthink = gpGlobals->time + 0.3;
pEntity->pev->spawnflags = SF_MESSAGE_ONCE;
}
}
if ( pev->spawnflags & SF_WORLD_DARK )
CVAR_SET_FLOAT( "v_dark", 1.0 );
else
CVAR_SET_FLOAT( "v_dark", 0.0 );
if ( pev->spawnflags & SF_WORLD_TITLE )
gDisplayTitle = TRUE; // display the game title if this key is set
else
gDisplayTitle = FALSE;
if ( pev->spawnflags & SF_WORLD_FORCETEAM )
{
CVAR_SET_FLOAT( "mp_defaultteam", 1 );
}
else
{
CVAR_SET_FLOAT( "mp_defaultteam", 0 );
}
}
//
// Just to ignore the "wad" field.
//
void CWorld :: KeyValue( KeyValueData *pkvd )
{
if ( FStrEq(pkvd->szKeyName, "skyname") )
{
// Sent over net now.
CVAR_SET_STRING( "sv_skyname", pkvd->szValue );
pkvd->fHandled = TRUE;
}
else if ( FStrEq(pkvd->szKeyName, "sounds") )
{
gpGlobals->cdAudioTrack = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if ( FStrEq(pkvd->szKeyName, "WaveHeight") )
{
// Sent over net now.
pev->scale = atof(pkvd->szValue) * (1.0/8.0);
pkvd->fHandled = TRUE;
CVAR_SET_FLOAT( "sv_wateramp", pev->scale );
}
else if ( FStrEq(pkvd->szKeyName, "MaxRange") )
{
pev->speed = atof(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if ( FStrEq(pkvd->szKeyName, "chaptertitle") )
{
pev->netname = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if ( FStrEq(pkvd->szKeyName, "startdark") )
{
// UNDONE: This is a gross hack!!! The CVAR is NOT sent over the client/sever link
// but it will work for single player
int flag = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
if ( flag )
pev->spawnflags |= SF_WORLD_DARK;
}
else if ( FStrEq(pkvd->szKeyName, "newunit") )
{
// Single player only. Clear save directory if set
if ( atoi(pkvd->szValue) )
CVAR_SET_FLOAT( "sv_newunit", 1 );
pkvd->fHandled = TRUE;
}
else if ( FStrEq(pkvd->szKeyName, "gametitle") )
{
if ( atoi(pkvd->szValue) )
pev->spawnflags |= SF_WORLD_TITLE;
pkvd->fHandled = TRUE;
}
else if ( FStrEq(pkvd->szKeyName, "mapteams") )
{
pev->team = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else if ( FStrEq(pkvd->szKeyName, "defaultteam") )
{
if ( atoi(pkvd->szValue) )
{
pev->spawnflags |= SF_WORLD_FORCETEAM;
}
pkvd->fHandled = TRUE;
}
else
CBaseEntity::KeyValue( pkvd );
}
*/