dragon generation breaking the game
seed validation wrong
This commit is contained in:
2024-07-16 23:00:10 -04:00
parent ea3164ae07
commit 3b164bbe9f
9 changed files with 65 additions and 60 deletions

View File

@ -117,9 +117,8 @@ feature proc_args(int argc, char **argv,
if (result & FEATURE_SEED) { if (result & FEATURE_SEED) {
std::istringstream iss {seed}; std::istringstream iss {seed};
unsigned int tmp; unsigned int tmp;
iss >> tmp;
if (!iss.good()) if (!(iss >> tmp))
return FEATURE_PANIC_SEED; return FEATURE_PANIC_SEED;
rng = std::make_unique<RNG>(tmp); rng = std::make_unique<RNG>(tmp);

View File

@ -9,17 +9,18 @@
#include "enemies/merchant.h" #include "enemies/merchant.h"
#include "enemies/orc.h" #include "enemies/orc.h"
void new_dragon(RNG *rng, std::unique_ptr<enemy_base> &p, std::unique_ptr<enemy_base> new_dragon(RNG *rng, const position &pos,
const position &pos, const position &fallback, const position &fallback,
const feature enabled_features, int which_room) { const feature enabled_features,
int which_room) {
const position nil{0, 0}; const position nil{0, 0};
if (pos != nil) if (pos != nil)
p = std::make_unique<dragon>(rng, enabled_features, return std::make_unique<dragon>(rng, enabled_features,
pos, which_room); pos, which_room);
else else
p = std::make_unique<dragon>(rng, enabled_features, return std::make_unique<dragon>(rng, enabled_features,
fallback, which_room); fallback, which_room);
} }
const int EXCNT = 6; const int EXCNT = 6;
@ -44,9 +45,9 @@ enum race get_normal_race(RNG *rng) {
return CHOICES[rng->rand_under(CNT)]; return CHOICES[rng->rand_under(CNT)];
} }
void new_enemy(RNG *rng, std::unique_ptr<enemy_base> &p, std::unique_ptr<enemy_base> new_enemy(RNG *rng, const position &pos,
const position &pos, const feature enabled_features, const feature enabled_features,
int which_room) { int which_room) {
using std::make_unique; using std::make_unique;
enum race r; enum race r;
@ -56,34 +57,40 @@ void new_enemy(RNG *rng, std::unique_ptr<enemy_base> &p,
else else
r = get_normal_race(rng); r = get_normal_race(rng);
p = nullptr;
switch (r) { switch (r) {
case rdwarf: case rdwarf:
p = make_unique<dwarf>(rng, enabled_features, pos, which_room); return make_unique<dwarf>(rng, enabled_features,
pos, which_room);
break; break;
case rhuman: case rhuman:
p = make_unique<human>(rng, enabled_features, pos, which_room); return make_unique<human>(rng, enabled_features,
pos, which_room);
break; break;
case relf: case relf:
p = make_unique<elf>(rng, enabled_features, pos, which_room); return make_unique<elf>(rng, enabled_features,
pos, which_room);
break; break;
case rorc: case rorc:
p = make_unique<orc>(rng, enabled_features, pos, which_room); return make_unique<orc>(rng, enabled_features,
pos, which_room);
break; break;
case rmerchant: case rmerchant:
p = make_unique<merchant>(rng, enabled_features, pos, which_room); return make_unique<merchant>(rng, enabled_features,
pos, which_room);
break; break;
case rhalfling: case rhalfling:
p = make_unique<halfling>(rng, enabled_features, pos, which_room); return make_unique<halfling>(rng, enabled_features,
pos, which_room);
break; break;
default: default:
break; break;
} }
return nullptr;
} }

View File

@ -4,12 +4,13 @@
#include <memory> #include <memory>
#include "enemy.h" #include "enemy.h"
void new_dragon(RNG *rng, std::unique_ptr<enemy_base> &p, std::unique_ptr<enemy_base> new_dragon(RNG *rng, const position &pos,
const position &pos, const position &fallback, const position &fallback,
const feature enabled_features, int which_room); const feature enabled_features,
int which_room);
void new_enemy(RNG *rng, std::unique_ptr<enemy_base> &p, std::unique_ptr<enemy_base> new_enemy(RNG *rng, const position &pos,
const position &pos, const feature enabled_features, const feature enabled_features,
int which_room); int which_room);
#endif #endif

View File

@ -15,7 +15,7 @@ game::game(const enum race starting_race,
the_world = false; the_world = false;
// TODO: add the other races // TODO: add the other races
init_player(rng, player, enabled_features, starting_race); player = init_player(rng, enabled_features, starting_race);
if (enabled_features & FEATURE_EXTRA_LEVELS) if (enabled_features & FEATURE_EXTRA_LEVELS)
max_level = rng->rand_between(MIN_LEVEL_CNT, MAX_LEVEL_CNT + 1); max_level = rng->rand_between(MIN_LEVEL_CNT, MAX_LEVEL_CNT + 1);

View File

@ -72,11 +72,11 @@ void level::gen_enemies(RNG *rng, std::vector<position_list> &tiles) {
spots.push_back(dhoard[i].pos + MOVE[i]); spots.push_back(dhoard[i].pos + MOVE[i]);
} }
pelist.push_back(nullptr); auto pos = spots.size() ? rng->get_rand_in_vector(spots) :
auto pos = rng->get_rand_in_vector(spots); dhoard[i].pos;
new_dragon(rng, pelist[i], pos, pelist.push_back(new_dragon(rng, pos, dhoard[i].pos,
dhoard[i].pos, enabled_features, enabled_features,
map.which_room(dhoard[i].pos)); map.which_room(dhoard[i].pos)));
int room = map.which_room(pos); int room = map.which_room(pos);
remove_from_list(tiles[room], pos); remove_from_list(tiles[room], pos);
@ -88,9 +88,9 @@ void level::gen_enemies(RNG *rng, std::vector<position_list> &tiles) {
for (int i = dhoard.size(); i < cnt; ++i) { for (int i = dhoard.size(); i < cnt; ++i) {
pelist.push_back(nullptr);
auto p = get_rand_pos(rng, tiles); auto p = get_rand_pos(rng, tiles);
new_enemy(rng, pelist[i], p, enabled_features, map.which_room(p)); pelist.push_back(new_enemy(rng, p, enabled_features,
map.which_room(p)));
elist.push_back(pelist[i].get()); elist.push_back(pelist[i].get());
} }
} }
@ -136,10 +136,8 @@ void level::gen_potions(RNG *rng, std::vector<position_list> &tiles) {
pplist.reserve(cnt); pplist.reserve(cnt);
for (int i = 0; i < cnt; ++i) { for (int i = 0; i < cnt; ++i) {
pplist.push_back(nullptr); pplist.push_back(new_potion((potion_type)rng->rand_under(max_type),
new_potion(pplist[i], get_rand_pos(rng, tiles)));
(potion_type)rng->rand_under(max_type),
get_rand_pos(rng, tiles));
plist.push_back(pplist[i].get()); plist.push_back(pplist[i].get());
} }
} }

View File

@ -8,38 +8,38 @@
#include "player/vampire.h" #include "player/vampire.h"
#include "player/t_800.h" #include "player/t_800.h"
void init_player(RNG *rng, std::unique_ptr<player_base> &pc, std::unique_ptr<player_base> init_player(RNG *rng,
const feature enabled_features, const enum race &r) { const feature enabled_features, const enum race &r) {
using std::make_unique; using std::make_unique;
pc = nullptr;
switch (r) { switch (r) {
case rgoblin: case rgoblin:
pc = make_unique<goblin>(rng, enabled_features); return make_unique<goblin>(rng, enabled_features);
break; break;
case rdrow: case rdrow:
pc = make_unique<drow>(rng, enabled_features); return make_unique<drow>(rng, enabled_features);
break; break;
case rshade: case rshade:
pc = make_unique<shade>(rng, enabled_features); return make_unique<shade>(rng, enabled_features);
break; break;
case rtroll: case rtroll:
pc = make_unique<troll>(rng, enabled_features); return make_unique<troll>(rng, enabled_features);
break; break;
case rvampire: case rvampire:
pc = make_unique<vampire>(rng, enabled_features); return make_unique<vampire>(rng, enabled_features);
break; break;
case rt_800: case rt_800:
pc = make_unique<t_800>(rng, enabled_features); return make_unique<t_800>(rng, enabled_features);
break; break;
default: default:
break; break;
} }
return nullptr;
} }

View File

@ -4,7 +4,7 @@
#include <memory> #include <memory>
#include "player.h" #include "player.h"
void init_player(RNG *rng, std::unique_ptr<player_base> &pc, std::unique_ptr<player_base> init_player(RNG *rng,
const feature enabled_features, const enum race &r); const feature enabled_features, const enum race &r);
#endif #endif

View File

@ -8,34 +8,35 @@
#include "potions/wound_atk.h" #include "potions/wound_atk.h"
#include "potions/wound_def.h" #include "potions/wound_def.h"
void new_potion(std::unique_ptr<potion> &pp, potion_type type, std::unique_ptr<potion> new_potion(potion_type type, const position &pos) {
const position &pos) {
switch (type) { switch (type) {
case restore_health: case restore_health:
pp = std::make_unique<class restore_health>(pos); return std::make_unique<class restore_health>(pos);
break; break;
case boost_atk: case boost_atk:
pp = std::make_unique<class boost_atk>(pos); return std::make_unique<class boost_atk>(pos);
break; break;
case boost_def: case boost_def:
pp = std::make_unique<class boost_def>(pos); return std::make_unique<class boost_def>(pos);
break; break;
case poison_health: case poison_health:
pp = std::make_unique<class poison_health>(pos); return std::make_unique<class poison_health>(pos);
break; break;
case wound_atk: case wound_atk:
pp = std::make_unique<class wound_atk>(pos); return std::make_unique<class wound_atk>(pos);
break; break;
case wound_def: case wound_def:
pp = std::make_unique<class wound_def>(pos); return std::make_unique<class wound_def>(pos);
break; break;
default: default:
break; break;
} }
return nullptr;
} }

View File

@ -6,7 +6,6 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
void new_potion(std::unique_ptr<potion> &pp, potion_type type, std::unique_ptr<potion> new_potion(potion_type type, const position &pos);
const position &pos);
#endif #endif