diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-12-14 17:13:36 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-14 17:23:35 +0100 |
commit | 36a95838d17ffaee4020a2aba832af6636591df4 (patch) | |
tree | 8853eb8623970201d009a4a4637e5451c9103f8c | |
parent | d376eb30b8363f712e3a0bbc04ea584547c09e65 (diff) |
Rework collision masks and improve AI.
-rw-r--r-- | src/game/assets.cpp | 2 | ||||
-rw-r--r-- | src/game/game.cpp | 2 | ||||
-rw-r--r-- | src/game/game.hpp | 8 | ||||
-rw-r--r-- | src/game/units.cpp | 23 | ||||
-rw-r--r-- | src/text.cpp | 5 | ||||
-rw-r--r-- | src/world.cpp | 3 |
6 files changed, 25 insertions, 18 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp index 2a91a96..1034f92 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -17,7 +17,7 @@ void load(void) alien.walking.load("assets/units/alien/walking", 2, 2, 2); world::register_tile(TILE_DIRT, 0); - world::register_tile(TILE_WALL, CF_SOLID | CF_HUMAN); + world::register_tile(TILE_WALL, CF_SOLID); render::register_tile(TILE_DIRT, "assets/tiles/dirt.png"); render::register_tile(TILE_WALL, "assets/tiles/wall.png"); } diff --git a/src/game/game.cpp b/src/game/game.cpp index 836b304..826f9e5 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -75,7 +75,7 @@ void state_t::command(v2f_t x) if (unit->dead) continue; - if (!unit->start_moving(snap)) + if (!unit->start_moving(snap, CF_SOLID)) unit->say(text::get(text::SAY_NO_PATH)); else unit->say(text::get(text::SAY_MOVING)); diff --git a/src/game/game.hpp b/src/game/game.hpp index 55e3c45..fdb2348 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -12,9 +12,9 @@ namespace game { }; enum { - CF_NONE = 0, - CF_SOLID = 1, - CF_HUMAN = 2 + CF_SOLID = 1, + CF_BODY = 2, + CF_BODY_SMALL = 4 }; extern size_t selection_cookie; @@ -79,7 +79,7 @@ namespace game { void place(world::world_t *world_, v2f_t x_); bool keep_moving(double speed); - bool start_moving(v2f_t dst); + bool start_moving(v2f_t dst, world::cflags_t cflags); bool awake = false; double wake_time = -INFINITY; diff --git a/src/game/units.cpp b/src/game/units.cpp index 5efab65..672e73f 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -139,8 +139,10 @@ bool unit_t::keep_moving(double speed) return rv; } -bool unit_t::start_moving(v2f_t dst) +bool unit_t::start_moving(v2f_t dst, world::cflags_t cflags) { + world::cmodel_t rep; + if (!world) { printf("unit_t::start_moving: entity is not linked\n"); return false; @@ -149,7 +151,10 @@ bool unit_t::start_moving(v2f_t dst) move.dst = dst; move.path.clear(); - if (!world->find_path(x, move.dst, &cmodel, this, &move.path)) { + rep.cflags = cflags; + rep.bounds = cmodel.bounds; + + if (!world->find_path(x, move.dst, &rep, this, &move.path)) { move.moving = false; return false; } @@ -166,7 +171,7 @@ void unit_t::damage(int points, unit_t *attacker) { health -= points; if (health < 0) { - game->interface->print(name + ": " + text::get(text::UNIT_DEATH) + "."); + game->interface->print(name + " " + text::get(text::UNIT_DEATH) + "."); dead = true; death_time = game->now; cflags = 0; @@ -208,7 +213,7 @@ void unit_t::try_attack(unit_t *target) human_t::human_t(game::state_t *game) : unit_t(game, UNIT_HUMAN) { - cflags = CF_HUMAN; + cflags = CF_BODY; health = max_health = 20; size[0] = v2f_t(-0.4f, -0.4f); size[1] = v2f_t(+0.4f, +0.4f); @@ -271,7 +276,7 @@ void human_t::render_to(render::state_t *render) alien_t::alien_t(game::state_t *game) : unit_t(game, UNIT_ALIEN) { - cflags = CF_SOLID; + cflags = CF_BODY_SMALL; health = max_health = 4; size[0] = v2f_t(-0.2f, -0.2f); size[1] = v2f_t(+0.2f, +0.2f); @@ -282,7 +287,7 @@ alien_t::alien_t(game::state_t *game) : unit_t(game, UNIT_ALIEN) void alien_t::wake(unit_t *by_whom) { - start_moving(by_whom->x); + start_moving(by_whom->x, CF_SOLID); next_targetting = game->now + 0.4; } @@ -351,10 +356,10 @@ void alien_t::think(void) if (game->now > next_targetting) { unit_t *target; - target = find_target(world, x, 5.0f, UNIT_HUMAN); + target = find_target(world, x, 10.0f, UNIT_HUMAN); if (target) { - attack(target, 0.75f); - start_moving(target->x); + attack(target, 1.0f); + start_moving(target->x, CF_SOLID); } next_targetting = game->now + 0.2; diff --git a/src/text.cpp b/src/text.cpp index 3c89610..ad8f007 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -4,8 +4,7 @@ namespace text { language_t language = LANG_ENGLISH; -static const char *human_names[] = -{ +static const char *human_names[] = { "Kowalski", "Jackson", "Carter", "O'Neill", "Hammond", "Mitchell" }; @@ -33,7 +32,7 @@ static std::string get_english(index_t index) return human_names[rand() % count(human_names)]; case UNIT_DEATH: - return "Death"; + return "died"; case UNIT_ATTACK: return "attacks"; diff --git a/src/world.cpp b/src/world.cpp index 71a7ae7..8a7720c 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -106,6 +106,9 @@ bool world_t::find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore if (ent == ignore) continue; + if (!(ent->cmodel.cflags & cmodel->cflags)) + continue; + center = ent->cmodel.bounds.center(); combined_dims = ent->cmodel.bounds.dims() + cmodel_dims; combined[0] = center - combined_dims / 2; |