forked from karadoc/Civ4-K-Mod
/
CvInitCore.cpp
2115 lines (1904 loc) · 57.5 KB
/
CvInitCore.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
992
993
994
995
996
997
998
999
1000
#include "CvGameCoreDLL.h"
#include "CvInitCore.h"
#include "CvPlayer.h"
#include "CvInfo_GameOption.h"
CvInitCore::CvInitCore()
{
m_aszLeaderName = new CvWString[MAX_PLAYERS];
m_aszCivDescription = new CvWString[MAX_PLAYERS];
m_aszCivShortDesc = new CvWString[MAX_PLAYERS];
m_aszCivAdjective = new CvWString[MAX_PLAYERS];
m_aszCivPassword = new CvWString[MAX_PLAYERS];
m_aszEmail = new CvString[MAX_PLAYERS];
m_aszSmtpHost = new CvString[MAX_PLAYERS];
m_aszFlagDecal = new CvWString[MAX_PLAYERS];
m_aszPythonCheck = new CvString[MAX_PLAYERS];
m_aszXMLCheck = new CvString[MAX_PLAYERS];
m_aeSlotStatus = new SlotStatus[MAX_PLAYERS];
m_aeSlotClaim = new SlotClaim[MAX_PLAYERS];
m_aeCustomMapOptions = NULL;
m_abVictories = NULL;
reset(NO_GAMEMODE);
}
CvInitCore::~CvInitCore()
{
uninit();
SAFE_DELETE_ARRAY(m_aszLeaderName);
SAFE_DELETE_ARRAY(m_aszCivDescription);
SAFE_DELETE_ARRAY(m_aszCivShortDesc);
SAFE_DELETE_ARRAY(m_aszCivAdjective);
SAFE_DELETE_ARRAY(m_aszCivPassword);
SAFE_DELETE_ARRAY(m_aszEmail);
SAFE_DELETE_ARRAY(m_aszSmtpHost);
SAFE_DELETE_ARRAY(m_aszFlagDecal);
SAFE_DELETE_ARRAY(m_aszPythonCheck);
SAFE_DELETE_ARRAY(m_aszXMLCheck);
SAFE_DELETE_ARRAY(m_aeSlotStatus);
SAFE_DELETE_ARRAY(m_aeSlotClaim);
}
void CvInitCore::init(GameMode eMode)
{
//--------------------------------
// Init saved data
reset(eMode);
}
void CvInitCore::uninit()
{
// <advc.003w> So that memory doesn't remain allocated after exit to main menu
if (GC.IsGraphicsInitialized())
{
for (int i = 0; i < MAX_CIV_PLAYERS; i++)
setCiv((PlayerTypes)i, NO_CIVILIZATION);
} // </advc.003w>
clearCustomMapOptions();
SAFE_DELETE_ARRAY(m_abVictories);
m_iNumVictories = 0;
}
// Initializes data members that are serialized.
void CvInitCore::reset(GameMode eMode)
{
uninit();
resetGame();
resetPlayers();
setMode(eMode);
if (getMode() != NO_GAMEMODE)
setDefaults();
}
void CvInitCore::setDefaults()
{
FOR_EACH_ENUM(GameOption)
{
m_abOptions.set(eLoopGameOption, GC.getInfo(eLoopGameOption).getDefault());
}
FOR_EACH_ENUM(MPOption)
{
m_abMPOptions.set(eLoopMPOption, GC.getInfo(eLoopMPOption).getDefault());
}
}
bool CvInitCore::getHuman(PlayerTypes eID) const
{
if (getSlotStatus(eID) == SS_TAKEN)
return true;
if (getSlotStatus(eID) == SS_OPEN)
return (gDLL->isGameActive() || getHotseat() || getPitboss() || getPbem());
return false;
}
int CvInitCore::getNumHumans() const
{
int iNumHumans = 0;
for (int i = 0; i < MAX_CIV_PLAYERS; i++)
{
if (getHuman((PlayerTypes)i))
iNumHumans++;
}
return iNumHumans;
}
int CvInitCore::getNumDefinedPlayers() const
{
int iCount = 0;
for (int i = 0; i < MAX_CIV_PLAYERS; i++)
{
PlayerTypes eLoopPlayer = (PlayerTypes)i;
if (getCiv(eLoopPlayer) != NO_CIVILIZATION &&
getLeader(eLoopPlayer) != NO_LEADER)
{
iCount++;
}
}
return iCount;
}
bool CvInitCore::getMultiplayer() const
{
switch (getType())
{
case GAME_MP_NEW:
case GAME_MP_LOAD:
case GAME_MP_SCENARIO:
return true;
default:
return false;
}
}
bool CvInitCore::getNewGame() const
{
switch (getType())
{
case GAME_SP_NEW:
case GAME_SP_SCENARIO:
case GAME_MP_NEW:
case GAME_MP_SCENARIO:
case GAME_HOTSEAT_NEW:
case GAME_HOTSEAT_SCENARIO:
case GAME_PBEM_NEW:
case GAME_PBEM_SCENARIO:
return true;
default:
return false;
}
}
bool CvInitCore::getSavedGame() const
{
switch (getType())
{
case GAME_SP_LOAD:
case GAME_MP_LOAD:
case GAME_HOTSEAT_LOAD:
case GAME_PBEM_LOAD:
return true;
default:
return false;
}
}
bool CvInitCore::getPitboss() const
{
return (getMode() == GAMEMODE_PITBOSS);
}
bool CvInitCore::getHotseat() const
{
return (getType() == GAME_HOTSEAT_NEW ||
getType() == GAME_HOTSEAT_SCENARIO ||
getType() == GAME_HOTSEAT_LOAD);
}
bool CvInitCore::getPbem() const
{
return (getType() == GAME_PBEM_NEW ||
getType() == GAME_PBEM_SCENARIO ||
getType() == GAME_PBEM_LOAD);
}
bool CvInitCore::getSlotVacant(PlayerTypes eID) const // advc: refactored
{
FAssertBounds(0, MAX_CIV_PLAYERS, eID);
SlotStatus eStatus = getSlotStatus(eID);
return ((eStatus == SS_OPEN ||
(eStatus == SS_COMPUTER && getMPOption(MPOPTION_TAKEOVER_AI))) &&
getSlotClaim(eID) != SLOTCLAIM_ASSIGNED);
}
// the next ID available
PlayerTypes CvInitCore::getAvailableSlot()
{
// First check for open slots only
for (int i = 0; i < MAX_CIV_PLAYERS; i++)
{
PlayerTypes eID = (PlayerTypes)i;
if (getSlotClaim(eID) == SLOTCLAIM_UNASSIGNED && getSlotStatus(eID) == SS_OPEN)
{
setSlotClaim(eID, SLOTCLAIM_ASSIGNED);
return eID;
}
}
// That didn't work, check to see if we can assign computer slots
if (getMPOption(MPOPTION_TAKEOVER_AI))
{
for (int i = 0; i < MAX_CIV_PLAYERS; i++)
{
PlayerTypes eID = (PlayerTypes)i;
if (getSlotClaim(eID) == SLOTCLAIM_UNASSIGNED &&
getSlotStatus(eID) == SS_COMPUTER)
{
setSlotClaim(eID, SLOTCLAIM_ASSIGNED);
return eID;
}
}
}
return NO_PLAYER; // None available at all...
}
void CvInitCore::reassignPlayer(PlayerTypes eOldID, PlayerTypes eNewID)
{
FAssertBounds(0, MAX_CIV_PLAYERS, eOldID);
FAssertBounds(0, MAX_CIV_PLAYERS, eNewID);
// *** SAVE TARGET SLOT DETAILS TEMPORARILY
// Temp civ details
CvWString szLeaderName = m_aszLeaderName[eNewID];
CvWString szCivDescription = m_aszCivDescription[eNewID];
CvWString szCivShortDesc = m_aszCivShortDesc[eNewID];
CvWString szCivAdjective = m_aszCivAdjective[eNewID];
CvWString szCivPassword = m_aszCivPassword[eNewID];
CvString szEmail = m_aszEmail[eNewID];
CvString szSmtpHost = m_aszSmtpHost[eNewID];
bool bWhiteFlag = m_abWhiteFlag.get(eNewID);
CvWString szFlagDecal = m_aszFlagDecal[eNewID];
CivilizationTypes eCiv = m_aeCiv.get(eNewID);
LeaderHeadTypes eLeader = m_aeLeader.get(eNewID);
// <advc.190c>
bool bRandomCiv = m_abCivChosenRandomly.get(eNewID);
bool bRandomLeader = m_abCivChosenRandomly.get(eNewID);
// </advc.190c>
TeamTypes eTeam = m_aeTeam.get(eNewID);
HandicapTypes eHandicap = m_aeHandicap.get(eNewID);
PlayerColorTypes eColor = m_aeColor.get(eNewID);
ArtStyleTypes eArtStyle = m_aeArtStyle.get(eNewID);
// Temp slot data
SlotStatus eSlotStatus = m_aeSlotStatus[eNewID];
SlotClaim eSlotClaim = m_aeSlotClaim[eNewID];
// Temp civ flags
bool bPlayableCiv = m_abPlayableCiv.get(eNewID);
bool bMinorNationCiv = m_abMinorNationCiv.get(eNewID);
// Temp unsaved player data
PlayerTypes eNetID = m_aiNetID.get(eNewID);
bool bReady = m_abReady.get(eNewID);
CvString szPythonCheck = m_aszPythonCheck[eNewID];
CvString szXMLCheck = m_aszXMLCheck[eNewID];
// *** SAVE OLD SLOT DETAILS IN NEW SLOT
// New civ details
m_aszLeaderName[eNewID] = m_aszLeaderName[eOldID];
m_aszCivDescription[eNewID] = m_aszCivDescription[eOldID];
m_aszCivShortDesc[eNewID] = m_aszCivShortDesc[eOldID];
m_aszCivAdjective[eNewID] = m_aszCivAdjective[eOldID];
m_aszCivPassword[eNewID] = m_aszCivPassword[eOldID];
m_aszEmail[eNewID] = m_aszEmail[eOldID];
m_aszSmtpHost[eNewID] = m_aszSmtpHost[eOldID];
m_abWhiteFlag.set(eNewID, m_abWhiteFlag.get(eOldID));
m_aszFlagDecal[eNewID] = m_aszFlagDecal[eOldID];
//m_aeCiv[eNewID] = m_aeCiv[eOldID];
setCiv(eNewID, m_aeCiv.get(eOldID)); // advc.003w
m_aeLeader.set(eNewID, m_aeLeader.get(eOldID));
// <advc.190c>
m_abCivChosenRandomly.set(eNewID, m_abCivChosenRandomly.get(eOldID));
m_abLeaderChosenRandomly.set(eNewID, m_abLeaderChosenRandomly.get(eOldID));
// </advc.190c>
m_aeTeam.set(eNewID, m_aeTeam.get(eOldID));
m_aeHandicap.set(eNewID, m_aeHandicap.get(eOldID));
m_aeColor.set(eNewID, m_aeColor.get(eOldID));
m_aeArtStyle.set(eNewID, m_aeArtStyle.get(eOldID));
// New slot data
m_aeSlotStatus[eNewID] = m_aeSlotStatus[eOldID];
m_aeSlotClaim[eNewID] = m_aeSlotClaim[eOldID];
// New civ flags
m_abPlayableCiv.set(eNewID, m_abPlayableCiv.get(eOldID));
m_abMinorNationCiv.set(eNewID, m_abMinorNationCiv.get(eOldID));
// New unsaved player data
m_aiNetID.set(eNewID, m_aiNetID.get(eOldID));
m_abReady.set(eNewID, m_abReady.get(eOldID));
m_aszPythonCheck[eNewID] = m_aszPythonCheck[eOldID];
m_aszXMLCheck[eNewID] = m_aszXMLCheck[eOldID];
// *** SAVE TEMP DETAILS IN OLD SLOT
// New civ details
m_aszLeaderName[eOldID] = szLeaderName;
m_aszCivDescription[eOldID] = szCivDescription;
m_aszCivShortDesc[eOldID] = szCivShortDesc;
m_aszCivAdjective[eOldID] = szCivAdjective;
m_aszCivPassword[eOldID] = szCivPassword;
m_aszEmail[eOldID] = szEmail;
m_aszSmtpHost[eOldID] = szSmtpHost;
m_abWhiteFlag.set(eOldID, bWhiteFlag);
m_aszFlagDecal[eOldID] = szFlagDecal;
//m_aeCiv[eOldID] = eCiv;
setCiv(eOldID, eCiv); // advc.003w
m_aeLeader.set(eOldID, eLeader);
// <advc.190c>
m_abCivChosenRandomly.set(eOldID, bRandomCiv);
m_abLeaderChosenRandomly.set(eOldID, bRandomLeader);
// </advc.190c>
m_aeTeam.set(eOldID, eTeam);
m_aeHandicap.set(eOldID, eHandicap);
m_aeColor.set(eOldID, eColor);
m_aeArtStyle.set(eOldID, eArtStyle);
// New slot data
m_aeSlotStatus[eOldID] = eSlotStatus;
m_aeSlotClaim[eOldID] = eSlotClaim;
// New civ flags
m_abPlayableCiv.set(eOldID, bPlayableCiv);
m_abMinorNationCiv.set(eOldID, bMinorNationCiv);
// New unsaved player data
m_aiNetID.set(eOldID, eNetID);
m_abReady.set(eOldID, bReady);
m_aszPythonCheck[eOldID] = szPythonCheck;
m_aszXMLCheck[eOldID] = szXMLCheck;
// We may have a new active player id...
if (getActivePlayer() == eOldID)
setActivePlayer(eNewID);
else if (getActivePlayer() == eNewID)
setActivePlayer(eOldID);
if (CvPlayer::areStaticsInitialized())
{
GET_PLAYER(eOldID).updateTeamType();
GET_PLAYER(eNewID).updateTeamType();
GET_PLAYER(eOldID).updateHuman();
GET_PLAYER(eNewID).updateHuman();
}
}
/* advc (caveat from C2C): When launching a network game, the EXE calls this only
on the host. Must not add code here that needs to be synchronized.
(Could add it e.g. in CvGame::init instead.) */
void CvInitCore::closeInactiveSlots()
{
// Open inactive slots mean different things to different game modes and types...
// Let's figure out what they mean for us
for (int i = 0; i < MAX_CIV_PLAYERS; i++)
{
PlayerTypes eID = (PlayerTypes)i;
if (getSlotStatus(eID) == SS_OPEN)
{
if (getPitboss() || getHotseat() || getPbem())
{
// Pitboss & hotseat - all "open" slots are non-present human players
setSlotStatus(eID, SS_TAKEN);
}
else if (getType() == GAME_MP_SCENARIO)
{
// Multiplayer scenario - all "open" slots should be filled with an AI player
setSlotStatus(eID, SS_COMPUTER);
}
else
{
// If it's a normal game, all "open" slots should be closed.
setSlotStatus(eID, SS_CLOSED);
}
setSlotClaim(eID, SLOTCLAIM_UNASSIGNED);
gDLL->sendPlayerInfo(eID);
}
}
}
void CvInitCore::reopenInactiveSlots()
{
// "Inactive" open slots will only be in Pitboss and Hotseat
if (getPitboss() || getHotseat() || getPbem())
{
for (int i = 0; i < MAX_CIV_PLAYERS; ++i)
{
PlayerTypes eID = (PlayerTypes)i;
// Reopen all slots that don't have active connections
if (getSlotStatus(eID) == SS_TAKEN)
{
if ( getSlotClaim(eID) != SLOTCLAIM_ASSIGNED )
{
setSlotStatus(eID, SS_OPEN);
}
}
}
}
}
void CvInitCore::resetGame(/* advc.enum: */ bool bBeforeRead)
{
// Descriptive strings about game and map
m_eType = GAME_NONE;
m_szGameName.clear();
m_szGamePassword.clear();
m_szAdminPassword.clear();
m_szMapScriptName.clear();
m_bPangaea = false; // advc
m_bWBMapNoPlayers = false;
// Standard game parameters
m_eWorldSize = NO_WORLDSIZE; // STANDARD_ option?
if (!bBeforeRead) // advc.enum (doesn't really matter ...)
/* <advc.003c> This function is called multiple times before XML is loaded.
GC.getDefineINT returns 0 then, which is fine, but now also triggers
a failed assertion. Therefore check if GC is done with the loading
(and caching) of XML values.
The in-line comments "NO_ option?" below are from the Vanilla developers.
If I'd just set everything to NO_..., I'd have to set proper values at
some later point though. */
{
bool cd = GC.isCachingDone();
m_eClimate = cd ? (ClimateTypes)GC.getDefineINT("STANDARD_CLIMATE") : NO_CLIMATE; // NO_ option?
m_eSeaLevel = cd ? (SeaLevelTypes)GC.getDefineINT("STANDARD_SEALEVEL") : NO_SEALEVEL; // NO_ option?
m_eEra = cd ? (EraTypes)GC.getDefineINT("STANDARD_ERA") : NO_ERA; // NO_ option?
m_eGameSpeed = cd ? (GameSpeedTypes)GC.getDefineINT("STANDARD_GAMESPEED") : NO_GAMESPEED; // NO_ option?
m_eTurnTimer = cd ? (TurnTimerTypes)GC.getDefineINT("STANDARD_TURNTIMER") : NO_TURNTIMER; // NO_ option?
m_eCalendar = cd ? (CalendarTypes)GC.getDefineINT("STANDARD_CALENDAR") : NO_CALENDAR; // NO_ option?
} // </advc.003c>
// Map-specific custom parameters
clearCustomMapOptions();
/* advc: Unused as far as I can tell, but still better to ensure that it
gets initialized. */
m_iNumHiddenCustomMapOptions = 0;
// Data-defined victory conditions
//refreshVictories();
/* <advc> Unrolling that function should make it easier to use an EnumMap instead
-- if I ever take another stab at that, which probably I should not. */
SAFE_DELETE_ARRAY(m_abVictories);
if (!bBeforeRead) // advc.enum
{
m_iNumVictories = GC.getNumVictoryInfos();
if (m_iNumVictories > 0)
{
m_abVictories = new bool[m_iNumVictories];
for (int i = 0; i < m_iNumVictories; i++)
m_abVictories[i] = true;
} // </advc>
}
// Standard game options
m_abOptions.reset();
m_abMPOptions.reset();
// <advc.enum>
if (bBeforeRead)
return; // </advc.enum>
m_abForceControls.reset();
m_iMaxCityElimination = 0;
m_iNumAdvancedStartPoints = 0;
// Misc
m_bStatReporting = false;
m_bCivLeaderSetupKnown = false; // advc.190c
// Game turn mgmt
m_iGameTurn = 0;
m_iMaxTurns = 0;
m_iPitbossTurnTime = 0;
m_iTargetScore = 0;
// Unsaved game data
m_uiSyncRandSeed = 0;
m_uiMapRandSeed = 0;
m_eActivePlayer = NO_PLAYER;
m_eActiveTeam = NO_TEAM; // advc.opt
// Temp vars
m_szTemp.clear();
}
void CvInitCore::resetGame(CvInitCore* pSource, bool bClear, bool bSaveGameType)
{
FAssert(pSource != NULL);
FAssertMsg(!bClear || !bSaveGameType, "Should not clear while trying to preserve gametype info");
if (bClear || pSource == NULL)
resetGame();
if(pSource == NULL)
return; // advc
// Only copy over saved data
// Descriptive strings about game and map
if (!bSaveGameType || getGameMultiplayer() != pSource->getGameMultiplayer())
setType(pSource->getType());
setGameName(pSource->getGameName());
setGamePassword(pSource->getGamePassword());
setAdminPassword(pSource->getAdminPassword(), false);
setMapScriptName(pSource->getMapScriptName());
setWBMapNoPlayers(pSource->getWBMapNoPlayers());
// Standard game parameters
setWorldSize(pSource->getWorldSize());
setClimate(pSource->getClimate());
setSeaLevel(pSource->getSeaLevel());
setEra(pSource->getEra());
setGameSpeed(pSource->getGameSpeed());
setTurnTimer(pSource->getTurnTimer());
setCalendar(pSource->getCalendar());
// Map-specific custom parameters
setCustomMapOptions(pSource->getNumCustomMapOptions(), pSource->getCustomMapOptions());
m_iNumHiddenCustomMapOptions = pSource->getNumHiddenCustomMapOptions();
// <advc.enum>
FOR_EACH_ENUM(Victory)
{
// Instead of calling that nasty (exported) setVictories function
setVictory(eLoopVictory, pSource->getVictory(eLoopVictory));
} // </advc.enum>
// Standard game options
FOR_EACH_ENUM(GameOption)
{
bool b = pSource->getOption(eLoopGameOption);
// <kekm.18>
CvGameOptionInfo const& kLoopGameOption = GC.getInfo(eLoopGameOption);
if (!kLoopGameOption.getVisible())
b = kLoopGameOption.getDefault(); // </kekm.18>
setOption(eLoopGameOption, b);
}
FOR_EACH_ENUM(MPOption)
{
setMPOption(eLoopMPOption, pSource->getMPOption(eLoopMPOption));
}
setMaxCityElimination(pSource->getMaxCityElimination());
setNumAdvancedStartPoints(pSource->getNumAdvancedStartPoints());
// Misc
setStatReporting(pSource->getStatReporting());
m_bCivLeaderSetupKnown = pSource->m_bCivLeaderSetupKnown; // advc.190c
// Game turn mgmt
setGameTurn(pSource->getGameTurn());
setMaxTurns(pSource->getMaxTurns());
setPitbossTurnTime(pSource->getPitbossTurnTime());
setTargetScore(pSource->getTargetScore());
setSyncRandSeed(pSource->getSyncRandSeed());
setMapRandSeed(pSource->getMapRandSeed());
}
void CvInitCore::resetPlayers(/* advc.enum: */ bool bBeforeRead)
{
for (int i = 0; i < MAX_PLAYERS; ++i)
{
resetPlayer((PlayerTypes)i, /* advc.enum: */ bBeforeRead);
}
}
void CvInitCore::resetPlayers(CvInitCore * pSource, bool bClear, bool bSaveSlotInfo)
{
for (int i = 0; i < MAX_PLAYERS; ++i)
{
resetPlayer((PlayerTypes)i, pSource, bClear, bSaveSlotInfo);
}
}
void CvInitCore::resetPlayer(PlayerTypes eID,
bool bBeforeRead) // advc.enum
{
FAssertBounds(0, MAX_PLAYERS, eID);
// Civ details
m_aszLeaderName[eID].clear();
m_aszCivDescription[eID].clear();
m_aszCivShortDesc[eID].clear();
m_aszCivAdjective[eID].clear();
m_aszCivPassword[eID].clear();
m_aszEmail[eID].clear();
m_aszSmtpHost[eID].clear();
m_uiTotalNameLength = 0; // advc.003k
m_abWhiteFlag.resetVal(eID);
m_aszFlagDecal[eID].clear();
m_aeCiv.resetVal(eID);
m_aeLeader.resetVal(eID);
// <advc.190c>
m_abCivChosenRandomly.resetVal(eID);
m_abLeaderChosenRandomly.resetVal(eID);
// </advc.190c>
m_aeTeam.set(eID, static_cast<TeamTypes>(eID));
// <advc.003c> See comment in resetGame
m_aeHandicap.set(eID, GC.isCachingDone() ?
(HandicapTypes)GC.getDefineINT("STANDARD_HANDICAP") : NO_HANDICAP);
// </advc.003c>
m_aeColor.resetVal(eID);
m_aeArtStyle.resetVal(eID);
// Slot data
m_aeSlotStatus[eID] = SS_CLOSED;
m_aeSlotClaim[eID] = SLOTCLAIM_UNASSIGNED;
// Civ flags
m_abPlayableCiv.resetVal(eID);
m_abMinorNationCiv.resetVal(eID);
// <advc.001p>
if (bBeforeRead)
{ // Avoid crash when loading from within a game
if (GET_PLAYER(eID).isEverAlive())
GET_PLAYER(eID).reset(eID); // </advc.001p>
return; // advc.enum
}
// Unsaved player data
m_aiNetID.resetVal(eID);
m_abReady.resetVal(eID);
m_aszPythonCheck[eID].clear();
m_aszXMLCheck[eID].clear();
if (CvPlayer::areStaticsInitialized())
{
GET_PLAYER(eID).updateTeamType();
GET_PLAYER(eID).updateHuman();
}
}
void CvInitCore::resetPlayer(PlayerTypes eID, CvInitCore * pSource, bool bClear, bool bSaveSlotInfo)
{
FAssert(pSource != NULL);
FAssertBounds(0, MAX_PLAYERS, eID);
FAssertMsg(!bClear || !bSaveSlotInfo, "Should not be clearing data while trying to preserve slot info in CvInitCore::resetPlayer");
if (bClear || pSource == NULL)
resetPlayer(eID);
if (pSource == NULL)
return; // advc
// Only copy over saved data
// Civ details
setCivDescription(eID, pSource->getCivDescription(eID));
setCivShortDesc(eID, pSource->getCivShortDesc(eID));
setCivAdjective(eID, pSource->getCivAdjective(eID));
setCivPassword(eID, pSource->getCivPassword(eID), false);
setEmail(eID, pSource->getEmail(eID));
setSmtpHost(eID, pSource->getSmtpHost(eID));
setFlagDecal(eID, pSource->getFlagDecal(eID));
setWhiteFlag(eID, pSource->getWhiteFlag(eID));
setHandicap(eID, pSource->getHandicap(eID));
setCiv(eID, pSource->getCiv(eID));
setTeam(eID, pSource->getTeam(eID));
setLeader(eID, pSource->getLeader(eID));
// <advc.190c>
m_abCivChosenRandomly.set(eID, pSource->m_abCivChosenRandomly.get(eID));
m_abLeaderChosenRandomly.set(eID, pSource->m_abLeaderChosenRandomly.get(eID));
// </advc.190c>
setColor(eID, pSource->getColor(eID));
setArtStyle(eID, pSource->getArtStyle(eID));
setPlayableCiv(eID, pSource->getPlayableCiv(eID));
setMinorNationCiv(eID, pSource->getMinorNationCiv(eID));
if (!bSaveSlotInfo) // Slot data
{
// We don't wanna reset the slot data if we are loading a game
// from init - we want to keep the changes we made during init
setLeaderName(eID, pSource->getLeaderName(eID));
setSlotStatus(eID, pSource->getSlotStatus(eID));
setSlotClaim(eID, pSource->getSlotClaim(eID));
// <advc.001p> Reset players while loading from within a game to avoid crash
if (pSource->getSavedGame() && GET_PLAYER(eID).isEverAlive())
GET_PLAYER(eID).reset(eID); // </advc.001p>
}
}
CvWString CvInitCore::getMapScriptName() const
{
if (!getWBMapScript() && // advc: Order switched; not sure what getTransferredMap does.
gDLL->getTransferredMap())
{
// If it's a transferred Python file, we have to hack in the transferred extension
return (m_szMapScriptName + CvWString(MAP_TRANSFER_EXT));
}
return m_szMapScriptName;
}
void CvInitCore::setMapScriptName(CvWString const& szMapScriptName)
{
m_szMapScriptName = szMapScriptName;
refreshCustomMapOptions();
updatePangaea();
}
bool CvInitCore::getWBMapScript() const
{
return (gDLL->isDescFileName(CvString(m_szMapScriptName).GetCString()));
}
/* advc.030 (from Civ4Col): This only works at the start of a game b/c all savegames
have type GAME_..._LOAD. Use CvGame::isScenario if it's not the start of a game. */
bool CvInitCore::getScenario() const
{
switch(m_eType)
{
case GAME_SP_SCENARIO:
case GAME_MP_SCENARIO:
case GAME_HOTSEAT_SCENARIO:
case GAME_PBEM_SCENARIO:
return true;
}
return false;
}
void CvInitCore::setWorldSize(CvWString const& szWorldSize)
{
FOR_EACH_ENUM(WorldSize)
{
if (wcsicmp(szWorldSize.GetCString(),
CvWString(GC.getInfo(eLoopWorldSize).getType()).GetCString()) == 0 )
{
setWorldSize(eLoopWorldSize);
}
}
}
const CvWString& CvInitCore::getWorldSizeKey(CvWString& szBuffer) const
{
if (checkBounds(getWorldSize(), 0, GC.getNumWorldInfos()))
{
szBuffer = GC.getInfo(getWorldSize()).getType();
return szBuffer;
}
szBuffer = L"NO_WORLDSIZE";
return szBuffer;
}
void CvInitCore::setClimate(CvWString const& szClimate)
{
FOR_EACH_ENUM(Climate)
{
if (wcsicmp(szClimate.GetCString(),
CvWString(GC.getInfo(eLoopClimate).getType()).GetCString()) == 0 )
{
setClimate(eLoopClimate);
}
}
}
const CvWString& CvInitCore::getClimateKey(CvWString& szBuffer) const
{
if (checkBounds(getClimate(), 0, GC.getNumClimateInfos()))
{
szBuffer = GC.getInfo(getClimate()).getType();
return szBuffer;
}
szBuffer = L"NO_CLIMATE";
return szBuffer;
}
void CvInitCore::setSeaLevel(CvWString const& szSeaLevel)
{
FOR_EACH_ENUM(SeaLevel)
{
if (wcsicmp(szSeaLevel.GetCString(),
CvWString(GC.getInfo(eLoopSeaLevel).getType()).GetCString()) == 0)
{
setSeaLevel(eLoopSeaLevel);
}
}
}
const CvWString& CvInitCore::getSeaLevelKey(CvWString& szBuffer) const
{
if (checkBounds(getSeaLevel(), 0, GC.getNumSeaLevelInfos()))
{
szBuffer = GC.getInfo(getSeaLevel()).getType();
return szBuffer;
}
szBuffer = L"NO_SEALEVEL";
return szBuffer;
}
void CvInitCore::setEra(CvWString const& szEra)
{
FOR_EACH_ENUM(Era)
{
if (wcsicmp(szEra.GetCString(),
CvWString(GC.getInfo(eLoopEra).getType()).GetCString()) == 0 )
{
setEra(eLoopEra);
}
}
}
const CvWString& CvInitCore::getEraKey(CvWString& szBuffer) const
{
if (checkBounds(getEra(), 0, GC.getNumEraInfos()))
{
szBuffer = GC.getInfo(getEra()).getType();
return szBuffer;
}
szBuffer = L"NO_ERA";
return szBuffer;
}
void CvInitCore::setGameSpeed(CvWString const& szGameSpeed)
{
FOR_EACH_ENUM(GameSpeed)
{
if (wcsicmp(szGameSpeed.GetCString(),
CvWString(GC.getInfo(eLoopGameSpeed).getType()).GetCString()) == 0)
{
setGameSpeed(eLoopGameSpeed);
}
}
}
CvWString const& CvInitCore::getGameSpeedKey(CvWString& szBuffer) const
{
if (checkBounds(getGameSpeed(), 0, GC.getNumGameSpeedInfos()))
{
szBuffer = GC.getInfo(getGameSpeed()).getType();
return szBuffer;
}
szBuffer = L"NO_GAMESPEED";
return szBuffer;
}
void CvInitCore::setTurnTimer(CvWString const& szTurnTimer)
{
FOR_EACH_ENUM(TurnTimer)
{
if (wcsicmp(szTurnTimer.GetCString(),
CvWString(GC.getInfo(eLoopTurnTimer).getType()).GetCString()) == 0 )
{
setTurnTimer(eLoopTurnTimer);
}
}
}
CvWString const& CvInitCore::getTurnTimerKey(CvWString& szBuffer) const
{
if (checkBounds(getTurnTimer(), 0, GC.getNumTurnTimerInfos()))
{
szBuffer = GC.getInfo(getTurnTimer()).getType();
return szBuffer;
}
szBuffer = L"NO_TURNTIMER";
return szBuffer;
}
void CvInitCore::setCalendar(CvWString const& szCalendar)
{
FOR_EACH_ENUM(Calendar)
{
if (wcsicmp(szCalendar.GetCString(),
CvWString(GC.getInfo(eLoopCalendar).getType()).GetCString()) == 0 )
{
setCalendar(eLoopCalendar);
}
}
}
CvWString const& CvInitCore::getCalendarKey(CvWString& szBuffer) const
{
if (checkBounds(getCalendar(), 0, NUM_CALENDAR_TYPES))
{
szBuffer = GC.getInfo(getCalendar()).getType();
return szBuffer;
}
szBuffer = L"NO_CALENDAR";
return szBuffer;
}
void CvInitCore::clearCustomMapOptions()
{
SAFE_DELETE_ARRAY(m_aeCustomMapOptions);
m_iNumCustomMapOptions = 0;
}
void CvInitCore::refreshCustomMapOptions()
{
clearCustomMapOptions();
if (getWBMapScript())
return;
CvString szMapScriptNameNarrow(getMapScriptName());
char const* szMapScriptName = szMapScriptNameNarrow.GetCString();
if (!gDLL->pythonMapExists(szMapScriptName))
{ /* advc: GAME_NONE means we're on the opening menu. The map script actually
needs to be present at that point b/c that's (apparently) when the EXE
caches the number of custom map options. However, this won't matter
if the player then selects to load a savegame or start a scenario.
We'll get another call upon entering a non-WB game setup screen;
lets wait for that with the assertion - if the script can't be found
earlier, it still won't be found then. */
FAssertMsg(getType() == GAME_NONE || getType() == GAME_SP_LOAD, "Map script not found");
return;
}
CvPythonCaller const& py = *GC.getPythonCaller();
m_iNumHiddenCustomMapOptions = py.numCustomMapOptions(szMapScriptName, true);
int iOptions = py.numCustomMapOptions(szMapScriptName, false);
if (iOptions <= 0)
return;
CustomMapOptionTypes* aeMapOptions = new CustomMapOptionTypes[iOptions];
for (int i = 0; i < iOptions; i++)
aeMapOptions[i] = py.customMapOptionDefault(szMapScriptName, i);
setCustomMapOptions(iOptions, aeMapOptions);
SAFE_DELETE_ARRAY(aeMapOptions);
}
// advc:
void CvInitCore::updatePangaea()
{
// That's the name of the .py file; not language-dependent.
m_bPangaea = (getMapScriptName().compare(L"Pangaea") == 0);
}
void CvInitCore::setCustomMapOptions(int iNumCustomMapOptions,
CustomMapOptionTypes const* aeCustomMapOptions)
{
clearCustomMapOptions();
if (iNumCustomMapOptions > 0)
{
FAssertMsg(aeCustomMapOptions != NULL, "CustomMap Num/Pointer mismatch in CvInitCore::setCustomMapOptions");
m_iNumCustomMapOptions = iNumCustomMapOptions;
m_aeCustomMapOptions = new CustomMapOptionTypes[m_iNumCustomMapOptions];
for (int i = 0; i < m_iNumCustomMapOptions; ++i)
{
m_aeCustomMapOptions[i] = aeCustomMapOptions[i];
}
}
}
CustomMapOptionTypes CvInitCore::getCustomMapOption(int iOptionID) const
{
FAssertBounds(0, m_iNumCustomMapOptions, iOptionID);
if (checkBounds(iOptionID, 0, m_iNumCustomMapOptions))
return m_aeCustomMapOptions[iOptionID];
return NO_CUSTOM_MAPOPTION;
}
void CvInitCore::setCustomMapOption(int iOptionID, CustomMapOptionTypes eCustomMapOption)
{
FAssertBounds(0, m_iNumCustomMapOptions, iOptionID);
if (checkBounds(iOptionID, 0, m_iNumCustomMapOptions))
m_aeCustomMapOptions[iOptionID] = eCustomMapOption;
}
void CvInitCore::setVictories(int iVictories, bool const* abVictories)
{
SAFE_DELETE_ARRAY(m_abVictories);
m_iNumVictories = 0;
if (iVictories > 0)
{
m_iNumVictories = iVictories;
m_abVictories = new bool[m_iNumVictories];
for (int i = 0; i < m_iNumVictories; i++)
m_abVictories[i] = abVictories[i];
}
}
void CvInitCore::setVictory(VictoryTypes eVictory, bool bVictory)
{
if (checkBounds(eVictory, 0, m_iNumVictories))
m_abVictories[eVictory] = bVictory;
else FAssertBounds(0, m_iNumVictories, eVictory);
}
bool CvInitCore::getVictory(VictoryTypes eVictory) const
{
FAssertBounds(0, m_iNumVictories, eVictory);
if (checkBounds(eVictory, 0, m_iNumVictories))
return m_abVictories[eVictory];
return false;
}
void CvInitCore::setOption(GameOptionTypes eIndex, bool bOption)
{
m_abOptions.set(eIndex, bOption);
}
void CvInitCore::setMPOption(MultiplayerOptionTypes eIndex, bool bOption)
{
m_abMPOptions.set(eIndex, bOption);