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

Method initialMapCheck

game/state/battle/battle.cpp:316–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314}
315
316bool Battle::initialMapCheck(GameState &state, std::list<StateRef<Agent>> agents)
317{
318 initMap();
319
320 // No checks for base defense
321 if (mission_type == MissionType::BaseDefense)
322 {
323 return true;
324 }
325
326 // Mark as low-priority all the enemy spawn los blocks that are seen from any player spawn block
327 for (auto &playerSpawn : losBlocks)
328 {
329 if (playerSpawn->spawn_type != SpawnType::Player || playerSpawn->spawn_priority == 0)
330 {
331 continue;
332 }
333 auto sPos = Vec3<float>((playerSpawn->start.x + playerSpawn->end.x) / 2.0f + 0.5f,
334 (playerSpawn->start.y + playerSpawn->end.y) / 2.0f + 0.5f,
335 playerSpawn->start.z + 0.5f);
336 for (auto &enemySpawn : losBlocks)
337 {
338 if (enemySpawn->spawn_type != SpawnType::Enemy || enemySpawn->spawn_priority == 0 ||
339 enemySpawn->low_priority)
340 {
341 continue;
342 }
343 auto ePos = Vec3<float>((enemySpawn->start.x + enemySpawn->end.x) / 2.0f + 0.5f,
344 (enemySpawn->start.y + enemySpawn->end.y) / 2.0f + 0.5f,
345 enemySpawn->start.z + 0.5f);
346 if (glm::length(ePos - sPos) > VIEW_DISTANCE ||
347 map->findCollision(sPos, ePos, {}, nullptr, true))
348 {
349 continue;
350 }
351 LogWarning("Los block center %s visible from %s", ePos, sPos);
352 enemySpawn->low_priority = true;
353 }
354 }
355
356 // Find out spawn point ratio for enemies
357 int spawnPoints = 0;
358 int spawnPointsRequired = 0;
359
360 for (auto &enemySpawn : losBlocks)
361 {
362 if (enemySpawn->spawn_type != SpawnType::Enemy || enemySpawn->low_priority)
363 {
364 continue;
365 }
366 for (int x = enemySpawn->start.x; x < enemySpawn->end.x; x++)
367 {
368 for (int y = enemySpawn->start.y; y < enemySpawn->end.y; y++)
369 {
370 auto tile = map->getTile(x, y, enemySpawn->start.z);
371 if (tile->getCanStand())
372 {
373 spawnPoints++;

Callers 1

createBattleMethod · 0.80

Calls 5

findCollisionMethod · 0.80
getTileMethod · 0.80
getCanStandMethod · 0.80
getPlayerMethod · 0.80
getCivilianMethod · 0.80

Tested by

no test coverage detected