From f4fe2c7f10a8d2e253de27f1a540ca68184d5d29 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 20 Apr 2018 12:35:21 +0200 Subject: Pseudo 3D firing and misc. fixes. --- src/game/unit_soldier.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/game/unit_soldier.cpp') diff --git a/src/game/unit_soldier.cpp b/src/game/unit_soldier.cpp index 433f88d..4cf840d 100644 --- a/src/game/unit_soldier.cpp +++ b/src/game/unit_soldier.cpp @@ -64,14 +64,18 @@ void unit_soldier_t::check_area(void) } } -static v2f_t spread_aim(v2f_t aim, float cof, procgen::prng_t *prng) +static v2f_t spread_aim(v2f_t x, v2f_t aim, float cof, procgen::prng_t *prng) { - float t; + float r, r_, dth; + v2f_t tmp; - t = prng->next_float(-cof / 2, cof / 2); + r = (aim - x).len(); + r_ = r + cof * r * prng->next_float(-1.0f, 1.0f); + tmp = (aim - x) / r * r_; - return v2f_t(cos(t) * aim[0] - sin(t) * aim[1], - sin(t) * aim[0] + cos(t) * aim[1]); + dth = cof * prng->next_float(-1.0f, 1.0f); + return x + v2f_t(cos(dth) * tmp[0] - sin(dth) * tmp[1], + sin(dth) * tmp[0] + cos(dth) * tmp[1]); } void unit_soldier_t::shoot(v2f_t aim) @@ -82,9 +86,9 @@ void unit_soldier_t::shoot(v2f_t aim) fx_tracer_t *tracer; fx_flash_t *flash; - end = x + (aim - x).norm() * 40; + end = spread_aim(x, aim, 0.1f, &game->prng); - trace = world->ray_v_all(x, end, CF_SOLID|CF_BODY|CF_BODY_SMALL, this); + trace = world->ray_v_all_p3d(x, end, CF_SOLID|CF_BODY|CF_BODY_SMALL, -1, this); if (!manual_firing && trace.hit && trace.ent && trace.ent->type == ET_UNIT) { unit_t *unit = dynamic_cast(trace.ent); @@ -110,6 +114,13 @@ void unit_soldier_t::shoot(v2f_t aim) entity_t *ent = dynamic_cast(trace.ent); ent->damage(3, this); } + + if (!trace.hit || (trace.ent && trace.ent->type != ET_UNIT)) { + fx_ricochet_t *ricochet; + + ricochet = new fx_ricochet_t(game, trace.end); + ricochet->place(&game->world); + } } void unit_soldier_t::target_and_attack(void) @@ -144,15 +155,13 @@ skip_targetting: if (last_attack + game->prng.next_float(1.4f, 1.6f) > game->now) return; - shoot(spread_aim(aim, 0.01, &game->prng)); + shoot(aim); } void unit_soldier_t::on_think(void) { - check_area(); - target_and_attack(); - keep_moving(2.0); + if (!move.moving) move_marker.reset(); @@ -160,6 +169,9 @@ void unit_soldier_t::on_think(void) move.last_step = x; assets::soldier.step_stone.play_3d(x); } + + check_area(); + target_and_attack(); } void unit_soldier_t::on_damage(unit_t *attacker) -- cgit