summaryrefslogtreecommitdiff
path: root/src/game/units.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-12-14 22:16:48 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-12-14 22:16:48 +0100
commit47ac1b7868b8bfb3e5fe71395a34124bf9f7209a (patch)
tree4bb1361ac664a3267344f6cf8230621be9c6feed /src/game/units.cpp
parentb914d67b4e683c2d3e43c1854d6ef48b1878e4b6 (diff)
Improve combat.
Diffstat (limited to 'src/game/units.cpp')
-rw-r--r--src/game/units.cpp75
1 files changed, 41 insertions, 34 deletions
diff --git a/src/game/units.cpp b/src/game/units.cpp
index 2eb5dbe..d1648d7 100644
--- a/src/game/units.cpp
+++ b/src/game/units.cpp
@@ -103,7 +103,9 @@ bool unit_t::keep_moving(double speed)
next = *move.path.begin();
delta = next - x;
- move.angle = delta.angle();
+
+ if (delta.len() != 0.0f)
+ move.angle = delta.angle();
if (delta.len() >= time) {
x_new = x + delta * time / delta.len();
@@ -182,15 +184,15 @@ void unit_t::damage(int points, unit_t *attacker)
void unit_t::try_attack(unit_t *target)
{
std::stringstream ss;
- int hit_roll, hit_dc = 10 /* FIXME */;
- int dmg_roll, dmg_bonus, dmg_total;
+ size_t hit_roll;
+ size_t dmg_roll;
ss << name << " " << text::get(text::UNIT_ATTACK) << " " << target->name << ": ";
- hit_roll = roll(1, 20);
- ss << hit_roll << " vs " << hit_dc;
+ hit_roll = game->roll(&cs.hit_roll);
+ ss << hit_roll << " vs " << target->cs.armor_class;
- if (hit_roll == 1 || hit_roll < hit_dc) {
+ if (hit_roll == 1 || hit_roll < target->cs.armor_class) {
ss << " (" << text::get((hit_roll == 1 ? text::UNIT_CRITICAL_MISS : text::UNIT_MISS)) << ")";
game->interface->print(ss.str());
return;
@@ -199,16 +201,14 @@ void unit_t::try_attack(unit_t *target)
ss << " (" << text::get((hit_roll == 20 ? text::UNIT_CRITICAL_HIT : text::UNIT_HIT)) << ")";
game->interface->print(ss.str());
- dmg_roll = roll(2, 6);
- dmg_bonus = 2;
- dmg_total = dmg_roll + dmg_bonus;
+ dmg_roll = game->roll(&cs.damage_roll);
ss.str(std::string());
ss << name << " " << text::get(text::UNIT_DAMAGE) << " " << target->name << ": ";
- ss << dmg_roll << " + " << dmg_bonus << " = " << dmg_total;
+ ss << dmg_roll - cs.damage_roll.bonus << " + " << cs.damage_roll.bonus << " = " << dmg_roll;
game->interface->print(ss.str());
- target->damage(dmg_total, this);
+ target->damage(dmg_roll, this);
}
static unit_t *find_target(world::world_t *world, v2f_t x, float r,
@@ -255,6 +255,10 @@ human_t::human_t(game::state_t *game) : unit_t(game, UNIT_HUMAN)
render_size[0] = v2f_t(-0.5f, -1.0f);
render_size[1] = v2f_t(+0.5f, +0.5f);
name = text::get(text::UNIT_HUMAN);
+
+ cs.armor_class = 10;
+ cs.hit_roll = roll_params_t(20);
+ cs.damage_roll = roll_params_t(4);
}
void human_t::wake(unit_t *by_whom)
@@ -275,9 +279,14 @@ void human_t::think(void)
last_target_time = game->now;
last_target_x = target->x;
- if (last_attack + 0.5 < game->now) {
- last_attack = game->now;
- try_attack(target);
+ if (last_attack + 1.5 < game->now) {
+ world::trace_t trace;
+
+ trace = world->trace(x, target->x, CF_SOLID);
+ if (!trace.hit) {
+ last_attack = game->now;
+ try_attack(target);
+ }
}
//start_moving(target->x, CF_SOLID);
@@ -326,7 +335,7 @@ void human_t::render_to(render::state_t *render)
render->render(legs, render_bounds, move.angle);
render->render(body, render_bounds, body_angle);
- render->render(&assets::human.head_idle, render_bounds, move.angle);
+ render->render(&assets::human.head_idle, render_bounds, body_angle);
} else
render->render(&assets::human.dead, render_bounds);
@@ -353,12 +362,16 @@ alien_t::alien_t(game::state_t *game) : unit_t(game, UNIT_ALIEN)
render_size[0] = v2f_t(-0.3f, -0.3f);
render_size[1] = v2f_t(+0.3f, +0.3f);
name = text::get(text::UNIT_ALIEN);
+
+ cs.armor_class = 5;
+ cs.hit_roll = roll_params_t(20);
+ cs.damage_roll = roll_params_t(3, 6, 1);
}
void alien_t::wake(unit_t *by_whom)
{
start_moving(by_whom->x, CF_SOLID);
- next_targetting = game->now + 0.4;
+ next_targetting = game->now + 0.2;
}
void alien_t::sleep(void)
@@ -370,23 +383,6 @@ void alien_t::die(void)
render_layer = -1;
}
-void alien_t::attack(unit_t *target, float range)
-{
- world::trace_t trace;
-
- if (game->now < next_attack)
- return;
-
- if ((x - target->x).len() > range)
- return;
-
- trace = world->trace(x, target->x, CF_SOLID);
- if (!trace.hit)
- try_attack(target);
-
- next_attack = game->now + 1.0;
-}
-
void alien_t::think(void)
{
if (game->now > next_targetting) {
@@ -394,7 +390,18 @@ void alien_t::think(void)
target = find_target(world, x, 10.0f, UNIT_HUMAN);
if (target) {
- attack(target, 1.0f);
+ if (last_attack + 0.5 < game->now) {
+ world::trace_t trace;
+
+ if ((x - target->x).len() < 1.0f) {
+ trace = world->trace(x, target->x, CF_SOLID);
+ if (!trace.hit)
+ try_attack(target);
+
+ last_attack = game->now;
+ }
+ }
+
start_moving(target->x, CF_SOLID);
}