1 #include "Campaign_Init.h"
2
3 #include "Campaign_Types.h"
4 #include "ContentManager.h"
5 #include "Creature_Spreading.h"
6 #include "GameInstance.h"
7 #include "GameSettings.h"
8 #include "MemMan.h"
9 #include "Overhead.h"
10 #include "Queen_Command.h"
11 #include "Quests.h"
12 #include "Random.h"
13 #include "Strategic_AI.h"
14 #include "Strategic_Mines.h"
15 #include "Strategic_Movement.h"
16 #include "Strategic_Movement_Costs.h"
17 #include "Strategic_Status.h"
18 #include "Tactical_Save.h"
19 #include "Types.h"
20 #include "UndergroundSectorModel.h"
21
22 #include <algorithm>
23
24 UNDERGROUND_SECTORINFO* gpUndergroundSectorInfoTail = NULL;
25
26
AddUndergroundNode(const UndergroundSectorModel * ugInfo,UINT8 ubDifLevel)27 static UNDERGROUND_SECTORINFO* AddUndergroundNode(const UndergroundSectorModel* ugInfo, UINT8 ubDifLevel)
28 {
29 UNDERGROUND_SECTORINFO* const u = ugInfo->createUndergroundSectorInfo(ubDifLevel);
30 UNDERGROUND_SECTORINFO*& tail = gpUndergroundSectorInfoTail;
31 *(tail ? &tail->next : &gpUndergroundSectorInfoHead) = u;
32 tail = u;
33
34 return u;
35 }
36
37
38 // setup which know facilities are in which cities
InitKnowFacilitiesFlags(void)39 static void InitKnowFacilitiesFlags(void)
40 {
41 SECTORINFO *pSector;
42
43 // Cambria hospital
44 pSector = &SectorInfo[SEC_G8];
45 pSector->uiFacilitiesFlags |= SFCF_HOSPITAL;
46 pSector = &SectorInfo[SEC_F8];
47 pSector->uiFacilitiesFlags |= SFCF_HOSPITAL;
48 pSector = &SectorInfo[SEC_G9];
49 pSector->uiFacilitiesFlags |= SFCF_HOSPITAL;
50 pSector = &SectorInfo[SEC_F9];
51 pSector->uiFacilitiesFlags |= SFCF_HOSPITAL;
52
53 // Drassen airport
54 pSector = &SectorInfo[SEC_B13];
55 pSector->uiFacilitiesFlags |= SFCF_AIRPORT;
56 pSector = &SectorInfo[SEC_C13];
57 pSector->uiFacilitiesFlags |= SFCF_AIRPORT;
58 pSector = &SectorInfo[SEC_D13];
59 pSector->uiFacilitiesFlags |= SFCF_AIRPORT;
60
61 // Meduna airport & military complex
62 pSector = &SectorInfo[SEC_N3];
63 pSector->uiFacilitiesFlags |= SFCF_AIRPORT;
64 pSector = &SectorInfo[SEC_N4];
65 pSector->uiFacilitiesFlags |= SFCF_AIRPORT;
66 pSector = &SectorInfo[SEC_N5];
67 pSector->uiFacilitiesFlags |= SFCF_AIRPORT;
68 pSector = &SectorInfo[SEC_O3];
69 pSector->uiFacilitiesFlags |= SFCF_AIRPORT;
70 pSector = &SectorInfo[SEC_O4];
71 pSector->uiFacilitiesFlags |= SFCF_AIRPORT;
72 }
73
74
TrashUndergroundSectorInfo()75 void TrashUndergroundSectorInfo()
76 {
77 UNDERGROUND_SECTORINFO *curr;
78 while( gpUndergroundSectorInfoHead )
79 {
80 curr = gpUndergroundSectorInfoHead;
81 gpUndergroundSectorInfoHead = gpUndergroundSectorInfoHead->next;
82 delete curr;
83 }
84 gpUndergroundSectorInfoHead = NULL;
85 gpUndergroundSectorInfoTail = NULL;
86 }
87
88 //Defines the sectors that can be occupied by enemies, creatures, etc. It also
89 //contains the network of cave connections critical for strategic creature spreading, as we can't
90 //know how the levels connect without loading the maps.
BuildUndergroundSectorInfoList()91 void BuildUndergroundSectorInfoList()
92 {
93 TrashUndergroundSectorInfo();
94
95 for (auto ugInfo : GCM->getUndergroundSectors())
96 {
97 AddUndergroundNode(ugInfo, gGameOptions.ubDifficultyLevel);
98 }
99 }
100
101 //This is the function that is called only once, when the player begins a new game. This will calculate
102 //starting numbers of the queen's army in various parts of the map, which will vary from campaign to campaign.
103 //This is also highly effected by the game's difficulty setting.
InitNewCampaign()104 void InitNewCampaign()
105 {
106 //First clear all the sector information of all enemy existance. Conveniently, the
107 //ubGroupType is also cleared, which is perceived to be an empty group.
108 std::fill_n(SectorInfo, 256, SECTORINFO{});
109 InitStrategicMovementCosts();
110 RemoveAllGroups();
111
112 InitKnowFacilitiesFlags( );
113
114 BuildUndergroundSectorInfoList();
115
116 // Allow overhead view of start sector on game onset.
117 SetSectorFlag(SECTORX(START_SECTOR), SECTORY(START_SECTOR), 0, SF_ALREADY_VISITED);
118
119 //Generates the initial forces in a new campaign. The idea is to randomize numbers and sectors
120 //so that no two games are the same.
121 InitStrategicAI();
122
123 InitStrategicStatus();
124
125 }
126