fixed: enemies may spawn on top of dragons

added prompting to picking up gold
This commit is contained in:
2024-07-15 19:47:07 -04:00
parent 9e0c6bc723
commit 70e80c1474
5 changed files with 41 additions and 11 deletions

View File

@ -86,7 +86,7 @@ long_result enemy_base::get_hit(character *ch, const int tATK,
return {miss, "PC tried to hit " + abbrev + " but missed. "}; return {miss, "PC tried to hit " + abbrev + " but missed. "};
} }
void enemy_base::dies(level *lvl, character *pc) { int enemy_base::dies(level *lvl) {
auto &elist = lvl->get_elist(); auto &elist = lvl->get_elist();
for (size_t i = 0; i < elist.size(); ++i) for (size_t i = 0; i < elist.size(); ++i)
@ -96,17 +96,19 @@ void enemy_base::dies(level *lvl, character *pc) {
} }
if (race == race::rdragon) { if (race == race::rdragon) {
return; return 0;
} else if (race == race::rmerchant) { } else if (race == race::rmerchant) {
lvl->add_gold({GOLD_MERCHANT, pos}); lvl->add_gold({GOLD_MERCHANT, pos});
return 0;
} else if (race == race::rhuman) { } else if (race == race::rhuman) {
lvl->add_gold({GOLD_NORMAL, pos}); lvl->add_gold({GOLD_NORMAL, pos});
auto plist = lvl->get_available_around_all(pos); auto plist = lvl->get_available_around_all(pos);
lvl->add_gold({GOLD_NORMAL, lvl->add_gold({GOLD_NORMAL,
rng->get_rand_in_vector(plist)}); rng->get_rand_in_vector(plist)});
return 0;
} }
((player_base *)pc)->add_gold(rand_gold_drop(rng)); return rand_gold_drop(rng);
} }
enemy_base *get_enemy_at(const position &pos, const enemy_list &elist) { enemy_base *get_enemy_at(const position &pos, const enemy_list &elist) {

View File

@ -26,7 +26,7 @@ public:
virtual std::string get_abbrev() const override; virtual std::string get_abbrev() const override;
virtual void dies(level *lvl, character *pc); virtual int dies(level *lvl);
}; };
typedef std::vector<enemy_base *> enemy_list; typedef std::vector<enemy_base *> enemy_list;

View File

@ -73,8 +73,12 @@ character *game::move_enemies() {
if (player->is_dead()) if (player->is_dead())
return ch; return ch;
if (ch->is_dead()) if (ch->is_dead()) {
ch->dies(levels[curr_level].get(), player.get()); int g = ch->dies(levels[curr_level].get());
if (g)
levels[curr_level]->add_gold({g, ch->get_pos()});
}
msg += res.msg; msg += res.msg;
} }

View File

@ -67,9 +67,16 @@ void level::gen_enemies(RNG *rng, std::vector<position_list> &tiles) {
} }
pelist.push_back(nullptr); pelist.push_back(nullptr);
new_dragon(rng, pelist[i], rng->get_rand_in_vector(spots), auto pos = rng->get_rand_in_vector(spots);
new_dragon(rng, pelist[i], pos,
dhoard[i].pos, enabled_features, dhoard[i].pos, enabled_features,
map.which_room(dhoard[i].pos)); map.which_room(dhoard[i].pos));
int room = map.which_room(pos);
remove_from_list(tiles[room], pos);
if (!tiles[room].size())
tiles.erase(tiles.begin() + room);
elist.push_back(pelist[i].get()); elist.push_back(pelist[i].get());
} }

View File

@ -66,8 +66,14 @@ long_result player_base::move(level *lvl,
} else if ((tmp = get_enemy_at(p, lvl->get_elist())) != nullptr) { } else if ((tmp = get_enemy_at(p, lvl->get_elist())) != nullptr) {
auto res = attack((character *)tmp); auto res = attack((character *)tmp);
if (tmp->is_dead()) if (tmp->is_dead()) {
tmp->dies(lvl, this); int g = tmp->dies(lvl);
if (g)
res.msg += "PC gains " +
std::to_string(g) +
" pieces of gold. ";
}
return res; return res;
} }
@ -121,6 +127,11 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) {
gold g = get_gold_at(pos, lvl->get_glist()); gold g = get_gold_at(pos, lvl->get_glist());
gold_cnt += g.amount; gold_cnt += g.amount;
if (g.amount)
res.msg += "PC picked up " + std::to_string(g.amount) +
" pieces of gold. ";
return res; return res;
} else if (cmd >= apply_north && cmd <= apply_southwest) { } else if (cmd >= apply_north && cmd <= apply_southwest) {
auto res = apply(get_potion_at(pos + MOVE[cmd - apply_north], auto res = apply(get_potion_at(pos + MOVE[cmd - apply_north],
@ -142,8 +153,14 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) {
auto res = attack((character *)tmp); auto res = attack((character *)tmp);
if (tmp != nullptr && tmp->is_dead()) if (tmp != nullptr && tmp->is_dead()) {
tmp->dies(lvl, this); int g = tmp->dies(lvl);
if (g)
res.msg += "PC gains " +
std::to_string(g) +
" pieces of gold. ";
}
return res; return res;
} else if (cmd == up_stairs) { } else if (cmd == up_stairs) {