fixed:
dragon generation breaking the game seed validation wrong
This commit is contained in:
@ -117,9 +117,8 @@ feature proc_args(int argc, char **argv,
|
||||
if (result & FEATURE_SEED) {
|
||||
std::istringstream iss {seed};
|
||||
unsigned int tmp;
|
||||
iss >> tmp;
|
||||
|
||||
if (!iss.good())
|
||||
if (!(iss >> tmp))
|
||||
return FEATURE_PANIC_SEED;
|
||||
|
||||
rng = std::make_unique<RNG>(tmp);
|
||||
|
@ -9,16 +9,17 @@
|
||||
#include "enemies/merchant.h"
|
||||
#include "enemies/orc.h"
|
||||
|
||||
void new_dragon(RNG *rng, std::unique_ptr<enemy_base> &p,
|
||||
const position &pos, const position &fallback,
|
||||
const feature enabled_features, int which_room) {
|
||||
std::unique_ptr<enemy_base> new_dragon(RNG *rng, const position &pos,
|
||||
const position &fallback,
|
||||
const feature enabled_features,
|
||||
int which_room) {
|
||||
const position nil{0, 0};
|
||||
|
||||
if (pos != nil)
|
||||
p = std::make_unique<dragon>(rng, enabled_features,
|
||||
return std::make_unique<dragon>(rng, enabled_features,
|
||||
pos, which_room);
|
||||
else
|
||||
p = std::make_unique<dragon>(rng, enabled_features,
|
||||
return std::make_unique<dragon>(rng, enabled_features,
|
||||
fallback, which_room);
|
||||
}
|
||||
|
||||
@ -44,8 +45,8 @@ enum race get_normal_race(RNG *rng) {
|
||||
return CHOICES[rng->rand_under(CNT)];
|
||||
}
|
||||
|
||||
void new_enemy(RNG *rng, std::unique_ptr<enemy_base> &p,
|
||||
const position &pos, const feature enabled_features,
|
||||
std::unique_ptr<enemy_base> new_enemy(RNG *rng, const position &pos,
|
||||
const feature enabled_features,
|
||||
int which_room) {
|
||||
using std::make_unique;
|
||||
|
||||
@ -56,34 +57,40 @@ void new_enemy(RNG *rng, std::unique_ptr<enemy_base> &p,
|
||||
else
|
||||
r = get_normal_race(rng);
|
||||
|
||||
p = nullptr;
|
||||
|
||||
switch (r) {
|
||||
case rdwarf:
|
||||
p = make_unique<dwarf>(rng, enabled_features, pos, which_room);
|
||||
return make_unique<dwarf>(rng, enabled_features,
|
||||
pos, which_room);
|
||||
break;
|
||||
|
||||
case rhuman:
|
||||
p = make_unique<human>(rng, enabled_features, pos, which_room);
|
||||
return make_unique<human>(rng, enabled_features,
|
||||
pos, which_room);
|
||||
break;
|
||||
|
||||
case relf:
|
||||
p = make_unique<elf>(rng, enabled_features, pos, which_room);
|
||||
return make_unique<elf>(rng, enabled_features,
|
||||
pos, which_room);
|
||||
break;
|
||||
|
||||
case rorc:
|
||||
p = make_unique<orc>(rng, enabled_features, pos, which_room);
|
||||
return make_unique<orc>(rng, enabled_features,
|
||||
pos, which_room);
|
||||
break;
|
||||
|
||||
case rmerchant:
|
||||
p = make_unique<merchant>(rng, enabled_features, pos, which_room);
|
||||
return make_unique<merchant>(rng, enabled_features,
|
||||
pos, which_room);
|
||||
break;
|
||||
|
||||
case rhalfling:
|
||||
p = make_unique<halfling>(rng, enabled_features, pos, which_room);
|
||||
return make_unique<halfling>(rng, enabled_features,
|
||||
pos, which_room);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -4,12 +4,13 @@
|
||||
#include <memory>
|
||||
#include "enemy.h"
|
||||
|
||||
void new_dragon(RNG *rng, std::unique_ptr<enemy_base> &p,
|
||||
const position &pos, const position &fallback,
|
||||
const feature enabled_features, int which_room);
|
||||
std::unique_ptr<enemy_base> new_dragon(RNG *rng, const position &pos,
|
||||
const position &fallback,
|
||||
const feature enabled_features,
|
||||
int which_room);
|
||||
|
||||
void new_enemy(RNG *rng, std::unique_ptr<enemy_base> &p,
|
||||
const position &pos, const feature enabled_features,
|
||||
std::unique_ptr<enemy_base> new_enemy(RNG *rng, const position &pos,
|
||||
const feature enabled_features,
|
||||
int which_room);
|
||||
|
||||
#endif
|
||||
|
@ -15,7 +15,7 @@ game::game(const enum race starting_race,
|
||||
the_world = false;
|
||||
|
||||
// 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)
|
||||
max_level = rng->rand_between(MIN_LEVEL_CNT, MAX_LEVEL_CNT + 1);
|
||||
|
20
src/level.cc
20
src/level.cc
@ -72,11 +72,11 @@ void level::gen_enemies(RNG *rng, std::vector<position_list> &tiles) {
|
||||
spots.push_back(dhoard[i].pos + MOVE[i]);
|
||||
}
|
||||
|
||||
pelist.push_back(nullptr);
|
||||
auto pos = rng->get_rand_in_vector(spots);
|
||||
new_dragon(rng, pelist[i], pos,
|
||||
dhoard[i].pos, enabled_features,
|
||||
map.which_room(dhoard[i].pos));
|
||||
auto pos = spots.size() ? rng->get_rand_in_vector(spots) :
|
||||
dhoard[i].pos;
|
||||
pelist.push_back(new_dragon(rng, pos, dhoard[i].pos,
|
||||
enabled_features,
|
||||
map.which_room(dhoard[i].pos)));
|
||||
int room = map.which_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) {
|
||||
pelist.push_back(nullptr);
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -136,10 +136,8 @@ void level::gen_potions(RNG *rng, std::vector<position_list> &tiles) {
|
||||
pplist.reserve(cnt);
|
||||
|
||||
for (int i = 0; i < cnt; ++i) {
|
||||
pplist.push_back(nullptr);
|
||||
new_potion(pplist[i],
|
||||
(potion_type)rng->rand_under(max_type),
|
||||
get_rand_pos(rng, tiles));
|
||||
pplist.push_back(new_potion((potion_type)rng->rand_under(max_type),
|
||||
get_rand_pos(rng, tiles)));
|
||||
plist.push_back(pplist[i].get());
|
||||
}
|
||||
}
|
||||
|
18
src/pc.cc
18
src/pc.cc
@ -8,38 +8,38 @@
|
||||
#include "player/vampire.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) {
|
||||
using std::make_unique;
|
||||
|
||||
pc = nullptr;
|
||||
|
||||
switch (r) {
|
||||
case rgoblin:
|
||||
pc = make_unique<goblin>(rng, enabled_features);
|
||||
return make_unique<goblin>(rng, enabled_features);
|
||||
break;
|
||||
|
||||
case rdrow:
|
||||
pc = make_unique<drow>(rng, enabled_features);
|
||||
return make_unique<drow>(rng, enabled_features);
|
||||
break;
|
||||
|
||||
case rshade:
|
||||
pc = make_unique<shade>(rng, enabled_features);
|
||||
return make_unique<shade>(rng, enabled_features);
|
||||
break;
|
||||
|
||||
case rtroll:
|
||||
pc = make_unique<troll>(rng, enabled_features);
|
||||
return make_unique<troll>(rng, enabled_features);
|
||||
break;
|
||||
|
||||
case rvampire:
|
||||
pc = make_unique<vampire>(rng, enabled_features);
|
||||
return make_unique<vampire>(rng, enabled_features);
|
||||
break;
|
||||
|
||||
case rt_800:
|
||||
pc = make_unique<t_800>(rng, enabled_features);
|
||||
return make_unique<t_800>(rng, enabled_features);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
2
src/pc.h
2
src/pc.h
@ -4,7 +4,7 @@
|
||||
#include <memory>
|
||||
#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);
|
||||
|
||||
#endif
|
||||
|
@ -8,34 +8,35 @@
|
||||
#include "potions/wound_atk.h"
|
||||
#include "potions/wound_def.h"
|
||||
|
||||
void new_potion(std::unique_ptr<potion> &pp, potion_type type,
|
||||
const position &pos) {
|
||||
std::unique_ptr<potion> new_potion(potion_type type, const position &pos) {
|
||||
switch (type) {
|
||||
case restore_health:
|
||||
pp = std::make_unique<class restore_health>(pos);
|
||||
return std::make_unique<class restore_health>(pos);
|
||||
break;
|
||||
|
||||
case boost_atk:
|
||||
pp = std::make_unique<class boost_atk>(pos);
|
||||
return std::make_unique<class boost_atk>(pos);
|
||||
break;
|
||||
|
||||
case boost_def:
|
||||
pp = std::make_unique<class boost_def>(pos);
|
||||
return std::make_unique<class boost_def>(pos);
|
||||
break;
|
||||
|
||||
case poison_health:
|
||||
pp = std::make_unique<class poison_health>(pos);
|
||||
return std::make_unique<class poison_health>(pos);
|
||||
break;
|
||||
|
||||
case wound_atk:
|
||||
pp = std::make_unique<class wound_atk>(pos);
|
||||
return std::make_unique<class wound_atk>(pos);
|
||||
break;
|
||||
|
||||
case wound_def:
|
||||
pp = std::make_unique<class wound_def>(pos);
|
||||
return std::make_unique<class wound_def>(pos);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
void new_potion(std::unique_ptr<potion> &pp, potion_type type,
|
||||
const position &pos);
|
||||
std::unique_ptr<potion> new_potion(potion_type type, const position &pos);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user