summaryrefslogtreecommitdiff
path: root/src/game/unit_builder.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-22 18:49:53 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-22 18:49:53 +0200
commit30c721089df4235a09829557005b029f9f5a7df1 (patch)
tree7a15f11314ef8008df01ca6d07c0eed9e3448b13 /src/game/unit_builder.cpp
parent4d757f7b9bcb30affbae7c567e2691cb616e96c1 (diff)
Repairing mechanic for the builder.
Diffstat (limited to 'src/game/unit_builder.cpp')
-rw-r--r--src/game/unit_builder.cpp55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/game/unit_builder.cpp b/src/game/unit_builder.cpp
index 1f5b81c..fcb3b90 100644
--- a/src/game/unit_builder.cpp
+++ b/src/game/unit_builder.cpp
@@ -51,6 +51,52 @@ unit_builder_t::unit_builder_t(game::state_t *game) : unit_t(game, UNIT_BUILDER)
health = max_health = 45;
}
+void unit_builder_t::repair(void)
+{
+ rectf_t rect;
+ world::trace_t trace;
+ unit_t *unit;
+
+ if (!move.moving)
+ start_moving(repairing_at);
+
+ if ((x - repairing_at).len() > 0.5f)
+ return;
+
+ if (next_repair && next_repair > game->time)
+ return;
+
+ trace = game->world.ray_v_all_p3d(x, repairing_at, CF_SOLID, CF_SURFACE, this);
+ if (!trace.hit || !trace.ent || trace.ent->type != ET_UNIT) {
+ repairing = false;
+ return;
+ }
+
+ unit = dynamic_cast<unit_t*>(trace.ent);
+ if (unit->type != UNIT_REPL || unit->health >= unit->max_health) {
+ repairing = false;
+ return;
+ }
+
+ if (!game->crystals) {
+ say("Nie mam czym naprawiać!");
+ return;
+ }
+
+ game->crystals--;
+ assets::ui.crystal_tick.play();
+
+ if (unit->max_health - unit->health < 3) {
+ repairing = false;
+ unit->health = unit->max_health;
+ say("Naprawa ukończona.");
+ } else
+ unit->health += 2;
+
+ next_repair = game->time + MSEC(250);
+ last_repair = game->time;
+}
+
void unit_builder_t::on_think(void)
{
keep_moving(2.0);
@@ -59,6 +105,11 @@ void unit_builder_t::on_think(void)
if (!move.moving)
move_marker.reset();
+ if (repairing)
+ repair();
+ else
+ repair_marker.reset();
+
if (move.moving && (x - move.last_step).len() > 0.5f) {
move.last_step = x;
assets::soldier.step_stone.play_3d(x);
@@ -121,7 +172,9 @@ void unit_builder_t::render_to(render::state_t *render)
render->render(0.0, &assets::unit_selected, cmodel.bounds, selection_color);
}
- if (!dead) {
+ if (!dead && last_repair + MSEC(300) > game->time) {
+ render->render(game->now * 2.0f, &assets::builder.repairing, render_bounds);
+ } else if (!dead) {
render::oriented_sprite_t *legs;
if (move.moving && !move.blocked)