diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-12-16 20:37:10 +0000 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-16 20:37:10 +0000 |
commit | 1b1704512b4c83dfa7e17c30f0facc5a7645181a (patch) | |
tree | f843823210be5dda636d2ba3f5149ba9f54cd876 /src/game | |
parent | 273c601a94464bef2161b9c3a29ea3cf901340e9 (diff) |
Clean up unit parameters a bit.
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/game.cpp | 14 | ||||
-rw-r--r-- | src/game/game.hpp | 3 | ||||
-rw-r--r-- | src/game/units.cpp | 32 |
3 files changed, 24 insertions, 25 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp index 51dca09..9584817 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -178,32 +178,32 @@ void state_t::wake_everything(v2f_t x, float range) } } -roll_params_t::roll_params_t(size_t sides_) +die_t::die_t(size_t sides_) { sides = sides_; } -roll_params_t::roll_params_t(size_t count_, size_t sides_) +die_t::die_t(size_t count_, size_t sides_) { count = count_; sides = sides_; } -roll_params_t::roll_params_t(size_t count_, size_t sides_, size_t bonus_) +die_t::die_t(size_t count_, size_t sides_, size_t bonus_) { count = count_; sides = sides_; bonus = bonus_; } -size_t state_t::roll(roll_params_t *P) +size_t state_t::roll(die_t die) { size_t total = 0; - for (size_t i = 0; i < P->count; i++) - total += dice_prng.next() % P->sides + 1; + for (size_t i = 0; i < die.count; i++) + total += dice_prng.next() % die.sides + 1; - return total + P->bonus; + return total + die.bonus; } bool load_assets(void) diff --git a/src/game/game.hpp b/src/game/game.hpp index df027ce..3fed3ec 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -117,8 +117,7 @@ namespace game { struct { size_t armor_class; - roll_params_t hit_roll; - roll_params_t damage_roll; + die_t hit_die; } cs; bool dead = false; diff --git a/src/game/units.cpp b/src/game/units.cpp index ee6ee9f..a1e233c 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -178,7 +178,7 @@ void unit_t::try_attack(unit_t *target) ss << name << " " << text::get(text::UNIT_ATTACK) << " " << target->name << ": "; - hit_roll = game->roll(&cs.hit_roll); + hit_roll = game->roll(die_t(20)); ss << hit_roll << " vs " << target->cs.armor_class; if (hit_roll == 1 || hit_roll < target->cs.armor_class) { @@ -187,14 +187,14 @@ void unit_t::try_attack(unit_t *target) return; } - dmg_roll = game->roll(&cs.damage_roll); + dmg_roll = game->roll(cs.hit_die); if (hit_roll < 20) { ss << ", " << text::get(text::UNIT_DAMAGE) << ": "; - ss << dmg_roll - cs.damage_roll.bonus << " + " << cs.damage_roll.bonus << " = " << dmg_roll; + ss << dmg_roll - cs.hit_die.bonus << " + " << cs.hit_die.bonus << " = " << dmg_roll; } else { ss << " (" << text::get(text::UNIT_CRITICAL_HIT) << ")" << ", " << text::get(text::UNIT_DAMAGE) << ": "; - ss << "(" << dmg_roll - cs.damage_roll.bonus << " + " << cs.damage_roll.bonus << ") x 2 = " << dmg_roll * 2; + ss << "(" << dmg_roll - cs.hit_die.bonus << " + " << cs.hit_die.bonus << ") x 2 = " << dmg_roll * 2; dmg_roll *= 2; } @@ -239,21 +239,21 @@ static unit_t *find_target(world::world_t *world, v2f_t x, float r, unit_soldier_t::unit_soldier_t(game::state_t *game) : unit_t(game, UNIT_SOLDIER) { - always_awake = true; - friendly = true; - controllable = 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); render_size[0] = v2f_t(-0.5f, -1.0f); render_size[1] = v2f_t(+0.5f, +0.5f); + cmodel.cflags = CF_BODY; + name = text::get(text::UNIT_NAME_SOLDIER); + always_awake = true; + friendly = true; + controllable = true; + + health = max_health = 20; cs.armor_class = 10; - cs.hit_roll = roll_params_t(20); - cs.damage_roll = roll_params_t(4); + cs.hit_die = die_t(4); } void unit_soldier_t::on_think(void) @@ -339,17 +339,17 @@ void unit_soldier_t::render_to(render::state_t *render) unit_spider_t::unit_spider_t(game::state_t *game) : unit_t(game, UNIT_SPIDER) { - 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); render_size[0] = v2f_t(-0.3f, -0.3f); render_size[1] = v2f_t(+0.3f, +0.3f); + cmodel.cflags = CF_BODY_SMALL; + name = text::get(text::UNIT_NAME_SPIDER); + health = max_health = 4; cs.armor_class = 5; - cs.hit_roll = roll_params_t(20); - cs.damage_roll = roll_params_t(3, 6, 1); + cs.hit_die = die_t(3, 6, 1); } void unit_spider_t::on_think(void) |