-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnarchy.cpp
More file actions
2417 lines (2026 loc) · 79.1 KB
/
Anarchy.cpp
File metadata and controls
2417 lines (2026 loc) · 79.1 KB
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
992
993
994
995
996
997
998
999
1000
/*
=========================================================
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE
PROPERTY OF OUTRAGE ENTERTAINMENT, INC.
('OUTRAGE'). OUTRAGE, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND
CONDITIONS HEREIN, GRANTS A ROYALTY-FREE,
PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY
SUCH END-USERS IN USING, DISPLAYING, AND
CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-
COMMERCIAL, ROYALTY OR REVENUE FREE PURPOSES.
IN NO EVENT SHALL THE END-USER USE THE
COMPUTER CODE CONTAINED HEREIN FOR REVENUE-
BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE
SAME BY USE OF THIS FILE.
COPYRIGHT 1999 OUTRAGE ENTERTAINMENT, INC. ALL
RIGHTS RESERVED.
=========================================================
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "idmfc.h" // Needed for DMFC
#include "Anarchy.h" // Some prototypes
#include "anarchystr.h" // String table header
#ifndef WIN32
#include <sys/time.h>
#endif
#include <limits.h>
#include <time.h>
#ifdef WIN32
#include <windows.h>
#endif
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
// Anarchy HUD Modes
#define AHD_NONE 0 //No HUD
#define AHD_SCORE 1 //Show player score
#define AHD_EFFICIENCY 2 //Show player efficiency
#define SPID_RECEIVESHOT 6
// Anarchy HUD Color Modes
#define ACM_PLAYERCOLOR 0 //Use the color of their ship
#define ACM_NORMAL 1 //Use green
object *dObjects;
player *dPlayers;
#define ADD_SCORE 0
#define CHECK_VERSION 1
#define SPID_CHANGEW 2
#define SPID_CHANGEWREQUEST 3
#define SPID_RECEIVECHEAT 7
int version_num = 25;
bool first_shot = true;
float save_reload = 0;
int MassIndex=-1;
int PlayerColorIndexes[32];
unsigned long shipShootIntervals[32];
unsigned long playerLastShots[32];
// backups for manipulated weapons
int backupSounds[32];
float backupVelocity[32];
int backupFlags[32];
float backupPlayerDamage[32];
float backupGenericDamage[32];
short backupExplodeImageHandle[32];
short backupSmokeHandle[32];
float backupImpactPlayerDamage[32];
float backupImpactGenericDamage[32];
float backupImpactForce[32];
float backupLifeTime[32];
light_info backupLightInfo[32];
short backupSpawnHandle[32];
short backupScorchHandle[32];
int sndCheaterHandle = -1;
/*
Our DMFC Interface. All Interaction with DMFC is via this
*/
IDMFC *DMFCBase = NULL;
/*
Our DMFC Stats Interface (F7 Stats screen manager). All interaction
with the stats is via this
*/
IDmfcStats *dstat = NULL;
/*
SortedPlayers - An array of indicies into the Player records. This
gets sorted every frame and is used throughout the mod (for instance
when displaying the scores on the HUD. SortedPlayers[0] = the player record
value of the player in first place.
*/
int SortedPlayers[MAX_PLAYER_RECORDS]; //sorted player nums
/*
DisplayScoreScreen - true if the F7 Stats screen is up
*/
bool DisplayScoreScreen;
/*
Highlight_bmp - Bitmap handle for the highlight bar used on the HUD when
displaying the player names, to highlight your name
*/
int Highlight_bmp = -1;
/*
Anarchy_hud_display - What should we display on the HUD? Nothing? Player
scores? Player efficiencies? This is changed in the F6 On-Screen Menu
*/
ubyte Anarchy_hud_display = AHD_SCORE;
/*
HUD_color_model - What color mode is the HUD in? Should the players be displayed
using the color of their ship? Or just green. This is changed in the F6
On-Screen menu
*/
ubyte HUD_color_model = ACM_PLAYERCOLOR;
/*
display_my_welcom - Takes the value of false until we display the "Welcome" message
when you join/start an Anarchy game. HUD messages can't be displayed until the
first frame of the game has displayed, so we wait until then to display the welcome
message.
*/
bool display_my_welcome = false;
// HUD callback function when it is time to render our HUD
void DisplayHUDScores(struct tHUDItem *hitem);
// Displays a welcome message for a joining client
void DisplayWelcomeMessage(int player_num);
// Called with a filename to save the current state of the game
// stats to file.
void SaveStatsToFile(char *filename);
// Switches the HUD Color mode to a new value
void SwitchHUDColor(int i);
// SwitchAnarchyScores
//
// Call this function to switch the HUD display mode for what
// we display on the HUD (Player Scores/Player Efficiency/Nothing)
void SwitchAnarchyScores(int i);
///////////////////////////////////////////////
//localization info (string table functions and variables)
//
// String tables are only needed if you plan on making a multi-lingual mod.
char **StringTable;
char **D3StringTable;
int StringTableSize = 0;
int D3StringTableSize = 0;
char *_ErrorString = "Missing String";
char *GetString(int d){if( (d<0) || (d>=StringTableSize) ) return _ErrorString; else return StringTable[d];}
char *GetD3String(int d){if( (d<0) || (d>=D3StringTableSize) ) return _ErrorString; else return D3StringTable[d];}
///////////////////////////////////////////////
#ifdef MACINTOSH
#pragma export on
#endif
typedef struct {
int player_num;
}thisplayer;
thisplayer players[64];
int currentslot = 1;
#ifdef WIN32
struct timezone
{
int tz_minuteswest;
int tz_dsttime;
};
int gettimeofday (struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag = 0;
if (NULL != tv)
{
GetSystemTimeAsFileTime (&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
tmpres /= 10;
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
if (!tzflag)
{
_tzset ();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
#endif
void ReceiveCheatMessage(ubyte *data)
{
int iCount = 0;
int iPnum = 0;
iPnum = MultiGetInt(data, &iCount);
player *plrs = &(DMFCBase->GetPlayers())[iPnum];
DLLAddHUDMessage("%s was caught cheating or experiences severe lags - kicking...", plrs->callsign);
DLLPlay2dSound(sndCheaterHandle);
}
void SendCheatMessage(int pnum)
{
ubyte uData[MAX_GAME_DATA_SIZE];
int iCount = 0;
DMFCBase->StartPacket(uData, SPID_RECEIVECHEAT, &iCount);
MultiAddInt(pnum, uData, &iCount);
DMFCBase->SendPacket(uData, iCount, SP_ALL);
}
void SendChangeWeaponsRequest(int iPnum)
{
ubyte uData[MAX_GAME_DATA_SIZE];
int iCount = 0;
DMFCBase->StartPacket(uData, SPID_CHANGEWREQUEST, &iCount);
int iSaved = iCount;
MultiAddInt(iPnum, uData, &iCount);
if (DMFCBase->GetLocalRole() == LR_SERVER)
ReceiveSendChangeWeaponsRequest(&uData[iSaved]);
else
DMFCBase->SendPacket(uData, iCount, SP_SERVER);
}
void ReceiveSendChangeWeaponsRequest(ubyte *uData)
{
int iCount = 0;
int iPnum = 0;
iPnum = MultiGetInt(uData, &iCount);
int bCount = 0;
ubyte bData[MAX_GAME_DATA_SIZE];
DMFCBase->StartPacket(bData, SPID_CHANGEW, &bCount);
int bSaved = bCount;
MultiAddInt(iPnum, bData, &bCount);
DMFCBase->SendPacket(bData, bCount, SP_ALL);
ReceiveChangeWeapons(&bData[bSaved]);
}
void ReceiveChangeWeapons(ubyte *uData)
{
int iCount = 0;
int iPnum = 0;
iPnum = MultiGetInt(uData, &iCount);
AddWeaponToPlayer(iPnum,MASSDRIVER_INDEX,15);
RemWeaponFromPlayer(iPnum,LASER_INDEX);
ChangeWeapon(iPnum,MASSDRIVER_INDEX);
RemWeaponFromPlayer(iPnum,CONCUSSION_INDEX);
}
void CheckVersionNumber(ubyte *data)
{
int count = 0;
int ver = MultiGetInt(data,&count);
if(ver != version_num)
DMFCBase->DisconnectMe();
}
void GetVersionNumber(int pnum)
{
int count = 0;
ubyte data[MAX_GAME_DATA_SIZE];
DMFCBase->StartPacket(data,CHECK_VERSION,&count);
MultiAddInt(version_num,data,&count);
DMFCBase->SendPacket(data,count,pnum);
}
void OnServerPlayerKilled(object *killer_obj,int victim_pnum)
{
DMFCBase->OnServerPlayerKilled(killer_obj, victim_pnum);
}
void AddScoreToPlayer(ubyte *data)
{
int count = 0;
int pnum = MultiGetInt(data,&count);
player_record *pr = DMFCBase->GetPlayerRecordByPnum(pnum);
pr->dstats.kills[DSTAT_LEVEL]++;
}
void OnServerPlayerEntersGame(int player_num)
{
GetVersionNumber(player_num);
players[currentslot].player_num = player_num;
currentslot++;
DMFCBase->OnServerPlayerEntersGame(player_num);
}
void OnServerPlayerDisconnect(int player_num)
{
int checknum = 0;
while (!(player_num == players[checknum].player_num))
{
checknum++;
};
currentslot--;
players[checknum].player_num = players[currentslot].player_num;
DMFCBase->OnServerPlayerDisconnect(player_num);
}
void CheckPlayers(int number)
{
while(!(number == 0))
{
player *player = &(DMFCBase->GetPlayers())[players[number].player_num];
if(!(player->weapon_flags & HAS_FLAG(MASSDRIVER_INDEX)))
if(!(dPlayers[players[number].player_num].flags & PLAYER_FLAGS_DEAD))
{
AddWeaponToPlayer(players[number].player_num,MASSDRIVER_INDEX,15);
}
if(player->weapon_ammo[MASSDRIVER_INDEX] < 15)
if(!(dPlayers[players[number].player_num].flags & PLAYER_FLAGS_DEAD))
{
AddWeaponToPlayer(players[number].player_num,MASSDRIVER_INDEX,1);
}
number--;
};
}
void OnServerCollide(object *me_obj,object *it_obj)
{
/*if((me_obj->type == OBJ_PLAYER) && (it_obj->id == MASSDRIVER_INDEX))
{
DMFCBase->DoDamageToPlayer(me_obj->id,PD_NONE, (me_obj->shields + 5),false);
object *test_obj;
DLLObjGet(it_obj->parent_handle, &test_obj);
int count = 0;
ubyte data[MAX_GAME_DATA_SIZE];
DMFCBase->StartPacket(data,ADD_SCORE,&count);
MultiAddInt(test_obj->id,data,&count);
DMFCBase->SendPacket(data,count,SP_ALL);
DLLObjGet(it_obj->parent_handle, &test_obj);
player_record *pr = DMFCBase->GetPlayerRecordByPnum(test_obj->id);
pr->dstats.kills[DSTAT_LEVEL]++;
return;
}
*/
DMFCBase->OnServerCollide(me_obj,it_obj);
}
void SendPlayerShots(int pnum)
{
ubyte uData[MAX_GAME_DATA_SIZE];
int iCount = 0;
int iShots = 0;
DMFCBase->StartPacket(uData, SPID_RECEIVESHOT, &iCount);
MultiAddInt(pnum, uData, &iCount);
MultiAddInt(iShots, uData, &iCount);
DMFCBase->SendPacket(uData, iCount, SP_ALL);
}
void OnWeaponFired(object *weapon_obj,object *shooter)
{
if (DMFCBase->GetLocalRole() == LR_SERVER && weapon_obj->id != FLARE_INDEX && weapon_obj->id != 108) // 108 --> black pyro flare
{
struct timeval now;
gettimeofday(&now, NULL);
unsigned long recentShot = (now.tv_sec * (unsigned int)1e6 + now.tv_usec);
unsigned long difference;
// workaround for time running over the buffer of ULONG_MAX and starting at 0 again
if (recentShot < playerLastShots[shooter->id])
difference = ULONG_MAX - playerLastShots[shooter->id] + recentShot;
else
difference = recentShot - playerLastShots[shooter->id];
if (difference < shipShootIntervals[shooter->id] || (weapon_obj->id != MASSDRIVER_INDEX && weapon_obj->id != LASER_INDEX))
{
player *plrs = &(DMFCBase->GetPlayers())[shooter->id];
SendCheatMessage(shooter->id);
DLLAddHUDMessage("%s was caught cheating or experiences severe lagging - kicking...", plrs->callsign);
DLLPlay2dSound(sndCheaterHandle);
DLLMultiDisconnectPlayer(shooter->id);
}
else
playerLastShots[shooter->id] = recentShot;
}
if(DMFCBase->GetPlayerNum() == shooter->id && weapon_obj->id == MASSDRIVER_INDEX)
{
if(first_shot)
{
player *player = &(DMFCBase->GetPlayers())[shooter->id];
ship *ship = &(DMFCBase->GetShips())[player->ship_index];
ship->static_wb[6].gp_fire_wait[0] = save_reload;
first_shot = false;
}
}
if(weapon_obj->id == MassIndex)
{
DLLCreateAndFireWeapon(&weapon_obj->pos, &shooter->orient.fvec, shooter, PlayerColorIndexes[shooter->id]);
DLLCreateAndFireWeapon(&weapon_obj->pos, &shooter->orient.fvec, shooter, PlayerColorIndexes[shooter->id]);
}
if(DMFCBase->GetLocalRole() == LR_SERVER)
SendPlayerShots(shooter->id);
DMFCBase->OnWeaponFired(weapon_obj, shooter);
}
int CheckWeapon(int slot, int weap_index)
{
player *player = &(DMFCBase->GetPlayers())[slot];
//if any ammo has been used, we need to refill so that the player never runs out
if(player->weapon_ammo[weap_index] < 15)
{
int pnum = DMFCBase->GetPlayerNum(); //get the player's number
AddWeaponToPlayer(pnum,MASSDRIVER_INDEX,1);
}
return 1;
}
int ChangeWeapon(int slot, int weap_index)
{
//player *player = &(DMFCBase->GetPlayers())[slot];
//player->weapon[PRIMARY_INDEX].index = weap_index;
return 1;
}
int RemWeaponFromPlayer(int slot,int weap_index)
{
// Get the player and ship pointers for this player
player *player = &(DMFCBase->GetPlayers())[slot];
ship *ship = &(DMFCBase->GetShips())[player->ship_index];
// "Take" the weapon from the player
player->weapon_flags &= ~(HAS_FLAG(weap_index));
otype_wb_info *wb = &ship->static_wb[weap_index];
ASSERT(wb != NULL);
//if secondary or primary that uses ammo, then remove the ammo
if((weap_index >= SECONDARY_INDEX) || wb->ammo_usage)
{
//figure out much ammo to remove
int removed = player->weapon_ammo[weap_index];
//now add it
player->weapon_ammo[weap_index] = player->weapon_ammo[weap_index] - (ushort)removed;
}
return 1;
}
int AddWeaponToPlayer(int slot,int weap_index, int ammo)
{
// Get the player and ship pointers for this player
player *player = &(DMFCBase->GetPlayers())[slot];
ship *ship = &(DMFCBase->GetShips())[player->ship_index];
// "Give" the weapon to the player
player->weapon_flags |= HAS_FLAG(weap_index);
// get the weapon battery information for the given weapon
// it is ship dependent, since each ship can hold different
// amounts of ammo
otype_wb_info *wb = &ship->static_wb[weap_index];
ASSERT(wb != NULL);
//if secondary or primary that uses ammo, then use the ammo
if((weap_index >= SECONDARY_INDEX) || wb->ammo_usage)
{
//figure out much ammo to add
int added = ammo;
//(ship->max_ammo[weap_index] - player->weapon_ammo[weap_index],ammo);
//now add it
player->weapon_ammo[weap_index] += (ushort)added;
}
return 1;
}
// DLLGetGameInfo
//
// This function gets called by the game when it wants to learn some info about
// the multiplayer mod.
void DLLFUNCCALL DLLGetGameInfo (tDLLOptions *options)
{
// Specify what values we will be filling in
options->flags = DOF_MAXTEAMS; //only max teams
options->max_teams = 1; //not a team game, so it's a 1
// Mandatory values
strcpy(options->game_name,"XInstaReap"); // The name of our game
strcpy(options->requirements,""); // the MSN file KEYWORD requirements
// there are no requirements for
// Anarchy, all levels are ok
}
// DLLGameInit
//
// Call by the game when the D3M is loaded. Initialize everything
// required for the mod here.
//
// Parms:
// api_func : List of D3 exported functions and variable pointers
// You don't have to do anything with this but pass it
// to DMFC::LoadFunctions();
// all_ok : When this function returns, Descent 3 checks the bool this
// pointer points to. If it's true (1) then the game continues
// to load. If it's false (0) then Descent 3 refuses to load
// the mod.
// num_teams_to_use : In the case of team games (2, 3 or 4 teams), this is
// the value the user selected for the number of teams.
void DLLFUNCCALL DLLGameInit (int *api_func,ubyte *all_ok,int num_teams_to_use)
{
// Initialize all_ok to true
*all_ok = 1;
// This MUST BE the absolute first thing done. Create the DMFC interface.
// CreateDMFC() returns a pointer to an instance of a DMFC class. If it
// returns NULL there was some problem creating the DMFC instance and you
// must bail right away!
DMFCBase = CreateDMFC();
if(!DMFCBase)
{
//no all is not ok!
*all_ok = 0;
return;
}
// Since we want an F7 stats screen, we will now try to create an instance
// of DMFCStats class. Calling CreateDmfcStats() is just like CreateDMFC()
// but it creates an instance of DMFCStats.
dstat = CreateDmfcStats();
if(!dstat)
{
//no all is not ok!
*all_ok = 0;
return;
}
// We can't call any functions exported from Descent 3 until we initialize
// them. Calling DMFC::LoadFunctions() will initialize them.
DMFCBase->LoadFunctions(api_func);
// In order to capture events from the game, we must tell DMFC what
// events we want to get notified about. The following list of functions
// call the appropriate DMFC member function to register a callback for
// an event. When a callback is registered for an event, as soon as the event
// happens, the callback you give will be called. It is your responsibility
// to call the default event handler of the specific event, DMFC performs
// many behind-the-scenes work in these default handlers.
// register for the keypress event (the user pressed a key)
DMFCBase->Set_OnKeypress(OnKeypress);
// important for InstaReap - set function for weapon fire action
DMFCBase->Set_OnWeaponFired(OnWeaponFired);
// register for the HUD interval event (gets called once per frame when it
// is time to render the HUD)
DMFCBase->Set_OnHUDInterval(OnHUDInterval);
// register for the interval event (gets called once per frame)
DMFCBase->Set_OnInterval(OnInterval);
// register for the client version of the player killed event (gets called
// on all clients when a player dies)
DMFCBase->Set_OnClientPlayerKilled(OnClientPlayerKilled);
// register for the client version of the player joined game event (gets
// called on all clients when a player enters the game)
DMFCBase->Set_OnClientPlayerEntersGame(OnClientPlayerEntersGame);
// register for the client version of the level start event (gets called
// on all clients when they are about to start/enter a level)
DMFCBase->Set_OnClientLevelStart(OnClientLevelStart);
// register for the client version of the level end event (gets called on
// all clients when the level ends)
DMFCBase->Set_OnClientLevelEnd(OnClientLevelEnd);
// register for the server event, that a game has been created (gets called
// only once, when the mod is loaded)
DMFCBase->Set_OnServerGameCreated(OnServerGameCreated);
// register for the Post Level Results interval event (gets called every frame
// when it's time to render a Post Level Results screen)
DMFCBase->Set_OnPLRInterval(OnPLRInterval);
// register for the Post Level Results init event (gets called before the first
// frame of the Post Level Results, per level, so we can setup some values).
DMFCBase->Set_OnPLRInit(OnPLRInit);
// register for the Save Stats event (gets called when the client wants to save
// the game stats now!)
DMFCBase->Set_OnSaveStatsToFile(OnSaveStatsToFile);
// register for the Save End of level stats event (gets called when the level
// ends if the client wants the stats saved at the end of each level.)
DMFCBase->Set_OnLevelEndSaveStatsToFile(OnLevelEndSaveStatsToFile);
// register for the Save on Disconnect event (gets called when you get disconnected
// from the server for some reason and the client wants stats saved)
DMFCBase->Set_OnDisconnectSaveStatsToFile(OnDisconnectSaveStatsToFile);
// register for the print scores event (gets called when a dedicated server
// does a $scores request)
DMFCBase->Set_OnPrintScores(OnPrintScores);
// Since our version of anarchy is localized (same code works for multiple
// languages) we need to load our string table now. The function knows
// what language to load in automatically. Anarchy.str is located in
// Anarchy.d3m hog file of Descent 3. It needs to be in a place where
// Descent 3 will be able to find it.
DMFCBase->Set_OnServerCollide(OnServerCollide);
DMFCBase->Set_OnServerPlayerEntersGame(OnServerPlayerEntersGame);
DMFCBase->Set_OnServerPlayerDisconnect(OnServerPlayerDisconnect);
DMFCBase->Set_OnServerPlayerKilled(OnServerPlayerKilled);
DMFCBase->RegisterPacketReceiver(SPID_CHANGEWREQUEST, ReceiveSendChangeWeaponsRequest);
DMFCBase->RegisterPacketReceiver(SPID_CHANGEW, ReceiveChangeWeapons);
int index = DLLFindWeaponName("Mass Driver");
MassIndex = index;
weapon *md;
weapon *weapons = &(DMFCBase->GetWeapons())[index];
weapons->player_damage = 250;
weapons->flags |= WF_SMOKE;
weapons->flags |= WF_PLANAR_SMOKE;
md = weapons;
// initialize player shoot times
if (DMFCBase->GetLocalRole() == LR_SERVER)
{
struct timeval now;
gettimeofday(&now, NULL);
for (int i = 0; i < 32; ++i)
playerLastShots[i] = (now.tv_sec * (unsigned int)1e6 + now.tv_usec);
// support for up to 16 players (+ dedicated server)
if (DMFCBase->GetNetgameInfo()->max_players > 17)
DMFCBase->GetNetgameInfo()->max_players = 17;
}
PlayerColorIndexes[0] = DLLFindWeaponName("Omega");
PlayerColorIndexes[1] = DLLFindWeaponName("Laser Level 1 - Red");
PlayerColorIndexes[2] = DLLFindWeaponName("Laser Level 2 - Blue");
PlayerColorIndexes[3] = DLLFindWeaponName("Laser Level 3 - Purple");
PlayerColorIndexes[4] = DLLFindWeaponName("Laser Level 4 - Green");
PlayerColorIndexes[5] = DLLFindWeaponName("Laser Level 5 -Yellow");
PlayerColorIndexes[6] = DLLFindWeaponName("Laser Level 6 -White");
PlayerColorIndexes[7] = DLLFindWeaponName("Super Laser");
PlayerColorIndexes[8] = DLLFindWeaponName("Plasma");
PlayerColorIndexes[9] = DLLFindWeaponName("Fusion");
PlayerColorIndexes[10] = DLLFindWeaponName("Guided");
PlayerColorIndexes[11] = DLLFindWeaponName("Vauss");
PlayerColorIndexes[12] = DLLFindWeaponName("Raygun");
PlayerColorIndexes[13] = DLLFindWeaponName("Frag");
PlayerColorIndexes[14] = DLLFindWeaponName("Robot Plasma");
PlayerColorIndexes[15] = DLLFindWeaponName("RobotFrag");
PlayerColorIndexes[16] = DLLFindWeaponName("Robot Concussion");
for (int i = 0; i < 32; ++i)
{
weapon *weapons = &(DMFCBase->GetWeapons())[PlayerColorIndexes[i]];
backupSounds[i] = weapons->sounds[1];
backupVelocity[i] = weapons->phys_info.velocity.z;
backupFlags[i] = weapons->flags;
backupPlayerDamage[i] = weapons->player_damage;
backupGenericDamage[i] = weapons->generic_damage;
backupExplodeImageHandle[i] = weapons->explode_image_handle;
backupSmokeHandle[i] = weapons->smoke_handle;
backupImpactPlayerDamage[i] = weapons->impact_player_damage;
backupImpactGenericDamage[i] = weapons->impact_generic_damage;
backupImpactForce[i] = weapons->impact_force;
backupLifeTime[i] = weapons->life_time;
backupLightInfo[i] = weapons->lighting_info;
backupSpawnHandle[i] = weapons->spawn_handle;
backupScorchHandle[i] = weapons->scorch_handle;
weapons->sounds[1] = (-1);
weapons->phys_info.velocity.z = 2000.0f;
weapons->player_damage = 0;
weapons->generic_damage = 0;
weapons->explode_image_handle = (-1);
weapons->smoke_handle = DLLFindTextureName("rsa");
weapons->impact_player_damage = 0;
weapons->impact_generic_damage = 0;
weapons->impact_force = 0;
weapons->life_time = 1.0f;
weapons->flags = md->flags;
weapons->spawn_handle = md->spawn_handle;
weapons->scorch_handle = -1;
switch (i)
{
case 0:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.0;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 1:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.125f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 1.0f;
break;
case 2:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 1.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 3:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 1.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 4:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.125f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.25f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.375f;
break;
case 5:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 1.0f;
break;
case 6:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 7:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 8:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 9:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.125f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 10:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 11:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 12:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 13:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 1.0f;
break;
case 14:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 1.0f;
break;
case 15:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 16:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.25f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 17:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 1.0f;
break;
case 18:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 1.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 19:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.25f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 20:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 1.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 21:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 22:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.25f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.25f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 23:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.25f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.25f;
break;
case 24:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.75f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 25:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 1.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
case 26:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.25f;
break;
case 27:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.25f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.25f;
break;
case 28:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.25f;
break;
case 29:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.75f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.0f;
break;
case 30:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 1.0f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 1.0f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 1.0f;
break;
case 31:
weapons->lighting_info.red_light1 = weapons->lighting_info.red_light2 = 0.5f;
weapons->lighting_info.green_light1 = weapons->lighting_info.green_light2 = 0.5f;
weapons->lighting_info.blue_light1 = weapons->lighting_info.blue_light2 = 0.5f;
break;
}
}
index = DLLFindShipName("Pyro-GL");
if(index != (-1))
{
ship *ships = &(DMFCBase->GetShips())[index];
ships->static_wb[6].ammo_usage = 0;
ships->static_wb[0].ammo_usage = 1;
}
index = DLLFindShipName("Phoenix");
if(index != (-1))
{
ship *ships = &(DMFCBase->GetShips())[index];
ships->static_wb[6].ammo_usage = 0;
ships->static_wb[0].ammo_usage = 1;
}
index = DLLFindShipName("Magnum-AHT");
if(index != (-1))
{
ship *ships = &(DMFCBase->GetShips())[index];
ships->static_wb[6].ammo_usage = 0;
ships->static_wb[0].ammo_usage = 1;
}
index = DLLFindShipName("Black Pyro");
if(index != (-1))
{
ship *ships = &(DMFCBase->GetShips())[index];