diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-04-12 23:17:02 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-04-12 23:17:02 +0200 |
commit | 545b0a1e0870aaf5032d8b2b96dcfc13ae97126f (patch) | |
tree | 11ab528d70030e3b89a6b84b09de7ff202c83b28 /src | |
parent | f274f281da32c829e20c5012d67431d6a4348cce (diff) |
Misc. gameplay improvements.
Diffstat (limited to 'src')
-rw-r--r-- | src/common.hpp | 2 | ||||
-rw-r--r-- | src/game/game.cpp | 9 | ||||
-rw-r--r-- | src/game/game.hpp | 3 | ||||
-rw-r--r-- | src/game/unit_nest.cpp | 2 | ||||
-rw-r--r-- | src/game/unit_spider.cpp | 6 | ||||
-rw-r--r-- | src/game/units.cpp | 12 |
6 files changed, 25 insertions, 9 deletions
diff --git a/src/common.hpp b/src/common.hpp index bb95f0e..3d7483d 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -40,6 +40,8 @@ extern bool debug_AI; typedef uint64_t ntime_t; ntime_t nclock(void); +#define MSEC(x) ((ntime_t)x * 1000000) + class freq_counter_t { ntime_t *samples; size_t num_samples, collected = 0; diff --git a/src/game/game.cpp b/src/game/game.cpp index 4cac4eb..66bf237 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -247,14 +247,9 @@ static void command_repl(unit_repl_t *repl, v2f_t x, int number) void state_t::command(v2f_t x, int number) { - v2f_t snap; - if (!selected_units.size()) return; - snap[0] = std::round(x[0] - 0.5f) + 0.5f; - snap[1] = std::round(x[1] - 0.5f) + 0.5f; - for (unit_t *unit : selected_units) { if (unit->dead || !unit->controllable) continue; @@ -262,12 +257,12 @@ void state_t::command(v2f_t x, int number) switch (unit->type) { case unit_t::UNIT_SOLDIER: command_soldier(dynamic_cast<unit_soldier_t*>(unit), - snap, number); + x, number); break; case unit_t::UNIT_REPL: command_repl(dynamic_cast<unit_repl_t*>(unit), - snap, number); + x, number); break; default:; diff --git a/src/game/game.hpp b/src/game/game.hpp index 321fc0c..4773f9c 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -197,11 +197,14 @@ namespace game { float next_attempt; v2f_t last_step; + + ntime_t random_walk_time = 0; } move; bool keep_moving(double speed); bool start_moving(v2f_t dst); void stop_moving(void); + void random_walk(void); bool dead = false; double death_time = -INFINITY; diff --git a/src/game/unit_nest.cpp b/src/game/unit_nest.cpp index ffa551b..30db39f 100644 --- a/src/game/unit_nest.cpp +++ b/src/game/unit_nest.cpp @@ -26,7 +26,7 @@ unit_nest_t::unit_nest_t(game::state_t *game_) : unit_t(game_, UNIT_NEST) size[1] = {+0.6f, +0.6f}; render_size[0] = {-0.6f, -0.6f}; render_size[1] = {+0.6f, +0.6f}; - cmodel.cflags = CF_BACKGROUND; + cmodel.cflags = CF_BODY; name = text::get(text::UNIT_NAME_NEST); diff --git a/src/game/unit_spider.cpp b/src/game/unit_spider.cpp index fd69305..9ff8fc1 100644 --- a/src/game/unit_spider.cpp +++ b/src/game/unit_spider.cpp @@ -44,8 +44,12 @@ void unit_spider_t::target_and_attack(void) return; target = find_target(world, x, 10.0f, true); - if (!target) + if (!target) { + if (health < max_health) + random_walk(); + return; + } start_moving(target->x); next_targetting = game->now + game->prng.next_float(0.2f, 0.4f); diff --git a/src/game/units.cpp b/src/game/units.cpp index f777400..fb0ce3c 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -209,6 +209,8 @@ void unit_t::damage(int points, unit_t *attacker) health -= points; if (health <= 0) die(attacker); + else + wake(); } void unit_t::die(unit_t *killer) @@ -261,4 +263,14 @@ unit_t *find_target(world::world_t *world, v2f_t x, float r, return nearest; } +void unit_t::random_walk(void) +{ + if (move.random_walk_time && + game->time - move.random_walk_time < MSEC(1000)) + return; + + start_moving(x + game->prng.unit_vec2() * 10); + move.random_walk_time = game->time; +} + } // namespace game |