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.cpp75
1 files changed, 38 insertions, 37 deletions
diff --git a/src/game/units.cpp b/src/game/units.cpp
index b4cb333..5563124 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -19,9 +19,10 @@ void unit_t::compute_bounds()
render_bounds[1] = x + render_size[1];
}
-unit_t::unit_t(unit_t::type_t type_) : entity_t(ET_UNIT)
+unit_t::unit_t(game::state_t *game_, unit_t::type_t type_) : entity_t(ET_UNIT)
{
type = type_;
+ game = game_;
}
void unit_t::render_to(render::state_t *render)
@@ -59,10 +60,10 @@ void unit_t::render_to(render::state_t *render)
render->debug_path(&move.path);
}
-void unit_t::say(const wchar_t *wstr, double now)
+void unit_t::say(const wchar_t *wstr)
{
say_text = wstr;
- say_time = now;
+ say_time = game->now;
std::cout << (void*)this << ": " << wstr << "\n";
}
@@ -78,17 +79,17 @@ void unit_t::place(world::world_t *world_, v2f_t x_)
link(world);
}
-bool unit_t::keep_moving(double now, double dt, double speed)
+bool unit_t::keep_moving(double speed)
{
float time;
if (!move.moving)
return false;
- if (move.blocked && now < move.next_attempt)
+ if (move.blocked && game->now < move.next_attempt)
return false;
- time = dt * speed;
+ time = game->dt * speed;
while (time > 0.0f) {
v2f_t delta, next, x_new;
@@ -122,10 +123,10 @@ bool unit_t::keep_moving(double now, double dt, double speed)
if (move.attempts_left) {
move.blocked = true;
move.attempts_left--;
- move.next_attempt = now + 0.2f;
+ move.next_attempt = game->now + 0.2f;
} else {
if ((x - move.dst).len() > 1.5f)
- say(text::unit_blocked, now);
+ say(text::unit_blocked);
move.moving = false;
}
break;
@@ -137,18 +138,18 @@ bool unit_t::keep_moving(double now, double dt, double speed)
return true;
}
-bool unit_t::start_moving(v2f_t dst_, double now)
+bool unit_t::start_moving(v2f_t dst)
{
if (!world) {
printf("unit_t::start_moving: entity is not linked\n");
return false;
}
- move.dst = dst_;
+ move.dst = dst;
move.path.clear();
if (!world->find_path(x, move.dst, &cmodel, this, &move.path)) {
- say(text::unit_no_path, now);
+ say(text::unit_no_path);
move.moving = false;
return false;
}
@@ -162,19 +163,19 @@ bool unit_t::start_moving(v2f_t dst_, double now)
return true;
}
-void unit_t::damage(double now, int points)
+void unit_t::damage(int points)
{
health -= points;
if (health < 0) {
printf("%p died\n", this);
dead = true;
- death_time = now;
+ death_time = game->now;
cflags = 0;
- die(now);
+ die();
}
}
-human_t::human_t() : unit_t(UNIT_HUMAN)
+human_t::human_t(game::state_t *game) : unit_t(game, UNIT_HUMAN)
{
cflags = CF_HUMAN;
health = max_health = 20;
@@ -185,20 +186,20 @@ human_t::human_t() : unit_t(UNIT_HUMAN)
render_layer = -1;
}
-void human_t::wake(double now, unit_t *by_whom)
+void human_t::wake(unit_t *by_whom)
{
}
-void human_t::sleep(double now)
+void human_t::sleep(void)
{
}
-void human_t::think(double now, double dt)
+void human_t::think(void)
{
- keep_moving(now, dt, 4.0);
+ keep_moving(4.0);
}
-void human_t::die(double now)
+void human_t::die(void)
{
render_size[0] = v2f_t(-0.75f, -0.5f);
render_size[1] = v2f_t(+0.75f, +0.5f);
@@ -221,7 +222,7 @@ void human_t::render_to(render::state_t *render)
} else
render->render(&assets::human.dead, render_bounds);
- if (say_time + 5.0 > render->now) {
+ if (say_time + 5.0 > game->now) {
v2f_t text_pos;
float height;
@@ -235,7 +236,7 @@ void human_t::render_to(render::state_t *render)
unit_t::render_to(render);
}
-alien_t::alien_t() : unit_t(UNIT_ALIEN)
+alien_t::alien_t(game::state_t *game) : unit_t(game, UNIT_ALIEN)
{
cflags = CF_SOLID;
health = max_health = 4;
@@ -245,17 +246,17 @@ alien_t::alien_t() : unit_t(UNIT_ALIEN)
render_size[1] = v2f_t(+0.3f, +0.3f);
}
-void alien_t::wake(double now, unit_t *by_whom)
+void alien_t::wake(unit_t *by_whom)
{
- start_moving(by_whom->x, now);
- next_targetting = now + 0.4;
+ start_moving(by_whom->x);
+ next_targetting = game->now + 0.4;
}
-void alien_t::sleep(double now)
+void alien_t::sleep(void)
{
}
-void alien_t::die(double now)
+void alien_t::die(void)
{
}
@@ -295,11 +296,11 @@ static unit_t *find_target(world::world_t *world, v2f_t x, float r,
return nearest;
}
-void alien_t::attack(double now, unit_t *target, float range)
+void alien_t::attack(unit_t *target, float range)
{
world::trace_t trace;
- if (now < next_attack)
+ if (game->now < next_attack)
return;
if ((x - target->x).len() > range)
@@ -307,26 +308,26 @@ void alien_t::attack(double now, unit_t *target, float range)
trace = world->trace(x, target->x, CF_SOLID);
if (!trace.hit)
- target->damage(now, rand() % 6 + rand() % 6 + 2);
+ target->damage(rand() % 6 + rand() % 6 + 2);
- next_attack = now + 0.4;
+ next_attack = game->now + 0.4;
}
-void alien_t::think(double now, double dt)
+void alien_t::think(void)
{
- if (now > next_targetting) {
+ if (game->now > next_targetting) {
unit_t *target;
target = find_target(world, x, 5.0f, UNIT_HUMAN);
if (target) {
- attack(now, target, 0.75f);
- start_moving(target->x, now);
+ attack(target, 0.75f);
+ start_moving(target->x);
}
- next_targetting = now + 0.2;
+ next_targetting = game->now + 0.2;
}
- keep_moving(now, dt, 7.0);
+ keep_moving(7.0);
}
void alien_t::render_to(render::state_t *render)