-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetWork.cpp
More file actions
4014 lines (3354 loc) · 103 KB
/
Copy pathNetWork.cpp
File metadata and controls
4014 lines (3354 loc) · 103 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
/*****************************************************************************
*
* NetWork.cpp -- F18 multi-player code
*
* David McKibbin 2Sep97
*
*-----------------------------------------------------------------------------
* Copyright (c) 1997 by Origin Systems, Inc., All Rights Reserved.
*****************************************************************************/
#include <windows.h>
//#include <dplay.h>
#include "dplay.h" // delete this when DX5 to all
#include "gamesettings.h"
#include "MultiDefs.h"
#include "F18.h"
#include "WrapInterface.h"
#include "Sprite.h"
#include "Resources.h"
#include "MultiPlayer.h"
#include "WrapInterface.h"
#include <crtdbg.h>
#include "keystuff.h"
#include "keysmsg.h"
#include "MultiPlayer.h"
//#undef DPSEND_GUARANTEED // disable guaranteed messages
//#define DPSEND_GUARANTEED 0
//
// SkunkNet currently has a "C" linkage because I can find no way to get
//
// --- F18API __declspec(naked) UINT P5time() ---
//
// to compile in a CPP file. ERROR: not all control paths return a value.
// In a C file we get: "warning C4035: 'P5time' : no return value"
//
#define F18LIB
#include "SkunkNet.h"
///////////////////////
// //
// Local Defines //
// //
///////////////////////
#define PLAYERS MAX_PLAYERS
#define CHANNELS (MAX_PLAYERS + 2)
#define INT_MAX ((unsigned)-1 >> 1);
#define SlotOK(x) (((UINT)(x)) < PLAYERS)
void NetRefreshComList(void);
void NetGetAll (void);
void NetGetFtp (DPMSG_GENERIC *pGeneric);
//void RecreatePlayerList (void);
void NetStartSim (DPMSG_STARTSIM *pMsg);
void NetPreviewMission (DPMSG_PREVIEW_MISSION *pMsg);
void NetReadyToFly (DPMSG_JOINER_READY *pMsg);
void NetFtpFlags (DPMSG_FTP_FLAGS *pMsg);
void NetRequestFtpFlags (DPMSG_FTP_FLAGS *pMsg);
void NetFtpTotalBlocks (DPMSG_FTP_BLOCKS *pMsg);
void NetQueryMission (DPMSG_QUERY_MISSION *pMsg);
void NetQueryMissionResult (DPMSG_QUERY_MISSION_RESULT *pMsg);
void InitAvSensorData();
extern void ReleaseShadowEntry(void *pt);
extern DetectedPlaneListType CurFramePlanes;
extern BOOL PrimaryIsAOT(DetectedPlaneListType *Plist);
extern void StopFFForPauseOrEnd();
extern BOOL g_bInSim;
extern BOOL SnowOn, doLightning, doRain;
// The following parameter values may be overriden via the registry.
//
int netRate = 50; // network packet time allowance (ms)
int netFork = 2; // minimum packet branching factor
int netMask = -1; // dpSend flag mask
double netKnob = 0.5; // feedback loop control valve (50%)
DPID g_adpidPlayers[MAX_PLAYERS]; // array of 8 directplay id's for host adminstration
//HUMANPILOT * g_pHumanList;
//DWORD g_dwHumanListLastModified;
IDirectPlay3A * g_lpDirectPlay;
//////////////////////////
// //
// Global Variables //
// //
//////////////////////////
extern AvionicsType Av;
extern TargetInfoType *Primary;
// Connection counters
int cRecv; // Network messages received
int cPoll; // Total polls in SIM
int cSpin; // Total polls not in SIM
int newTime; // current physics tick, ie. T1
int MySlot = -1;// my player's slot index [0..N], -1 is uninitialized
int NetWeapIX; // weapon GUID (unique system-wide) - HIWORD(slot#) | LOWORD(seq#)
int PlayerCount; // save data from dpPlayers()
char ** PlayerName;
BOOL g_bIAmHost;
MULTI_FTP_LIST * g_pTempMultiPlayerList; // Used by wrappers to keep multiplayer list while in sim...restored to wrappers after sim exits
extern int iInGameSlots;
extern NetSlot Slotarray[MAX_HUMANS + 1];
NetSlot Slot[MAXAIOBJS]; // was PLAYERS
typedef struct _DPMSG_SLOTREQUEST
{
int type; // message ID
int time; // system time stamp (ms)
int slot; // player plane slot#
int newslot; // target plane slot#
DPID dpidHost; // Host dpid
} DPMSG_SLOTREQUEST;
DPMSG_SLOTREQUEST NetSlotRequest; // static packet for sending
void NetPutSlotRequest (DPID dpTo, int nNewSlot)
{
g_adpidPlayers[nNewSlot] = dpTo;
NetSlotRequest.type = NET_SLOTREQUEST;
NetSlotRequest.time = GetTickCount ();
NetSlotRequest.slot = MySlot;
NetSlotRequest.newslot = nNewSlot;
NetSlotRequest.dpidHost = dpWhoAmID ();
dpSendGuaranteed ( dpTo, DPSEND_GUARANTEED, &NetSlotRequest, sizeof(NetSlotRequest) );
}
//============================================================================
// GAME SESSION DATA MANAGEMENT
//============================================================================
//
// Game Session Description from DirectPlay.
//
DPSESSIONDESC2 GameInfo;
char GameName[32]; // DPSESSIONNAMELEN
// GameInfo.dwUser3/4 are used as an 8-byte array of kills
//
#define NetTally ((char *)&GameInfo.dwUser3)
void FreeMultiPlayerList (void)
{
MULTI_FTP_LIST * pList = g_pTempMultiPlayerList;
MULTI_FTP_LIST * pNext;
while (pList)
{
pNext = pList->pNext;
free (pList);
pList = pNext;
}
g_pTempMultiPlayerList = NULL;
}
BOOL SaveMultiPlayerList (MULTI_FTP_LIST *pWrappersList)
{
MULTI_FTP_LIST * pNewEntry;
BOOL bOk = TRUE;
FreeMultiPlayerList ();
while (pWrappersList)
{
pNewEntry = (MULTI_FTP_LIST *) malloc (sizeof (MULTI_FTP_LIST));
_ASSERT (pNewEntry);
if (pNewEntry)
{
memcpy (pNewEntry, pWrappersList, sizeof (MULTI_FTP_LIST));
pNewEntry->pNext = g_pTempMultiPlayerList;
g_pTempMultiPlayerList = pNewEntry;
}
else
bOk = FALSE;
pWrappersList = pWrappersList->pNext;
}
return (bOk);
}
BOOL RestoreMultiPlayerList (MULTI_FTP_LIST *pWrapperList)
{
MULTI_FTP_LIST * pTemp;
if (!g_pTempMultiPlayerList || !pWrapperList)
return (FALSE);
while (pWrapperList)
{
pTemp = g_pTempMultiPlayerList;
while (pTemp)
{
if (pWrapperList->dpid == pTemp->dpid)
{
// Copy over whatever other info we need to restore here...
// be careful not to restore any variables that are out of context, like nMissionExists, for instance
pWrapperList->nFtpFlags = pTemp->nFtpFlags;
pTemp = NULL;
}
else
pTemp = pTemp->pNext;
}
pWrapperList = pWrapperList->pNext;
}
return (TRUE);
}
/*----------------------------------------------------------------------------
*
* NetSetHostFlag ()
*
* Called by wrappers or multi-player message filter to set this machine as host
*
*/
void NetSetHostFlag (BOOL bIAmHost)
{
g_bIAmHost = bIAmHost;
if(g_bIAmHost)
{
// RecreatePlayerList ();
for(PlaneParams *planepnt = Planes; planepnt <= LastPlane; planepnt ++)
{
if((planepnt->Status & (AL_AI_DRIVEN|PL_ACTIVE)) == (AL_AI_DRIVEN|PL_ACTIVE))
{
if(!((Planes[planepnt->AI.iMultiPlayerAIController].Status & (AL_DEVICE_DRIVEN|AL_COMM_DRIVEN)) && (Planes[planepnt->AI.iMultiPlayerAIController].Status & (PL_ACTIVE))))
{
if(planepnt->AI.iAICombatFlags1 & AI_MULTI_REMOVEABLE)
{
planepnt->Status = 0;
}
else
{
planepnt->AI.iAICombatFlags1 |= AI_MULTI_ACTIVE;
planepnt->AI.iMultiPlayerAIController = PlayerPlane - Planes;
}
}
}
}
}
// clean out our array of directplay slots
memset (g_adpidPlayers, 0, sizeof (DPID) * MAX_PLAYERS);
if (MySlot != -1)
g_adpidPlayers[MySlot] = dpWhoAmID ();
}
/*----------------------------------------------------------------------------
*
* NetPutGameInfo()
*
* Update our GameInfo struct from new DirectPlay data.
*
*/
void NetPutGameInfo( DPSESSIONDESC2 *dpsd )
{
if (dpsd)
{
GameInfo = *dpsd;
strncpy( GameName, dpsd->lpszSessionNameA, sizeof(GameName)-1 );
GameInfo.lpszSessionNameA = GameName;
}
}
/*----------------------------------------------------------------------------
*
* NetGetGameInfo()
*
* Update our GameInfo struct from host.
*
*/
void NetGetGameInfo()
{
DPSESSIONDESC2 *dpsd;
int hr = dpGetSessionDesc( -1, (void**)&dpsd );
if SUCCEEDED(hr) NetPutGameInfo( dpsd );
}
/*----------------------------------------------------------------------------
*
* NetSetGameInfo()
*
* Update DP host's SessionDesc from our GameInfo struct.
*
*/
void NetSetGameInfo()
{
dpSetSessionDesc( (void*)&GameInfo );
}
//============================================================================
// HIT/KILL LOGGING & DISPLAY
//============================================================================
/*----------------------------------------------------------------------------
*
* NetRadio()
*
* Display a radio message (and echo debug string)
*
* Note: varargs must be strings
*
*/
void NetRadio( int msgid, ... )
{
char msg[256];
char *argv = (char *)(&msgid+1); // va_start( argv, msgid );
FormatMessage( FORMAT_MESSAGE_FROM_HMODULE, NULL, msgid,
g_iLanguageId, msg, sizeof(msg), &argv );
if (g_bInSim) AICAddAIRadioMsgs( msg, 69 );
strcat( msg, ".\n" );
OutputDebugString( msg );
}
/*----------------------------------------------------------------------------
*
* KillVerb() -- return random KILL verb
*
* killed, fried, incinerated, wasted, splashed, nailed, barbecued, splattered
*
*/
char *KillVerb()
{
static char verb[32];
FormatMessage( FORMAT_MESSAGE_FROM_HMODULE, NULL, NET_KILL_VERB+(GameLoop&7),
g_iLanguageId, verb, sizeof(verb), NULL );
return verb;
}
/*----------------------------------------------------------------------------
*
* NetSetKill()
*
* Record author of damage to target
*
* To keep compatibility with F15v102f, the "noMsg" argument was added.
* NET_DAMAGE messages from old versions will still set the kill, but
* will not generate radio messages. So kill tallys will still work
* across different versions. Patched versions will get kill messages
* in all cases and will get hit messages from other patched versions.
*
*/
void NetSetKill( int src, int tgt, int noMsg)
{
Slot[tgt].lastHit = src;
if(src == -1)
return;
if (noMsg) return; // F15v102f compatibility
if (src == tgt)
return;
if (NetGetSlotFromPlaneIndex(src) == MySlot)
{
if((Planes[tgt].Status & PL_ACTIVE) && (strlen(Slot[tgt].name) < 20))
{
if(strlen(Slot[tgt].name) == 0)
{
NetRadio( NET_HIT_YOU, pDBAircraftList[Planes[tgt].AI.iPlaneIndex].sName );
}
else
{
NetRadio( NET_HIT_YOU, Slot[tgt].name );
}
}
}
if (NetGetSlotFromPlaneIndex(tgt) == MySlot)
{
if((Planes[src].Status & PL_ACTIVE) && (strlen(Slot[src].name) < 20))
{
if(strlen(Slot[src].name) == 0)
{
NetRadio( NET_HIT_ME, pDBAircraftList[Planes[src].AI.iPlaneIndex].sName );
}
else
{
NetRadio( NET_HIT_ME, Slot[src].name );
}
}
}
}
/*----------------------------------------------------------------------------
*
* NetLogKill()
*
* Only the HOST can set the session descriptor,
* but for simplicity all players log the kill.
*
*/
void NetLogKill( int tgt ) // tgt: index of crash'd plane
{
int src = Slot[tgt].lastHit; // src: source of last hit
int srcslot, tgtslot;
srcslot = NetGetSlotFromPlaneIndex(src, 1);
tgtslot = NetGetSlotFromPlaneIndex(tgt, 1);
Slot[tgt].lastHit = -1; // clear damage doer
if((src == -1) || (!SlotOK(srcslot))) // crash w/o damage
{
if((!(Planes[tgt].FlightStatus & PL_OUT_OF_CONTROL)) && ((Planes[tgt].Status & PL_ACTIVE) && (strlen(Slot[tgt].name) < 20)))
NetRadio( NET_CRASHED, Slot[tgt].name );
return;
}
if((srcslot != -1) || (tgtslot != -1))
{
if (srcslot == MySlot)
{
if((Planes[tgt].Status & PL_ACTIVE) && (strlen(Slot[tgt].name) < 20))
{
if(strlen(Slot[tgt].name) == 0)
{
NetRadio( NET_KILL_YOU, KillVerb(), pDBAircraftList[Planes[tgt].AI.iPlaneIndex].sName );
}
else
{
NetRadio( NET_KILL_YOU, KillVerb(), Slot[tgt].name );
}
}
}
else
{
if(tgtslot == MySlot)
{
if((Planes[src].Status & PL_ACTIVE) && (strlen(Slot[src].name) < 20))
{
if(strlen(Slot[src].name) == 0)
{
NetRadio( NET_KILL_ME, KillVerb(), pDBAircraftList[Planes[src].AI.iPlaneIndex].sName );
}
else
{
NetRadio( NET_KILL_ME, KillVerb(), Slot[src].name );
}
}
}
else
{
if((Planes[tgt].Status & PL_ACTIVE) && (strlen(Slot[tgt].name) < 20) && (Planes[src].Status & PL_ACTIVE) && (strlen(Slot[src].name) < 20))
{
char srcname[64], tgtname[64];
if(strlen(Slot[src].name) == 0)
strcpy(srcname, pDBAircraftList[Planes[src].AI.iPlaneIndex].sName);
else
strcpy(srcname, Slot[src].name);
if(strlen(Slot[tgt].name) == 0)
strcpy(tgtname, pDBAircraftList[Planes[tgt].AI.iPlaneIndex].sName);
else
strcpy(tgtname, Slot[tgt].name);
NetRadio( NET_KILL_BY, KillVerb(), srcname, tgtname );
}
}
}
}
if(srcslot != -1)
{
NetGetGameInfo(); // make sure we are current (host could have migrated)
NetTally[NetGetSlotFromPlaneIndex(src)]++; // bump killer's tally
NetSetGameInfo();
}
}
/*----------------------------------------------------------------------------
*
* NetLetKill()
*
* We want to permanently enable the kill tally for a slot for the
* entire duration of the session. Even if players drop out and
* others rejoin, we need a continuous tally. So at host creation
* time the tallys are set to -1 to indicate disabled. As a player
* joins/rejoins the tally is enabled as necessary.
*
*/
void NetLetKill( int src )
{
NetGetGameInfo(); // make sure we are current (host could have migrated)
NetSetGameInfo();
}
//============================================================================
// SLOT MANAGEMENT
//============================================================================
/*----------------------------------------------------------------------------
*
* NetQuitSlot()
*
* Mark a slot EMPTY and init for future assignment.
*
* Called at DESTROYPLAYER.
*
*/
void NetQuitSlot( int ix )
{
int planenum;
if (!SlotOK(ix)) return;
planenum = iSlotToPlane[ix];
if(planenum == -1) return;
NetSlot *S = &Slot[planenum];
char name[20]; // preserve name across "quit" for Debrief kill stats
strcpy( name, S->name );
int team = S->x.chTeam;
int life = S->nLives;
ZeroMemory( S, sizeof(NetSlot) );
S->nLives = life;
S->x.chTeam = team;
strcpy( S->name, name );
S->x.iSlot = -1; // set slot inactive for wrappers
S->lastHit = -1; // clear damage doer
S->minDelta = INT_MAX;
S->netDelta = INT_MAX;
// Make plane inactive & comm (my available mark)
//
// Planes[planenum].Status = PL_COMM_DRIVEN;
NewGenerator(PLANE_EXPLODES,Planes[planenum].WorldPosition,0.0,2.0f,50);
Planes[planenum].Status = 0;
Planes[planenum].AI.iAIFlags2 = 0;
OrphanAllPlaneSmoke(&Planes[planenum]);
NetRefreshComList();
}
/*----------------------------------------------------------------------------
*
* NetInitSlot()
*
* ZERO slotand init for future assignment.
*
* Called at session startup.
*
*/
void NetInitSlot( int ix )
{
int planex;
if (!SlotOK(ix)) return;
planex = NetGetPlaneIndexFromSlot(ix);
if(planex == -1) return;
iSlotToPlane[ix] = -1;
ZeroMemory( &Slot[planex], sizeof(Slot[planex]) );
NetQuitSlot( ix );
}
/*----------------------------------------------------------------------------
*
* NetSetSlotData()
*
* Broadcast this slot's data to the world.
*
*/
void NetSetSlotData( int ix, int nGuarantee )
{
// if (SlotOK(ix) && (iSlotToPlane[ix] != -1))
if (SlotOK(ix))
// dpSetPlayerData( &Slot[ix].x, sizeof(dpSlot), nGuarantee );
dpSetPlayerData( &Slot[NetGetPlaneIndexFromSlot(ix)].x, sizeof(dpSlot), nGuarantee );
}
/*----------------------------------------------------------------------------
*
* NetGetSlotData()
*
* Return a pointer to this slot's data structure.
*
* Even return free slots so wrappers can just do this once.
*
*/
dpSlot *NetGetSlotData( int ix )
{
if(NetGetPlaneIndexFromSlot(ix) == -1) return(NULL);
return SlotOK(ix) ? &Slot[NetGetPlaneIndexFromSlot(ix)].x : NULL;
}
/*----------------------------------------------------------------------------
*
* NetGetSlotDataEx ()
*
* Return a pointer to this slot's data structure.
* Even return free slots so wrappers can just do this once.
*
*/
NetSlot *NetGetSlotDataEx ( int ix )
{
if(NetGetPlaneIndexFromSlot(ix) == -1) return(NULL);
return SlotOK(ix) ? &Slot[NetGetPlaneIndexFromSlot(ix)] : NULL;
}
/*----------------------------------------------------------------------------
*
* NetSetSlot()
*
* Assign this slot:
*
* * Copy the DirectPlay player data into our struct.
* * Save the player's DPID.
* * Save the player's name.
* * Reset the 1st packet trigger
* * Reset the damage doer
*
* Called at session startup for each player returned by dpPlayers()
* and also at SETPLAYERDATA for each player data update
*
*/
void NetSetSlot( dpSlot *X, int dpid )
{
int ix = X->iSlot;
int planenum;
if (!SlotOK(ix)) return;
planenum = NetGetPlaneIndexFromSlot(ix);
if(planenum == -1) return;
NetSlot *S = &Slot[planenum];
S->x = *X; // copy the broadcast struct into the slot
S->dpid = dpid; // set the slot active
S->nPacks = 0; // reset the 1st packet trigger
S->lastHit = -1; // clear damage doer
DPNAME *dpName = NULL;
dpGetPlayerName( dpid, (void**)&dpName );
if (dpName)
strncpy( S->name, dpName->lpszShortNameA, sizeof(S->name)-1 );
NetRefreshComList();
}
/*----------------------------------------------------------------------------
*
* NetInitSlots()
*
* Empty all slots and update player and game data from the net.
*
*/
void NetInitSlots()
{
// Empty all the slots.
//
for (int i=0; i<PLAYERS; i++) NetInitSlot( i );
// Get current player list.
//
dpPlayers( -1, &PlayerCount, &PlayerName );
// Update plane assignments.
//
for (i=0; i<PlayerCount; i++)
{
dpSlot data;
int size = sizeof(dpSlot);
int dpid = dpIndex2ID(i);
int hr = dpGetPlayerData( dpid, &data, (DWORD*)&size );
if (hr == 0 && size == sizeof(dpSlot))
NetSetSlot( &data, dpid );
}
NetGetGameInfo();
}
/*----------------------------------------------------------------------------
*
* NetGetSlots() *** INITIALIZE NETWORK ***
*
* Query network for players and their plane assignments
* and update all slot assignments to reflect this state.
* Assign a slot for ME. First choice is my dpPlayer index.
* If that is taken, take the first available slot.
*
* SAFETY: If there are now more players than when we started,
* start over. We are allowing the host to passively
* arbitrate slot assignments. dpPlayers() seems to order the
* player list is reverse order of joining the session, ie.
* the last player to join is listed first and the first player
* to join (ie. the host) is listed last. So we use that order
* as a globally broadcast slot order.
*
*/
int NetGetSlots()
{
int planenum;
do // Assign slots until player count is stable.
{
NetInitSlots();
}
while (PlayerCount != (int)GameInfo.dwCurrentPlayers);
// If this is the first time through as host, set our slot now
if (g_bIAmHost && MySlot == -1)
{
MySlot = 0;
g_adpidPlayers[MySlot] = dpWhoAmID ();
}
// commented out 11/12/98
int dpIndex = dpWhoAmI();
if ((UINT)dpIndex >= (UINT)PlayerCount)
return -1; // error
// My first slot choice is my DP join order#
//
//MySlot = PlayerCount - dpIndex - 1;
//if (Slot[MySlot].dpid) // MySlot is already assigned
// for (int i=0; i<PLAYERS; i++)
// if (Slot[i].dpid == 0) { MySlot = i; break; }
// Broadcast my slot assignment.
//
planenum = NetGetPlaneIndexFromSlot(MySlot);
Slot[planenum].x.iSlot = MySlot;
NetSetSlotData( MySlot, TRUE );
// Init my player's name for wrappers immediate use.
// Can't wait for echo of DP_SYS_MSG.
strncpy( Slot[planenum].name, PlayerName[dpIndex], sizeof(Slot[planenum].name)-1 );
NetWeapIX = (MySlot << 16) + 256; // Init my GUID
Planes[planenum].Status = PL_DEVICE_DRIVEN;
return MySlot; // return my slot# [0..7]
}
/*----------------------------------------------------------------------------
*
* NetUnLockWeapons()
*
* Unlock any weapons going after regenning plane.
*
*/
void NetUnLockWeapons( int planenum )
{
PlaneParams *planepnt = &Planes[planenum];
for (WeaponParams *W=Weapons; W<=LastWeapon; W++)
{
if(W->pTarget == planepnt)
{
W->pTarget = NULL;
W->iTargetType = NONE;
W->Flags &= ~(BOOST_PHASE|ACTIVE_SEARCH|ACTIVE_SEEKER);
W->Flags |= LOSING_LOCK|LOST_LOCK;
}
}
}
/*----------------------------------------------------------------------------
*
* NetUnDamage()
*
* Reset damage variables outside of PlaneParams.
*
*/
void NetUnDamage( int planenum )
{
int ix;
int i;
ix = NetGetSlotFromPlaneIndex(planenum);
if(ix != -1)
{
for (i=0; i<40; i++)
{
cPlayerArmor [ix][i] = (char)125;
cPlayerDamage[ix][i] = 0;
}
}
for (i=0; i<MAX_DELAYED_DAMAGE; i++)
{
if (gDamageEvents[i].iPlaneNum != planenum) continue;
gDamageEvents[i].iPlaneNum = -1;
gDamageEvents[i].lDamageTimer = -1;
gDamageEvents[i].lDamagedSystem = 0;
}
NetUnLockWeapons(planenum);
// added 11/13/98
OrphanAllPlaneSmoke(&Planes[planenum]);
}
/*----------------------------------------------------------------------------
*
* NetKillChutes()
*
* Delete all weapons assigned to my plane.
*/
void NetKillChutes( int planenum )
{
for (WeaponParams *W = Weapons; W <= LastWeapon; W++)
if (W->Flags & WEAPON_INUSE
&& W->P == &Planes[planenum]
&& W->Kind == EJECTION_SEAT) DeleteBomb(W);
if(PlayerPlane == &Planes[planenum])
{
PlayerPlane->AI.iAIFlags1 &= ~AI_HAS_EJECTED;
pPlayerChute = NULL;
}
}
/*----------------------------------------------------------------------------
*
* NetSetPlane()
*
* Activate the plane and init its parameters.
*
* Called from NetGrabPlanes(), NetRegenerate() and NetGetPlane() at 1st data
*
*/
void NetSetPlane( int ix )
{
int planenum;
int cnt;
PlaneParams *planepnt;
int msgOK = 1;
BYTE bworkvar;
FPoint fpworkvar;
// Always jam the team# since host could migrate
//
planenum = NetGetPlaneIndexFromSlot(ix);
Planes[planenum].AI.iSide = Slot[planenum].x.chTeam;
if (Slot[planenum].nLives++ == 0) // first life
{
if(ix != MySlot)
{
pPlaneLoadUpdate[ix] = PlayerPlane;
iLoadUpdateStation[ix] = 0;
iLoadUpdateStatus[ix] = 1;
lLoadUpdateTimer[ix] = 30000;
if(!iLoadUpdateStatus[MySlot])
{
iLoadUpdateStatus[MySlot] = 1;
}
if(g_bIAmHost)
{
if(!(iNetHasWeather & (1<<ix)))
{
iMAISendTo = ix;
bworkvar = 0;
if(SnowOn)
{
bworkvar |= 0x1;
}
if(doLightning)
{
bworkvar |= 0x2;
}
if(doRain)
{
bworkvar |= 0x4;
}
fpworkvar.X = WorldParams.Weather;
fpworkvar.Y = WorldParams.CloudAlt;
fpworkvar.Z = WorldParams.Visibility;
NetPutGenericMessage2FPoint(NULL, GM2FP_WEATHER_INFO, fpworkvar, bworkvar);
iMAISendTo = -1;
}
if(iAllowRegen)
{
iMAISendTo = ix;
NetPutGenericMessage1(PlayerPlane, GM_ALLOW_REGEN);
iMAISendTo = -1;
}
}
}
else if(!g_bIAmHost)
{
NetPutGenericMessage1(PlayerPlane, GM_REQUEST_WEATHER);
}
iSlotToPlane[ix] = planenum;
NetLetKill( ix ); // enable kill tally
Planes[planenum].Status |= ( PL_ACTIVE | PL_NEED_ATTITUDE );
// Planes[planenum+100] = Planes[planenum]; // save copy of plane in hanger
if(ix < MAX_HUMANS)
{
NetRegenPlanes[ix] = Planes[planenum];
}
#if 0 // Since Planes could be more than 100 do something else. Also AI_MULTI_ACTIVE SHOULD ALREADY BE SET
PlaneParams *leadplane;
if(g_bIAmHost)
{
for(planepnt = Planes; planepnt <= LastPlane; planepnt ++)
{
if(planepnt->Status & PL_ACTIVE)
{
if((planepnt->Status & AL_AI_DRIVEN) && (!(planepnt->AI.iAICombatFlags1 & AI_HUMAN_CONTROLLED)))
{
leadplane = AIGetLeader(planepnt);
if((leadplane->Status & AL_AI_DRIVEN) && (!(leadplane->AI.iAICombatFlags1 & AI_HUMAN_CONTROLLED)))
{
planepnt->AI.iAICombatFlags1 |= AI_MULTI_ACTIVE;
}
}
}
}
}
#endif
if(planenum == (PlayerPlane - Planes))
{
if(GetRegValueL("mpdebug") == 1)
{
hNetDebugFile=_open("netmlog.txt",_O_CREAT | _O_TRUNC | _O_TEXT | _O_WRONLY, _S_IWRITE | _S_IREAD);
hNetPacketFile=_open("netpslog.txt",_O_CREAT | _O_TRUNC | _O_TEXT | _O_WRONLY, _S_IWRITE | _S_IREAD);
}
else
{
hNetDebugFile=-1;
hNetPacketFile=-1;
}
lTotalSecs = 0;
for(cnt = 0; cnt < 4; cnt ++)
{
lLastBytes[cnt] = 0;
}
for(cnt = 0; cnt < MAX_HUMANS; cnt ++)
{
pLastBPPos[cnt] = NULL;
}
}
//******************* if we ever do Arena then we will need to do something like this, but not now.
// NetSetAIPlanes(planenum);
if((ix == 0) && (&Planes[planenum] == PlayerPlane)) // Have first plane start controlling Ground Defenses.
{
lAINetFlags1 |= NGAI_ACTIVE;
}
if(ix != MySlot)