| 1135 | } |
| 1136 | |
| 1137 | sp<BattleUnit> Battle::spawnUnit(GameState &state, StateRef<Organisation> owner, |
| 1138 | StateRef<AgentType> agentType, Vec3<float> position, |
| 1139 | Vec2<int> facing, BodyState curState, BodyState tarState) |
| 1140 | { |
| 1141 | auto agent = state.agent_generator.createAgent(state, owner, agentType); |
| 1142 | agent->city = state.current_city; |
| 1143 | auto unit = state.current_battle->placeUnit(state, agent, position); |
| 1144 | unit->falling = true; |
| 1145 | if (facing.x == 0 && facing.y == 0) |
| 1146 | { |
| 1147 | if (agentType->bodyType->allowed_facing.empty()) |
| 1148 | { |
| 1149 | facing = {randBoundsInclusive(state.rng, 0, 1), randBoundsInclusive(state.rng, 0, 1)}; |
| 1150 | if (facing.x == 0 && facing.y == 0) |
| 1151 | { |
| 1152 | facing.y = 1; |
| 1153 | } |
| 1154 | } |
| 1155 | else |
| 1156 | { |
| 1157 | facing = |
| 1158 | pickRandom(state.rng, agentType->bodyType->allowed_facing.at(agent->appearance)); |
| 1159 | } |
| 1160 | } |
| 1161 | unit->setFacing(state, facing); |
| 1162 | unit->setBodyState(state, curState); |
| 1163 | unit->setMission(state, BattleUnitMission::changeStance(*unit, tarState)); |
| 1164 | unit->assignToSquad(*state.current_battle); |
| 1165 | unit->refreshUnitVisibilityAndVision(state); |
| 1166 | |
| 1167 | unit->strategyImages = state.battle_common_image_list->strategyImages; |
| 1168 | unit->burningDoodad = state.battle_common_image_list->burningDoodad; |
| 1169 | unit->genericHitSounds = state.battle_common_sample_list->genericHitSounds; |
| 1170 | unit->psiSuccessSounds = state.battle_common_sample_list->psiSuccessSounds; |
| 1171 | unit->psiFailSounds = state.battle_common_sample_list->psiFailSounds; |
| 1172 | |
| 1173 | return unit; |
| 1174 | } |
| 1175 | |
| 1176 | sp<BattleExplosion> Battle::addExplosion(GameState &state, Vec3<int> position, |
| 1177 | StateRef<DoodadType> doodadType, |
no test coverage detected