#include "terrain_alignment_system.h" #include "../core/component.h" #include "../core/entity.h" #include "../core/world.h" #include "../map/terrain_service.h" #include "../units/troop_config.h" namespace Game::Systems { void TerrainAlignmentSystem::update(Engine::Core::World *world, float) { auto &terrain_service = Game::Map::TerrainService::instance(); if (!terrain_service.is_initialized()) { return; } auto entities = world->get_entities_with(); for (auto *entity : entities) { align_entity_to_terrain(entity); } } void TerrainAlignmentSystem::align_entity_to_terrain( Engine::Core::Entity *entity) { auto *transform = entity->get_component(); if (transform == nullptr) { return; } auto &terrain_service = Game::Map::TerrainService::instance(); float const terrain_height = terrain_service.get_terrain_height( transform->position.x, transform->position.z); float entity_base_offset = 0.0F; if (auto *unit = entity->get_component()) { entity_base_offset = Game::Units::TroopConfig::instance().getSelectionRingGroundOffset( unit->spawn_type); } transform->position.y = terrain_height + entity_base_offset * transform->scale.y; } } // namespace Game::Systems