|
|
@@ -0,0 +1,95 @@
|
|
|
+#include "healer.h"
|
|
|
+#include "../core/component.h"
|
|
|
+#include "../core/event_manager.h"
|
|
|
+#include "../core/world.h"
|
|
|
+#include "../systems/troop_profile_service.h"
|
|
|
+#include "units/troop_type.h"
|
|
|
+#include "units/unit.h"
|
|
|
+#include <memory>
|
|
|
+#include <qvectornd.h>
|
|
|
+
|
|
|
+static inline auto team_color(int owner_id) -> QVector3D {
|
|
|
+ switch (owner_id) {
|
|
|
+ case 1:
|
|
|
+ return {0.20F, 0.55F, 1.00F};
|
|
|
+ case 2:
|
|
|
+ return {1.00F, 0.30F, 0.30F};
|
|
|
+ case 3:
|
|
|
+ return {0.20F, 0.80F, 0.40F};
|
|
|
+ case 4:
|
|
|
+ return {1.00F, 0.80F, 0.20F};
|
|
|
+ default:
|
|
|
+ return {0.8F, 0.9F, 1.0F};
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+namespace Game::Units {
|
|
|
+
|
|
|
+Healer::Healer(Engine::Core::World &world) : Unit(world, TroopType::Healer) {}
|
|
|
+
|
|
|
+auto Healer::Create(Engine::Core::World &world,
|
|
|
+ const SpawnParams ¶ms) -> std::unique_ptr<Healer> {
|
|
|
+ auto unit = std::unique_ptr<Healer>(new Healer(world));
|
|
|
+ unit->init(params);
|
|
|
+ return unit;
|
|
|
+}
|
|
|
+
|
|
|
+void Healer::init(const SpawnParams ¶ms) {
|
|
|
+
|
|
|
+ auto *e = m_world->createEntity();
|
|
|
+ m_id = e->getId();
|
|
|
+
|
|
|
+ const auto nation_id = resolve_nation_id(params);
|
|
|
+ auto profile = Game::Systems::TroopProfileService::instance().get_profile(
|
|
|
+ nation_id, TroopType::Healer);
|
|
|
+
|
|
|
+ m_t = e->addComponent<Engine::Core::TransformComponent>();
|
|
|
+ m_t->position = {params.position.x(), params.position.y(),
|
|
|
+ params.position.z()};
|
|
|
+ float const scale = profile.visuals.render_scale;
|
|
|
+ m_t->scale = {scale, scale, scale};
|
|
|
+
|
|
|
+ m_r = e->addComponent<Engine::Core::RenderableComponent>("", "");
|
|
|
+ m_r->visible = true;
|
|
|
+ m_r->rendererId = profile.visuals.renderer_id;
|
|
|
+
|
|
|
+ m_u = e->addComponent<Engine::Core::UnitComponent>();
|
|
|
+ m_u->spawn_type = params.spawn_type;
|
|
|
+ m_u->health = profile.combat.health;
|
|
|
+ m_u->max_health = profile.combat.max_health;
|
|
|
+ m_u->speed = profile.combat.speed;
|
|
|
+ m_u->owner_id = params.player_id;
|
|
|
+ m_u->vision_range = profile.combat.vision_range;
|
|
|
+ m_u->nation_id = nation_id;
|
|
|
+
|
|
|
+ if (params.aiControlled) {
|
|
|
+ e->addComponent<Engine::Core::AIControlledComponent>();
|
|
|
+ }
|
|
|
+
|
|
|
+ QVector3D const tc = team_color(m_u->owner_id);
|
|
|
+ m_r->color[0] = tc.x();
|
|
|
+ m_r->color[1] = tc.y();
|
|
|
+ m_r->color[2] = tc.z();
|
|
|
+
|
|
|
+ m_mv = e->addComponent<Engine::Core::MovementComponent>();
|
|
|
+ if (m_mv != nullptr) {
|
|
|
+ m_mv->goalX = params.position.x();
|
|
|
+ m_mv->goalY = params.position.z();
|
|
|
+ m_mv->target_x = params.position.x();
|
|
|
+ m_mv->target_y = params.position.z();
|
|
|
+ }
|
|
|
+
|
|
|
+ auto *healer_comp = e->addComponent<Engine::Core::HealerComponent>();
|
|
|
+ if (healer_comp != nullptr) {
|
|
|
+ healer_comp->healing_range = profile.combat.vision_range * 0.6F;
|
|
|
+ healer_comp->healing_amount = profile.combat.ranged_damage > 0
|
|
|
+ ? profile.combat.ranged_damage
|
|
|
+ : 5;
|
|
|
+ healer_comp->healing_cooldown = profile.combat.ranged_cooldown;
|
|
|
+ }
|
|
|
+
|
|
|
+ Engine::Core::EventManager::instance().publish(
|
|
|
+ Engine::Core::UnitSpawnedEvent(m_id, m_u->owner_id, m_u->spawn_type));
|
|
|
+}
|
|
|
+
|
|
|
+} // namespace Game::Units
|