summaryrefslogtreecommitdiff
path: root/src/game/units.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-03-28 14:17:47 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-03-28 14:17:47 +0200
commit6966908022e36df9fb4c5e2233603a6fef18e97d (patch)
tree1540097e60001636cbe752d8fb1e459f45081e41 /src/game/units.cpp
parentaa4731d2e1305ea4fb6d59032026bf1ce6f2b65d (diff)
Pie menu; start redoing shooting mechanics.
Diffstat (limited to 'src/game/units.cpp')
-rw-r--r--src/game/units.cpp68
1 files changed, 50 insertions, 18 deletions
diff --git a/src/game/units.cpp b/src/game/units.cpp
index a0dcee3..f3d53d7 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -188,6 +188,12 @@ bool unit_t::start_moving(v2f_t dst)
return true;
}
+void unit_t::stop_moving(void)
+{
+ move.path.clear();
+ move.moving = false;
+}
+
void unit_t::damage(int points, unit_t *attacker)
{
fx_blood_t *blood;
@@ -316,14 +322,52 @@ void unit_soldier_t::check_area(void)
}
}
-void unit_soldier_t::target_and_attack(void)
+static v2f_t spread_aim(v2f_t aim, float cof, procgen::prng_t *prng)
{
- unit_t *target;
+ float t;
+
+ t = prng->next_float(-cof / 2, cof / 2);
+
+ return v2f_t(cos(t) * aim[0] - sin(t) * aim[1],
+ sin(t) * aim[0] + cos(t) * aim[1]);
+}
+
+void unit_soldier_t::shoot(v2f_t aim)
+{
+ v2f_t end;
world::trace_t trace;
v2f_t muzzle_point;
fx_tracer_t *tracer;
fx_flash_t *flash;
+ end = x + (aim - x).norm() * 40;
+
+ trace = world->trace(x, end, CF_SOLID);
+
+ muzzle_point = x + v2f_t(0, -1.0f);
+
+ tracer = new fx_tracer_t(game, muzzle_point, trace.end);
+ tracer->place(&game->world);
+
+ flash = new fx_flash_t(game, muzzle_point, 5.0f);
+ flash->place(&game->world);
+
+ last_attack = game->now;
+ assets::soldier.fire.play();
+ //target->damage(3, this); FIXME
+}
+
+void unit_soldier_t::target_and_attack(void)
+{
+ unit_t *target;
+ v2f_t aim;
+
+ if (manual_firing) {
+ aim = manual_firing_target;
+ last_target_x = aim;
+ goto skip_targetting;
+ }
+
if (game->now < next_targetting)
return;
@@ -332,28 +376,16 @@ void unit_soldier_t::target_and_attack(void)
target = find_target(world, x, 5.0f, false);
if (!target)
return;
+ aim = target->x;
last_target_time = game->now;
last_target_x = target->x;
+skip_targetting:
if (last_attack + game->dice_prng.next_float(1.4f, 1.6f) > game->now)
return;
- trace = world->trace(x, target->x, CF_SOLID);
- if (trace.hit)
- return;
-
- muzzle_point = x + v2f_t(0, -1.0f);
-
- tracer = new fx_tracer_t(game, muzzle_point, target->x);
- tracer->place(&game->world);
-
- flash = new fx_flash_t(game, muzzle_point, 5.0f);
- flash->place(&game->world);
-
- last_attack = game->now;
- assets::soldier.fire.play();
- target->damage(3, this);
+ shoot(spread_aim(aim, 0.2, &game->dice_prng));
}
void unit_soldier_t::on_think(void)
@@ -465,7 +497,7 @@ void unit_soldier_t::render_to(render::state_t *render)
else
legs = &assets::soldier.legs_idle;
- if (!panic && last_target_time + 3 > game->now) {
+ if (!panic && (manual_firing || last_target_time + 3 > game->now)) {
if (last_attack + 0.1 > game->now)
body = &assets::soldier.body_firing;
else