| 1163 | } |
| 1164 | |
| 1165 | void BattleMapPart::updateFalling(GameState &state, unsigned int ticks) |
| 1166 | { |
| 1167 | auto fallTicksRemaining = ticks; |
| 1168 | auto newPosition = position; |
| 1169 | while (fallTicksRemaining-- > 0) |
| 1170 | { |
| 1171 | fallingSpeed += FALLING_ACCELERATION_MAP_PART; |
| 1172 | newPosition -= Vec3<float>{0.0f, 0.0f, (fallingSpeed / TICK_SCALE)} / VELOCITY_SCALE_BATTLE; |
| 1173 | } |
| 1174 | |
| 1175 | // Collision with this tile happens when map part moves from this tile to the next |
| 1176 | if (newPosition.z < 0 || floorf(newPosition.z) != floorf(position.z)) |
| 1177 | { |
| 1178 | sp<BattleMapPart> rubble; |
| 1179 | // we may kill a unit by applying fall damage, this will trigger a stance change which will |
| 1180 | // remove its tile and shadow objects from the ownedObjects set (invalidating iterators) |
| 1181 | // we work around this by iterating over a set's copy |
| 1182 | auto set = tileObject->getOwningTile()->ownedObjects; |
| 1183 | for (auto &obj : set) |
| 1184 | { |
| 1185 | if (tileObject->getOwningTile()->ownedObjects.find(obj) == |
| 1186 | tileObject->getOwningTile()->ownedObjects.end()) |
| 1187 | { |
| 1188 | continue; |
| 1189 | } |
| 1190 | switch (obj->getType()) |
| 1191 | { |
| 1192 | // If there's a live ground or map mart of our type here - die |
| 1193 | case TileObject::Type::Ground: |
| 1194 | case TileObject::Type::LeftWall: |
| 1195 | case TileObject::Type::RightWall: |
| 1196 | case TileObject::Type::Feature: |
| 1197 | { |
| 1198 | auto mp = std::static_pointer_cast<TileObjectBattleMapPart>(obj)->getOwner(); |
| 1199 | |
| 1200 | // Find if we collide into it |
| 1201 | if (mp->type->type == type->type || |
| 1202 | mp->type->type == BattleMapPartType::Type::Ground) |
| 1203 | { |
| 1204 | if (tileObject && mp->isAlive()) |
| 1205 | { |
| 1206 | destroyed = true; |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | // Find if we deposit rubble into it |
| 1211 | if ((type->type != BattleMapPartType::Type::Ground && |
| 1212 | mp->type->type == type->type) || |
| 1213 | (type->type == BattleMapPartType::Type::Ground && |
| 1214 | mp->type->type == BattleMapPartType::Type::Feature)) |
| 1215 | { |
| 1216 | if (mp->isAlive()) |
| 1217 | { |
| 1218 | rubble = mp; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | break; |
nothing calls this directly
no test coverage detected