fixed:
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:
@ -175,7 +175,7 @@ void print_args_list() {
|
|||||||
-R : Enable revisiting levels\n\
|
-R : Enable revisiting levels\n\
|
||||||
-e : Enable extra potions and races\n\
|
-e : Enable extra potions and races\n\
|
||||||
-E : Enable extra levels\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\
|
-s [seed] : Sets initial seed to seed\n\
|
||||||
-I [file] : Reads commands from file. CANNOT BE USED WITH -n.\n\
|
-I [file] : Reads commands from file. CANNOT BE USED WITH -n.\n\
|
||||||
-O [file] : Outputs to file. CANNOT BE USED WITH -n.\n\
|
-O [file] : Outputs to file. CANNOT BE USED WITH -n.\n\
|
||||||
|
@ -30,7 +30,7 @@ void cursor::show() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cursor::clear() const {
|
void cursor::clear() const {
|
||||||
::clear();
|
// ::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cursor::print_char(const position &pos, const char ch,
|
void cursor::print_char(const position &pos, const char ch,
|
||||||
|
@ -73,11 +73,14 @@ long_result enemy_base::get_hit(character *ch, const int tATK,
|
|||||||
if (HP == 0)
|
if (HP == 0)
|
||||||
return {result::hit,
|
return {result::hit,
|
||||||
"PC deals " + std::to_string(tmp) +
|
"PC deals " + std::to_string(tmp) +
|
||||||
" damage to " + abbrev + ". " + abbrev +
|
" damage to " + abbrev + " (" +
|
||||||
|
std::to_string(HP) + " HP). " +
|
||||||
|
abbrev +
|
||||||
" is slain by PC. "};
|
" is slain by PC. "};
|
||||||
|
|
||||||
return {result::hit, "PC deals " +
|
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. "};
|
return {miss, "PC tried to hit " + abbrev + " but missed. "};
|
||||||
|
16
src/game.cc
16
src/game.cc
@ -83,11 +83,13 @@ character *game::move_enemies() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
game_result game::run() {
|
game_result game::run() {
|
||||||
player->start_turn();
|
|
||||||
auto res = player->interpret_command(levels[curr_level].get(),
|
auto res = player->interpret_command(levels[curr_level].get(),
|
||||||
in->get_command());
|
in->get_command());
|
||||||
msg = res.msg;
|
msg = res.msg;
|
||||||
|
|
||||||
|
if (res.msg.find('M') != std::string::npos)
|
||||||
|
hostile_merchants = true;
|
||||||
|
|
||||||
switch (res.res) {
|
switch (res.res) {
|
||||||
case result::terminate:
|
case result::terminate:
|
||||||
return {terminated, ""};
|
return {terminated, ""};
|
||||||
@ -99,14 +101,16 @@ game_result game::run() {
|
|||||||
if (curr_level == max_level - 1)
|
if (curr_level == max_level - 1)
|
||||||
return {won, "You won! You collected " +
|
return {won, "You won! You collected " +
|
||||||
std::to_string(player->get_gold()) +
|
std::to_string(player->get_gold()) +
|
||||||
" after " + std::to_string(curr_turn + 1) +
|
" pieces of gold after " +
|
||||||
|
std::to_string(curr_turn + 1) +
|
||||||
" turns!"};
|
" turns!"};
|
||||||
|
|
||||||
player->discard_level_effects();
|
player->discard_level_effects();
|
||||||
|
|
||||||
++curr_level;
|
++curr_level;
|
||||||
|
|
||||||
new_level();
|
if (curr_level == levels.size())
|
||||||
|
new_level();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -115,7 +119,8 @@ game_result game::run() {
|
|||||||
if (curr_level == 0)
|
if (curr_level == 0)
|
||||||
return {escaped, "You escaped the dungeon with " +
|
return {escaped, "You escaped the dungeon with " +
|
||||||
std::to_string(player->get_gold()) +
|
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!"};
|
" turns! Coward!"};
|
||||||
|
|
||||||
player->discard_level_effects();
|
player->discard_level_effects();
|
||||||
@ -169,6 +174,7 @@ const position STATUS_HP{0, 26};
|
|||||||
const position STATUS_ATK{0, 27};
|
const position STATUS_ATK{0, 27};
|
||||||
const position STATUS_DEF{0, 28};
|
const position STATUS_DEF{0, 28};
|
||||||
const position STATUS_ACTION{0, 29};
|
const position STATUS_ACTION{0, 29};
|
||||||
|
const std::string BLANK(DISPLAY_BUFFER_SIZE, ' ');
|
||||||
|
|
||||||
size_t game::get_curr_turn() const {
|
size_t game::get_curr_turn() const {
|
||||||
return curr_turn;
|
return curr_turn;
|
||||||
@ -180,6 +186,8 @@ void game::print() {
|
|||||||
msg += "...";
|
msg += "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out->print_str({0, 0}, BLANK);
|
||||||
|
|
||||||
levels[curr_level]->print(out);
|
levels[curr_level]->print(out);
|
||||||
player->print(out);
|
player->print(out);
|
||||||
|
|
||||||
|
34
src/level.cc
34
src/level.cc
@ -6,6 +6,15 @@ level::level(character *player, RNG *rng, const feature enabled_features):
|
|||||||
enabled_features{enabled_features}, map{player, rng, enabled_features},
|
enabled_features{enabled_features}, map{player, rng, enabled_features},
|
||||||
player{player} {
|
player{player} {
|
||||||
auto tiles = map.get_room_list();
|
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_potions(rng, tiles);
|
||||||
gen_gold(rng, tiles);
|
gen_gold(rng, tiles);
|
||||||
gen_enemies(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},
|
enabled_features{enabled_features},
|
||||||
map{player, map_data, rng, enabled_features}, player{player} {
|
map{player, map_data, rng, enabled_features}, player{player} {
|
||||||
auto tiles = map.get_room_list();
|
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_potions(rng, tiles);
|
||||||
gen_gold(rng, tiles);
|
gen_gold(rng, tiles);
|
||||||
gen_enemies(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) {
|
for (size_t i = 0; i < dhoard.size(); ++i) {
|
||||||
position_list spots;
|
position_list spots;
|
||||||
|
|
||||||
for (int i = 0; i < DIRECTION_CNT; ++i)
|
for (int i = 0; i < DIRECTION_CNT; ++i) {
|
||||||
if (map.which_room(dhoard[i].pos + MOVE[i]) != -1)
|
position tmp = dhoard[i].pos + MOVE[i];
|
||||||
|
|
||||||
|
if (map.which_room(tmp) != -1)
|
||||||
spots.push_back(dhoard[i].pos + MOVE[i]);
|
spots.push_back(dhoard[i].pos + MOVE[i]);
|
||||||
|
}
|
||||||
|
|
||||||
pelist.push_back(nullptr);
|
pelist.push_back(nullptr);
|
||||||
new_dragon(rng, pelist[i], rng->get_rand_in_vector(spots),
|
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))
|
if (!map.is_available(pos))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (player->get_pos() == pos)
|
||||||
|
return false;
|
||||||
|
|
||||||
for (size_t i = 0; i < elist.size(); ++i)
|
for (size_t i = 0; i < elist.size(); ++i)
|
||||||
if (pos == elist[i]->get_pos())
|
if (pos == elist[i]->get_pos())
|
||||||
return false;
|
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)
|
for (size_t i = 0; i < plist.size(); ++i)
|
||||||
if (pos == plist[i]->get_pos())
|
if (pos == plist[i]->get_pos())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!(enabled_features & FEATURE_WALK_OVER) && !is_player)
|
||||||
for (size_t i = 0; i < glist.size(); ++i)
|
for (size_t i = 0; i < glist.size(); ++i)
|
||||||
if (pos == glist[i].pos)
|
if (pos == glist[i].pos)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -149,6 +172,9 @@ bool level::is_available_all(const position &pos) const {
|
|||||||
if (!map.is_available(pos))
|
if (!map.is_available(pos))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (player->get_pos() == pos)
|
||||||
|
return false;
|
||||||
|
|
||||||
for (size_t i = 0; i < elist.size(); ++i)
|
for (size_t i = 0; i < elist.size(); ++i)
|
||||||
if (pos == elist[i]->get_pos())
|
if (pos == elist[i]->get_pos())
|
||||||
return false;
|
return false;
|
||||||
|
@ -111,18 +111,31 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) {
|
|||||||
return {result::terminate, ""};
|
return {result::terminate, ""};
|
||||||
} else if (cmd >= move_north && cmd <= move_southwest) {
|
} else if (cmd >= move_north && cmd <= move_southwest) {
|
||||||
auto res = move(lvl, pos + MOVE[cmd - move_north]);
|
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 g = get_gold_at(pos, lvl->get_glist());
|
||||||
gold_cnt += g.amount;
|
gold_cnt += g.amount;
|
||||||
return res;
|
return res;
|
||||||
} else if (cmd >= apply_north && cmd <= apply_southwest) {
|
} 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()));
|
lvl->get_plist()));
|
||||||
|
|
||||||
|
if (res.res == result::applied)
|
||||||
|
start_turn();
|
||||||
|
|
||||||
|
return res;
|
||||||
} else if (cmd == apply_panic) {
|
} else if (cmd == apply_panic) {
|
||||||
return {result::fine,
|
return {result::fine,
|
||||||
"PC tried to use in some non-existent direction. "};
|
"PC tried to use in some non-existent direction. "};
|
||||||
} else if (cmd >= attack_north && cmd <= attack_southwest) {
|
} else if (cmd >= attack_north && cmd <= attack_southwest) {
|
||||||
enemy_base *tmp = get_enemy_at(pos + MOVE[cmd - attack_north],
|
enemy_base *tmp = get_enemy_at(pos + MOVE[cmd - attack_north],
|
||||||
lvl->get_elist());
|
lvl->get_elist());
|
||||||
|
|
||||||
|
if (tmp != nullptr)
|
||||||
|
start_turn();
|
||||||
|
|
||||||
auto res = attack((character *)tmp);
|
auto res = attack((character *)tmp);
|
||||||
|
|
||||||
if (tmp != nullptr && tmp->is_dead())
|
if (tmp != nullptr && tmp->is_dead())
|
||||||
@ -131,14 +144,18 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) {
|
|||||||
return res;
|
return res;
|
||||||
} else if (cmd == up_stairs) {
|
} else if (cmd == up_stairs) {
|
||||||
if (lvl->get_up_stairs() == pos &&
|
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 {go_up, "PC went up the stairs. "};
|
||||||
|
}
|
||||||
|
|
||||||
return {result::fine,
|
return {result::fine,
|
||||||
"PC tried to fly through the ceiling. "};
|
"PC tried to fly through the ceiling. "};
|
||||||
} else if (cmd == down_stairs) {
|
} 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 {go_down, "PC went down the stairs. "};
|
||||||
|
}
|
||||||
|
|
||||||
return {result::fine,
|
return {result::fine,
|
||||||
"PC tried to dig through the floor. "};
|
"PC tried to dig through the floor. "};
|
||||||
|
@ -67,7 +67,7 @@ std::vector<position> remove_from_list(const std::vector<position>
|
|||||||
|
|
||||||
void remove_from_list(std::vector<position>
|
void remove_from_list(std::vector<position>
|
||||||
&positions,
|
&positions,
|
||||||
position &excluded) {
|
const position &excluded) {
|
||||||
for (auto i = positions.begin(); i != positions.end(); ++i)
|
for (auto i = positions.begin(); i != positions.end(); ++i)
|
||||||
if (*i == excluded) {
|
if (*i == excluded) {
|
||||||
positions.erase(i);
|
positions.erase(i);
|
||||||
|
@ -26,7 +26,7 @@ std::size_t find(const position_list &sorted_list,
|
|||||||
std::vector<position> remove_from_list(const position_list &sorted_positions,
|
std::vector<position> remove_from_list(const position_list &sorted_positions,
|
||||||
position_list excluded);
|
position_list excluded);
|
||||||
void remove_from_list(position_list &sorted_positions,
|
void remove_from_list(position_list &sorted_positions,
|
||||||
position &excluded);
|
const position &excluded);
|
||||||
|
|
||||||
float distance(const position &a, const position &b);
|
float distance(const position &a, const position &b);
|
||||||
int distance_sqr(const position &a, const position &b);
|
int distance_sqr(const position &a, const position &b);
|
||||||
|
Reference in New Issue
Block a user