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

Method attachToSomething

game/state/battle/battlemappart.cpp:242–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242bool BattleMapPart::attachToSomething(bool checkType, bool checkHard)
243{
244 providesHardSupport = false;
245 auto pos = tileObject->getOwningTile()->position;
246 auto &map = tileObject->map;
247 // Cling to ceiling
248 if (pos.z == map.size.z - 1)
249 {
250 return true;
251 }
252 auto tileType = tileObject->getType();
253 auto sft = shared_from_this();
254
255 // List of directions (for ground and feature)
256 static const std::list<Vec3<int>> directionGDFTList = {
257 {0, 0, -1}, {0, 0, 1}, {0, -1, 0}, {1, 0, 0}, {0, 1, 0}, {-1, 0, 0},
258 };
259
260 // List of directions for left wall
261 static const std::list<Vec3<int>> directionLWList = {
262 {0, 0, -1}, {0, -1, 0}, {0, 1, 0}, {0, 0, 1}, {-1, 0, 0}, {0, 0, 0},
263 };
264
265 // List of directions for right wall
266 static const std::list<Vec3<int>> directionRWList = {
267 {0, 0, -1}, {1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {0, 0, 0},
268 };
269
270 auto &directionList =
271 tileType == TileObject::Type::LeftWall
272 ? directionLWList
273 : (tileType == TileObject::Type::RightWall ? directionRWList : directionGDFTList);
274
275 // Search for map parts
276 for (auto &dir : directionList)
277 {
278 int x = pos.x + dir.x;
279 int y = pos.y + dir.y;
280 int z = pos.z + dir.z;
281 if (x < 0 || x >= map.size.x || y < 0 || y >= map.size.y || z < 0 || z >= map.size.z)
282 {
283 continue;
284 }
285 auto tile = map.getTile(x, y, z);
286 for (auto &o : tile->ownedObjects)
287 {
288 if (o->getType() != tileType && checkType)
289 {
290 continue;
291 }
292 // Even if we're not doing type checking, we cannot allow for walls to cling to other
293 // type of walls through gaps
294 if (tileType == TileObject::Type::RightWall)
295 {
296 if ((o->getType() == TileObject::Type::LeftWall && x < pos.x) ||
297 (o->getType() == TileObject::Type::RightWall && y < pos.y))
298 {
299 continue;

Callers 1

initialMapPartLinkUpMethod · 0.45

Calls 5

getOwningTileMethod · 0.80
getTileMethod · 0.80
getTypeMethod · 0.45
getOwnerMethod · 0.45
isAliveMethod · 0.45

Tested by

no test coverage detected