| 106 | } |
| 107 | |
| 108 | void 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; |
no test coverage detected