summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/game.hpp4
-rw-r--r--src/game/units.cpp96
2 files changed, 59 insertions, 41 deletions
diff --git a/src/game/game.hpp b/src/game/game.hpp
index e2ac514..7b0674c 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -178,6 +178,8 @@ namespace game {
~unit_soldier_t(void) {};
void render_to(render::state_t *render);
+ void target_and_attack(void);
+
void on_think(void);
void on_spawn(void) {};
void on_wake(void) {};
@@ -190,6 +192,8 @@ namespace game {
~unit_spider_t(void) {};
void render_to(render::state_t *render);
+ void target_and_attack(void);
+
void on_think(void);
void on_spawn(void) {};
void on_wake(void);
diff --git a/src/game/units.cpp b/src/game/units.cpp
index 4ef03ee..cbc3f1a 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -283,37 +283,43 @@ unit_soldier_t::unit_soldier_t(game::state_t *game) : unit_t(game, UNIT_SOLDIER)
cs.hit_die = die_t(8);
}
-void unit_soldier_t::on_think(void)
+void unit_soldier_t::target_and_attack(void)
{
- game->wake_everything(x, 10);
+ unit_t *target;
+ world::trace_t trace;
+ fx_tracer_t *tracer;
- if (game->now > next_targetting) {
- unit_t *target;
+ if (game->now < next_targetting)
+ return;
- target = find_target(world, x, 10.0f, false);
- if (target) {
- last_target_time = game->now;
- last_target_x = target->x;
+ next_targetting = game->now + 0.2;
- if (last_attack + 1.5 < game->now) {
- world::trace_t trace;
- fx_tracer_t *tracer;
+ target = find_target(world, x, 10.0f, false);
+ if (!target)
+ return;
- trace = world->trace(x, target->x, CF_SOLID);
- if (!trace.hit) {
- tracer = new fx_tracer_t(game, x, target->x);
- tracer->place(&game->world);
+ last_target_time = game->now;
+ last_target_x = target->x;
- last_attack = game->now;
- try_attack(target);
- }
- }
+ if (last_attack + 1.5 > game->now)
+ return;
- //start_moving(target->x, CF_SOLID);
- }
+ trace = world->trace(x, target->x, CF_SOLID);
+ if (trace.hit)
+ return;
- next_targetting = game->now + 0.2;
- }
+ tracer = new fx_tracer_t(game, x, target->x);
+ tracer->place(&game->world);
+
+ last_attack = game->now;
+ try_attack(target);
+}
+
+void unit_soldier_t::on_think(void)
+{
+ game->wake_everything(x, 10);
+
+ target_and_attack();
if (!keep_moving(4.0))
say(text::get(text::SAY_BLOCKED));
@@ -376,30 +382,38 @@ unit_spider_t::unit_spider_t(game::state_t *game) : unit_t(game, UNIT_SPIDER)
cs.hit_die = die_t(3, 6);
}
-void unit_spider_t::on_think(void)
+void unit_spider_t::target_and_attack(void)
{
- if (game->now > next_targetting) {
- unit_t *target;
+ unit_t *target;
+ world::trace_t trace;
- target = find_target(world, x, 10.0f, true);
- if (target) {
- if (last_attack + 0.5 < game->now) {
- world::trace_t trace;
+ if (game->now < next_targetting)
+ return;
- if ((x - target->x).len() < 1.0f) {
- trace = world->trace(x, target->x, CF_SOLID);
- if (!trace.hit)
- try_attack(target);
+ target = find_target(world, x, 10.0f, true);
+ if (!target)
+ return;
- last_attack = game->now;
- }
- }
+ start_moving(target->x, CF_SOLID | CF_WATER);
+ next_targetting = game->now + 0.2;
- start_moving(target->x, CF_SOLID | CF_WATER);
- }
+ if (last_attack + 0.5 > game->now)
+ return;
- next_targetting = game->now + 0.2;
- }
+ if ((x - target->x).len() >= 1.0f)
+ return;
+
+ trace = world->trace(x, target->x, CF_SOLID);
+ if (trace.hit)
+ return;
+
+ try_attack(target);
+ last_attack = game->now;
+}
+
+void unit_spider_t::on_think(void)
+{
+ target_and_attack();
keep_moving(7.0);