From 86872106dc9aa960b417b5ff7f4a175c81058411 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Thu, 26 Apr 2018 11:44:23 +0200 Subject: Add the replicator. --- src/game/unit_soldier.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'src/game/unit_soldier.cpp') diff --git a/src/game/unit_soldier.cpp b/src/game/unit_soldier.cpp index 4747060..1750e2e 100644 --- a/src/game/unit_soldier.cpp +++ b/src/game/unit_soldier.cpp @@ -250,6 +250,72 @@ void unit_soldier_t::command_throw_grenade(v2f_t at) grenade->place(&game->world); } +void unit_soldier_t::command_restock(bool grenades) +{ + rectf_t rect; + bool replicators = false; + size_t needed, taken = 0; + + if (grenades) + needed = storage.max_grenades - storage.grenades; + else + needed = storage.max_shells - storage.shells; + + if (!needed) { + say("Ich kann nicht mehr tragen."); + return; + } + + rect = rectf_t::around(x, 2.0f); + for (world::entity_t *ent : game->world.get_entities(rect, CF_SOLID)) { + world::trace_t trace; + unit_t *unit; + size_t take; + + if (ent->type != ET_UNIT) + continue; + + unit = dynamic_cast(ent); + if (unit->type != UNIT_REPLICATOR) + continue; + + trace = world->ray_v_all(x, unit->x, CF_SOLID, this); + if (trace.hit && trace.ent != ent) + continue; + + replicators = true; + + if (grenades) { + take = std::min(needed, unit->storage.grenades); + taken += take; + unit->storage.grenades -= take; + } else { + take = std::min(needed, unit->storage.shells); + taken += take; + unit->storage.shells -= take; + } + } + + if (!replicators) { + say("Es gibt keine Replikators."); + return; + } + + if (!taken) { + if (grenades) + say("Ich konnte keine Granaten finden."); + else + say("Ich konnte keine Munition finden."); + + return; + } + + if (grenades) + storage.grenades += taken; + else + storage.shells += taken; +} + void unit_soldier_t::render_to(render::state_t *render) { sf::Color selection_color; -- cgit