MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / initBattle

Method initBattle

game/state/battle/battle.cpp:108–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108void Battle::initBattle(GameState &state, bool first)
109{
110 common_image_list = state.battle_common_image_list;
111 common_sample_list = state.battle_common_sample_list;
112 loadResources(state);
113 auto stt = shared_from_this();
114 for (auto &s : this->map_parts)
115 {
116 if (s->door)
117 {
118 s->door->mapParts.push_back(s);
119 s->door->position = s->getPosition();
120 }
121 }
122 for (auto &o : this->items)
123 {
124 o->item->ownerItem = o->shared_from_this();
125 o->strategySprite = state.battle_common_image_list->strategyImages->at(480);
126 }
127 for (auto &o : this->units)
128 {
129 o.second->strategyImages = state.battle_common_image_list->strategyImages;
130 o.second->burningDoodad = state.battle_common_image_list->burningDoodad;
131 o.second->genericHitSounds = state.battle_common_sample_list->genericHitSounds;
132 o.second->psiSuccessSounds = state.battle_common_sample_list->psiSuccessSounds;
133 o.second->psiFailSounds = state.battle_common_sample_list->psiFailSounds;
134 }
135 if (forces.empty())
136 {
137 // Init forces and fill squads with nullptrs so that we have where to place units
138 for (auto &o : this->participants)
139 {
140 forces[o];
141 for (int i = 0; i < 6; i++)
142 {
143 forces[o].squads[i].units = std::vector<sp<BattleUnit>>(6);
144 }
145 }
146 // Place units into squads directly to their positions
147 for (auto &u : this->units)
148 {
149 if (u.second->squadNumber == -1)
150 {
151 continue;
152 }
153 forces[u.second->owner].squads[u.second->squadNumber].units[u.second->squadPosition] =
154 u.second;
155 }
156 // Trim nullptrs from squad units
157 for (auto &o : this->participants)
158 {
159 for (int i = 0; i < 6; i++)
160 {
161 for (int j = 5; j >= 0; j--)
162 {
163 if (forces[o].squads[i].units[j])
164 {
165 break;

Callers 2

initStateMethod · 0.80
enterBattleMethod · 0.80

Calls 12

emptyMethod · 0.80
updateTileVisionBlockMethod · 0.80
tryCollapseMethod · 0.80
refreshUnitVisionMethod · 0.80
getPositionMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
initMethod · 0.45
beginTurnRoutineMethod · 0.45
growMethod · 0.45
updateTBMethod · 0.45
beginTurnMethod · 0.45

Tested by

no test coverage detected