summaryrefslogtreecommitdiff
path: root/src/game/unit_soldier.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-20 13:08:58 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-20 13:08:58 +0200
commite8b487b0d2c1dc622256b89642ac291632f101fc (patch)
tree02df8baf050da52e22d9eb8ab55b45b0e242d87c /src/game/unit_soldier.cpp
parentf4fe2c7f10a8d2e253de27f1a540ca68184d5d29 (diff)
More improvements to shooting.
Diffstat (limited to 'src/game/unit_soldier.cpp')
-rw-r--r--src/game/unit_soldier.cpp57
1 files changed, 34 insertions, 23 deletions
diff --git a/src/game/unit_soldier.cpp b/src/game/unit_soldier.cpp
index 4cf840d..2131493 100644
--- a/src/game/unit_soldier.cpp
+++ b/src/game/unit_soldier.cpp
@@ -78,17 +78,39 @@ static v2f_t spread_aim(v2f_t x, v2f_t aim, float cof, procgen::prng_t *prng)
sin(dth) * tmp[0] + cos(dth) * tmp[1]);
}
-void unit_soldier_t::shoot(v2f_t aim)
+void unit_soldier_t::shoot(v2f_t from, v2f_t at, int damage)
{
- v2f_t end;
world::trace_t trace;
- v2f_t muzzle_point;
fx_tracer_t *tracer;
+
+ trace = world->ray_v_all_p3d(from, at, CF_SOLID|CF_BODY|CF_BODY_SMALL, -1, this);
+ if (trace.hit && trace.ent) {
+ entity_t *ent = dynamic_cast<entity_t*>(trace.ent);
+ ent->damage(damage, this);
+ }
+
+ tracer = new fx_tracer_t(game, from, at);
+ tracer->place(&game->world);
+
+ if (trace.hit && (!trace.ent || trace.ent->type == ET_UNIT)) {
+ fx_bullet_miss_t *bullet_miss;
+ bool water;
+
+ water = (trace.tile && trace.tile->type == TILE_WATER);
+ bullet_miss = new fx_bullet_miss_t(game, trace.end, water);
+ bullet_miss->place(&game->world);
+ }
+}
+
+void unit_soldier_t::fire_shotgun(v2f_t aim)
+{
+ v2f_t muzzle_point;
+ world::trace_t trace;
fx_flash_t *flash;
- end = spread_aim(x, aim, 0.1f, &game->prng);
+ muzzle_point = x + v2f_t(0, -0.7f);
- trace = world->ray_v_all_p3d(x, end, CF_SOLID|CF_BODY|CF_BODY_SMALL, -1, this);
+ trace = world->ray_v_all_p3d(x, aim, 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<unit_t*>(trace.ent);
@@ -98,31 +120,20 @@ void unit_soldier_t::shoot(v2f_t aim)
return;
}
- muzzle_point = x + v2f_t(0, -1.0f);
+ for (size_t i = 0; i < 5; i++) {
+ v2f_t end;
- tracer = new fx_tracer_t(game, muzzle_point, trace.end);
- tracer->place(&game->world);
+ end = spread_aim(muzzle_point, aim, 0.1f, &game->prng);
+ shoot(muzzle_point, end, 1);
+ }
flash = new fx_flash_t(game, muzzle_point, 5.0f, sf::Color(255, 170, 50, 80));
flash->place(&game->world);
-
last_attack = game->now;
-
assets::soldier.fire.play_3d(x);
-
- if (trace.hit && trace.ent) {
- entity_t *ent = dynamic_cast<entity_t*>(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)
{
unit_t *target;
@@ -155,7 +166,7 @@ skip_targetting:
if (last_attack + game->prng.next_float(1.4f, 1.6f) > game->now)
return;
- shoot(aim);
+ fire_shotgun(aim);
}
void unit_soldier_t::on_think(void)