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.cpp114
1 files changed, 41 insertions, 73 deletions
diff --git a/src/game/units.cpp b/src/game/units.cpp
index 73e1cf0..8eb11c7 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -2,27 +2,9 @@
namespace game {
-world::cmodel_t unit_t::make_cmodel(v2f_t at)
-{
- world::cmodel_t cmodel;
-
- cmodel.bounds[0] = at + size[0];
- cmodel.bounds[1] = at + size[1];
- cmodel.cflags = cflags;
-
- return cmodel;
-}
-
-void unit_t::compute_bounds()
-{
- render_bounds[0] = x + render_size[0];
- render_bounds[1] = x + render_size[1];
-}
-
-unit_t::unit_t(game::state_t *game_, unit_t::type_t type_) : entity_t(ET_UNIT)
+unit_t::unit_t(game::state_t *game_, unit_t::type_t type_) : game::entity_t(game_, ET_UNIT)
{
type = type_;
- game = game_;
}
void unit_t::render_to(render::state_t *render)
@@ -78,18 +60,6 @@ void unit_t::say(std::string str)
game->interface->print(name + ": " + str);
}
-void unit_t::place(world::world_t *world_, v2f_t x_)
-{
- world = world_;
- x = x_;
- move.moving = false;
-
- unlink();
- cmodel = make_cmodel(x);
- compute_bounds();
- link(world);
-}
-
bool unit_t::keep_moving(double speed)
{
float time;
@@ -127,7 +97,8 @@ bool unit_t::keep_moving(double speed)
move.path.pop_front();
}
- cmodel_next = make_cmodel(x_new);
+ cmodel_next.bounds = size + x_new;
+ cmodel_next.cflags = cmodel.cflags;
if (!world->test_rect(&cmodel_next, this)) {
x = x_new;
cmodel = cmodel_next;
@@ -146,9 +117,7 @@ bool unit_t::keep_moving(double speed)
break;
}
- unlink();
- compute_bounds();
- link(world);
+ place(world, x);
return rv;
}
@@ -185,16 +154,20 @@ void unit_t::damage(int points, unit_t *attacker)
fx_blood_t *blood;
blood = new fx_blood_t(game, x, type == UNIT_ALIEN);
- game->add_effect(blood);
+ blood->place(&game->world);
health -= points;
- if (health < 0) {
- game->interface->print(name + " " + text::get(text::UNIT_DEATH) + ".");
- dead = true;
- death_time = game->now;
- cflags = 0;
- die();
- }
+ if (health < 0)
+ die(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;
+ on_death();
}
void unit_t::try_attack(unit_t *target)
@@ -266,7 +239,9 @@ static unit_t *find_target(world::world_t *world, v2f_t x, float r,
human_t::human_t(game::state_t *game) : unit_t(game, UNIT_HUMAN)
{
- cflags = CF_BODY;
+ always_awake = true;
+
+ cmodel.cflags = CF_BODY;
health = max_health = 20;
size[0] = v2f_t(-0.4f, -0.4f);
size[1] = v2f_t(+0.4f, +0.4f);
@@ -279,16 +254,13 @@ human_t::human_t(game::state_t *game) : unit_t(game, UNIT_HUMAN)
cs.damage_roll = roll_params_t(4);
}
-void human_t::wake(unit_t *by_whom)
+void human_t::on_think(void)
{
-}
+ if (dead)
+ return;
-void human_t::sleep(void)
-{
-}
+ game->wake_everything(x, 10);
-void human_t::think(void)
-{
if (game->now > next_targetting) {
unit_t *target;
@@ -304,7 +276,7 @@ void human_t::think(void)
trace = world->trace(x, target->x, CF_SOLID);
if (!trace.hit) {
tracer = new fx_tracer_t(game, x, target->x);
- game->add_effect(tracer);
+ tracer->place(&game->world);
last_attack = game->now;
try_attack(target);
@@ -321,15 +293,13 @@ void human_t::think(void)
say(text::get(text::SAY_BLOCKED));
}
-void human_t::die(void)
+void human_t::on_death(void)
{
render_size[0] = v2f_t(-0.75f, -0.5f);
render_size[1] = v2f_t(+0.75f, +0.5f);
render_layer = -1;
cmodel.cflags = CF_BACKGROUND;
- unlink();
- compute_bounds();
- link(world);
+ place(world, x);
}
void human_t::render_to(render::state_t *render)
@@ -367,7 +337,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_BODY_SMALL;
+ cmodel.cflags = CF_BODY_SMALL;
health = max_health = 4;
size[0] = v2f_t(-0.2f, -0.3f);
size[1] = v2f_t(+0.2f, +0.3f);
@@ -380,24 +350,11 @@ alien_t::alien_t(game::state_t *game) : unit_t(game, UNIT_ALIEN)
cs.damage_roll = roll_params_t(3, 6, 1);
}
-void alien_t::wake(unit_t *by_whom)
-{
- start_moving(by_whom->x, CF_SOLID | CF_WATER);
- next_targetting = game->now + 0.2;
-}
-
-void alien_t::sleep(void)
-{
-}
-
-void alien_t::die(void)
+void alien_t::on_think(void)
{
- render_layer = -1;
- cmodel.cflags = CF_BACKGROUND;
-}
+ if (dead)
+ return;
-void alien_t::think(void)
-{
if (game->now > next_targetting) {
unit_t *target;
@@ -424,6 +381,17 @@ void alien_t::think(void)
keep_moving(7.0);
}
+void alien_t::on_wake(void)
+{
+ next_targetting = game->now;
+}
+
+void alien_t::on_death(void)
+{
+ render_layer = -1;
+ cmodel.cflags = CF_BACKGROUND;
+}
+
void alien_t::render_to(render::state_t *render)
{
bool moving;