summaryrefslogtreecommitdiff
path: root/src/game/unit_soldier.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-26 11:44:23 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-26 11:44:23 +0200
commit86872106dc9aa960b417b5ff7f4a175c81058411 (patch)
treee8da47396f7f7eb37efe80b559e68d84aec9e818 /src/game/unit_soldier.cpp
parentd04e1b48bd934f8d9d91aab13e9e51393fd7b6ba (diff)
Add the replicator.
Diffstat (limited to 'src/game/unit_soldier.cpp')
-rw-r--r--src/game/unit_soldier.cpp66
1 files changed, 66 insertions, 0 deletions
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<unit_t*>(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;