1. potions being walked over
2. spawning on stairs
3. enemies walking under players
4. merchants not being aggresive
5. potions losing effect when sending pass signal (cleared by player::start_turn())’
This commit is contained in:
2024-07-15 14:41:32 -04:00
parent e561d3bbf4
commit 295b808e14
8 changed files with 72 additions and 18 deletions

View File

@ -175,7 +175,7 @@ void print_args_list() {
-R : Enable revisiting levels\n\
-e : Enable extra potions and races\n\
-E : Enable extra levels\n\
-o : Allows monsters to go over gold and potions\n\
-o : Allows characters to go over gold and potions\n\
-s [seed] : Sets initial seed to seed\n\
-I [file] : Reads commands from file. CANNOT BE USED WITH -n.\n\
-O [file] : Outputs to file. CANNOT BE USED WITH -n.\n\

View File

@ -30,7 +30,7 @@ void cursor::show() const {
}
void cursor::clear() const {
::clear();
// ::clear();
}
void cursor::print_char(const position &pos, const char ch,

View File

@ -73,11 +73,14 @@ long_result enemy_base::get_hit(character *ch, const int tATK,
if (HP == 0)
return {result::hit,
"PC deals " + std::to_string(tmp) +
" damage to " + abbrev + ". " + abbrev +
" damage to " + abbrev + " (" +
std::to_string(HP) + " HP). " +
abbrev +
" is slain by PC. "};
return {result::hit, "PC deals " +
std::to_string(tmp) + " damage to " + abbrev + ". "};
std::to_string(tmp) + " damage to " + abbrev + " (" +
std::to_string(HP) + " HP). "};
}
return {miss, "PC tried to hit " + abbrev + " but missed. "};

View File

@ -83,11 +83,13 @@ character *game::move_enemies() {
}
game_result game::run() {
player->start_turn();
auto res = player->interpret_command(levels[curr_level].get(),
in->get_command());
msg = res.msg;
if (res.msg.find('M') != std::string::npos)
hostile_merchants = true;
switch (res.res) {
case result::terminate:
return {terminated, ""};
@ -99,13 +101,15 @@ game_result game::run() {
if (curr_level == max_level - 1)
return {won, "You won! You collected " +
std::to_string(player->get_gold()) +
" after " + std::to_string(curr_turn + 1) +
" pieces of gold after " +
std::to_string(curr_turn + 1) +
" turns!"};
player->discard_level_effects();
++curr_level;
if (curr_level == levels.size())
new_level();
break;
@ -115,7 +119,8 @@ game_result game::run() {
if (curr_level == 0)
return {escaped, "You escaped the dungeon with " +
std::to_string(player->get_gold()) +
" after " + std::to_string(curr_turn + 1) +
" pieces of gold after " +
std::to_string(curr_turn + 1) +
" turns! Coward!"};
player->discard_level_effects();
@ -169,6 +174,7 @@ const position STATUS_HP{0, 26};
const position STATUS_ATK{0, 27};
const position STATUS_DEF{0, 28};
const position STATUS_ACTION{0, 29};
const std::string BLANK(DISPLAY_BUFFER_SIZE, ' ');
size_t game::get_curr_turn() const {
return curr_turn;
@ -180,6 +186,8 @@ void game::print() {
msg += "...";
}
out->print_str({0, 0}, BLANK);
levels[curr_level]->print(out);
player->print(out);

View File

@ -6,6 +6,15 @@ level::level(character *player, RNG *rng, const feature enabled_features):
enabled_features{enabled_features}, map{player, rng, enabled_features},
player{player} {
auto tiles = map.get_room_list();
for (size_t i = 0; i < tiles.size(); ++i)
remove_from_list(tiles[i], map.get_down_stairs());
if (enabled_features & FEATURE_REVISIT)
for (size_t i = 0; i < tiles.size(); ++i)
remove_from_list(tiles[i], map.get_up_stairs());
gen_potions(rng, tiles);
gen_gold(rng, tiles);
gen_enemies(rng, tiles);
@ -16,6 +25,14 @@ level::level(const std::string &map_data, character *player, RNG *rng,
enabled_features{enabled_features},
map{player, map_data, rng, enabled_features}, player{player} {
auto tiles = map.get_room_list();
for (size_t i = 0; i < tiles.size(); ++i)
remove_from_list(tiles[i], map.get_down_stairs());
if (enabled_features & FEATURE_REVISIT)
for (size_t i = 0; i < tiles.size(); ++i)
remove_from_list(tiles[i], map.get_up_stairs());
gen_potions(rng, tiles);
gen_gold(rng, tiles);
gen_enemies(rng, tiles);
@ -42,9 +59,12 @@ void level::gen_enemies(RNG *rng, std::vector<position_list> &tiles) {
for (size_t i = 0; i < dhoard.size(); ++i) {
position_list spots;
for (int i = 0; i < DIRECTION_CNT; ++i)
if (map.which_room(dhoard[i].pos + MOVE[i]) != -1)
for (int i = 0; i < DIRECTION_CNT; ++i) {
position tmp = dhoard[i].pos + MOVE[i];
if (map.which_room(tmp) != -1)
spots.push_back(dhoard[i].pos + MOVE[i]);
}
pelist.push_back(nullptr);
new_dragon(rng, pelist[i], rng->get_rand_in_vector(spots),
@ -128,19 +148,22 @@ bool level::is_available(const position &pos, bool is_player) const {
if (!map.is_available(pos))
return false;
if (player->get_pos() == pos)
return false;
for (size_t i = 0; i < elist.size(); ++i)
if (pos == elist[i]->get_pos())
return false;
if (!(enabled_features & FEATURE_WALK_OVER) && !is_player) {
if (!(enabled_features & FEATURE_WALK_OVER))
for (size_t i = 0; i < plist.size(); ++i)
if (pos == plist[i]->get_pos())
return false;
if (!(enabled_features & FEATURE_WALK_OVER) && !is_player)
for (size_t i = 0; i < glist.size(); ++i)
if (pos == glist[i].pos)
return false;
}
return true;
}
@ -149,6 +172,9 @@ bool level::is_available_all(const position &pos) const {
if (!map.is_available(pos))
return false;
if (player->get_pos() == pos)
return false;
for (size_t i = 0; i < elist.size(); ++i)
if (pos == elist[i]->get_pos())
return false;

View File

@ -111,18 +111,31 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) {
return {result::terminate, ""};
} else if (cmd >= move_north && cmd <= move_southwest) {
auto res = move(lvl, pos + MOVE[cmd - move_north]);
if (res.res == result::moved)
start_turn();
gold g = get_gold_at(pos, lvl->get_glist());
gold_cnt += g.amount;
return res;
} else if (cmd >= apply_north && cmd <= apply_southwest) {
return apply(get_potion_at(pos + MOVE[cmd - apply_north],
auto res = apply(get_potion_at(pos + MOVE[cmd - apply_north],
lvl->get_plist()));
if (res.res == result::applied)
start_turn();
return res;
} else if (cmd == apply_panic) {
return {result::fine,
"PC tried to use in some non-existent direction. "};
} else if (cmd >= attack_north && cmd <= attack_southwest) {
enemy_base *tmp = get_enemy_at(pos + MOVE[cmd - attack_north],
lvl->get_elist());
if (tmp != nullptr)
start_turn();
auto res = attack((character *)tmp);
if (tmp != nullptr && tmp->is_dead())
@ -131,14 +144,18 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) {
return res;
} else if (cmd == up_stairs) {
if (lvl->get_up_stairs() == pos &&
enabled_features & FEATURE_REVISIT)
enabled_features & FEATURE_REVISIT) {
start_turn();
return {go_up, "PC went up the stairs. "};
}
return {result::fine,
"PC tried to fly through the ceiling. "};
} else if (cmd == down_stairs) {
if (lvl->get_down_stairs() == pos)
if (lvl->get_down_stairs() == pos) {
start_turn();
return {go_down, "PC went down the stairs. "};
}
return {result::fine,
"PC tried to dig through the floor. "};

View File

@ -67,7 +67,7 @@ std::vector<position> remove_from_list(const std::vector<position>
void remove_from_list(std::vector<position>
&positions,
position &excluded) {
const position &excluded) {
for (auto i = positions.begin(); i != positions.end(); ++i)
if (*i == excluded) {
positions.erase(i);

View File

@ -26,7 +26,7 @@ std::size_t find(const position_list &sorted_list,
std::vector<position> remove_from_list(const position_list &sorted_positions,
position_list excluded);
void remove_from_list(position_list &sorted_positions,
position &excluded);
const position &excluded);
float distance(const position &a, const position &b);
int distance_sqr(const position &a, const position &b);