summaryrefslogtreecommitdiff
path: root/src/game/units.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/units.cpp')
-rw-r--r--src/game/units.cpp103
1 files changed, 89 insertions, 14 deletions
diff --git a/src/game/units.cpp b/src/game/units.cpp
index a1e233c..49ae050 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -164,9 +164,14 @@ void unit_t::damage(int points, unit_t *attacker)
void unit_t::die(unit_t *killer)
{
game->interface->print(name + " " + text::get(text::UNIT_DEATH) + ".");
+
dead = true;
death_time = game->now;
cmodel.cflags = 0;
+
+ sleep();
+ ignore_waking = true;
+
on_death();
}
@@ -203,7 +208,7 @@ void unit_t::try_attack(unit_t *target)
}
static unit_t *find_target(world::world_t *world, v2f_t x, float r,
- unit_t::type_t type)
+ bool friendly)
{
rectf_t rect;
float nearest_dist = INFINITY;
@@ -221,7 +226,7 @@ static unit_t *find_target(world::world_t *world, v2f_t x, float r,
unit = (unit_t*)ent;
- if (unit->type != type)
+ if (unit->friendly != friendly)
continue;
if (unit->dead)
@@ -247,26 +252,24 @@ unit_soldier_t::unit_soldier_t(game::state_t *game) : unit_t(game, UNIT_SOLDIER)
name = text::get(text::UNIT_NAME_SOLDIER);
- always_awake = true;
+ ignore_waking = true; // Always awake.
+ wake();
friendly = true;
controllable = true;
health = max_health = 20;
cs.armor_class = 10;
- cs.hit_die = die_t(4);
+ cs.hit_die = die_t(8);
}
void unit_soldier_t::on_think(void)
{
- if (dead)
- return;
-
game->wake_everything(x, 10);
if (game->now > next_targetting) {
unit_t *target;
- target = find_target(world, x, 10.0f, UNIT_SPIDER);
+ target = find_target(world, x, 10.0f, false);
if (target) {
last_target_time = game->now;
last_target_x = target->x;
@@ -348,19 +351,16 @@ unit_spider_t::unit_spider_t(game::state_t *game) : unit_t(game, UNIT_SPIDER)
name = text::get(text::UNIT_NAME_SPIDER);
health = max_health = 4;
- cs.armor_class = 5;
- cs.hit_die = die_t(3, 6, 1);
+ cs.armor_class = 15;
+ cs.hit_die = die_t(3, 6);
}
void unit_spider_t::on_think(void)
{
- if (dead)
- return;
-
if (game->now > next_targetting) {
unit_t *target;
- target = find_target(world, x, 10.0f, UNIT_SOLDIER);
+ target = find_target(world, x, 10.0f, true);
if (target) {
if (last_attack + 0.5 < game->now) {
world::trace_t trace;
@@ -381,6 +381,9 @@ void unit_spider_t::on_think(void)
}
keep_moving(7.0);
+
+ if (!move.moving && wake_time + 5 > game->now)
+ sleep();
}
void unit_spider_t::on_wake(void)
@@ -409,4 +412,76 @@ void unit_spider_t::render_to(render::state_t *render)
unit_t::render_to(render);
}
+unit_nest_t::unit_nest_t(game::state_t *game_) : unit_t(game_, UNIT_NEST)
+{
+ size[0] = {-0.6f, +0.2f};
+ size[1] = {+0.6f, +0.6f};
+ render_size[0] = {-0.6f, -0.6f};
+ render_size[1] = {+0.6f, +0.6f};
+ cmodel.cflags = CF_BACKGROUND;
+
+ name = text::get(text::UNIT_NAME_NEST);
+
+ health = max_health = 45;
+ cs.armor_class = 5;
+
+ next_spawning = game->now + 5.0;
+}
+
+void spawn_spider(game::state_t *game, v2f_t nest)
+{
+ for (size_t i = 0; i < 5; i++) { // Try a few times before giving up.
+ v2f_t offset, x;
+ world::cmodel_t cmodel;
+ unit_spider_t *spider;
+
+ offset = game->dice_prng.unit_vec2();
+ x = nest + offset * (game->dice_prng.next_float() * 0.2 + 0.4);
+
+ cmodel.bounds = rectf_t(v2f_t(-0.5f, -0.5f), v2f_t(0.5f, 0.5f)) + x;
+ cmodel.cflags = CF_BODY_SMALL;
+ if (game->world.test_rect(&cmodel, NULL))
+ continue;
+
+ spider = new unit_spider_t(game);
+ spider->place(&game->world, x);
+ return;
+ }
+}
+
+void unit_nest_t::on_think(void)
+{
+ if (wake_time + 30 > game->now)
+ sleep();
+
+ if (next_spawning > game->now)
+ return;
+
+ spawn_spider(game, x);
+ next_spawning = game->now + game->dice_prng.next_float() * 10 + 5;
+}
+
+void unit_nest_t::on_spawn(void)
+{
+ spawn_spider(game, x);
+ spawn_spider(game, x);
+ spawn_spider(game, x);
+}
+
+void unit_nest_t::on_death(void)
+{
+ render_layer = -1;
+ cmodel.cflags = CF_BACKGROUND;
+}
+
+void unit_nest_t::render_to(render::state_t *render)
+{
+ if (!dead)
+ render->render(game->now, &assets::nest.idle, render_bounds);
+ else
+ render->render(game->now, &assets::nest.dead, render_bounds);
+
+ unit_t::render_to(render);
+}
+
} // namespace game