diff options
Diffstat (limited to 'src/game/unit_builder.cpp')
-rw-r--r-- | src/game/unit_builder.cpp | 88 |
1 files changed, 85 insertions, 3 deletions
diff --git a/src/game/unit_builder.cpp b/src/game/unit_builder.cpp index fcb3b90..1ed7f58 100644 --- a/src/game/unit_builder.cpp +++ b/src/game/unit_builder.cpp @@ -51,6 +51,78 @@ unit_builder_t::unit_builder_t(game::state_t *game) : unit_t(game, UNIT_BUILDER) health = max_health = 45; } +void unit_builder_t::command_stop(void) +{ + stop_moving(); + move_marker.reset(); + + repairing = false; + repair_marker.reset(); + + say("Stop.", false); +} + +void unit_builder_t::command_repair(v2f_t where) +{ + repairing = true; + building = false; + repairing_at = where; + repair_marker = std::make_unique<fx_aim_marker_t>(game, where); + say("Idę naprawiać.", false); +} + +void unit_builder_t::command_build(v2f_t where, type_t what) +{ + world::trace_t trace; + unit_t *built; + size_t price; + world::cmodel_t cmodel; + + if ((x - where).len() > 1.3f) { + say("Tak daleko tego nie postawię!"); + return; + } + + trace = world->ray_v_all(x, where, CF_SOLID|CF_WATER|CF_DECOS, this); + if (trace.hit) { + say("Coś stoi mi na drodze."); + return; + } + + switch (what) { + case UNIT_REPL: + built = new unit_repl_t(game); + price = 250; + break; + + default: + abort(); + } + + if (price > game->crystals) { + game->interface.print("Insufficient crystals; " + std::to_string(price - game->crystals) + " more needed"); + delete built; + return; + } + + cmodel.bounds[0] = where + built->size[0]; + cmodel.bounds[1] = where + built->size[1]; + cmodel.cflags = CF_SOLID|CF_SURFACE2|CF_WATER|CF_DECOS; + + if (world->test_rect(&cmodel, nullptr)) { + say("Nie ma tutaj miejsca."); + delete built; + return; + } + + game->crystals -= price; + built->place(world, where); + + repairing = true; + building = true; + repairing_at = where; +} + void unit_builder_t::repair(void) { rectf_t rect; @@ -66,7 +138,7 @@ void unit_builder_t::repair(void) if (next_repair && next_repair > game->time) return; - trace = game->world.ray_v_all_p3d(x, repairing_at, CF_SOLID, CF_SURFACE, this); + trace = game->world.ray_v_all_p3d(x, repairing_at, CF_SOLID, CF_SURFACE2, this); if (!trace.hit || !trace.ent || trace.ent->type != ET_UNIT) { repairing = false; return; @@ -79,7 +151,11 @@ void unit_builder_t::repair(void) } if (!game->crystals) { - say("Nie mam czym naprawiać!"); + game->interface.print("Insufficient crystals; 1 more needed."); + if (building) + say("Nie mam czym konstruować!", false); + else + say("Nie mam czym naprawiać!", false); return; } @@ -89,7 +165,13 @@ void unit_builder_t::repair(void) if (unit->max_health - unit->health < 3) { repairing = false; unit->health = unit->max_health; - say("Naprawa ukończona."); + unit->constructed = true; + + if (building) + say("Budowa zakończona."); + else + say("Naprawa ukończona."); + } else unit->health += 2; |