WORK IN PROGRESS
TODO: implement random level generation moved exclude from list to position.h distinguished level and map
This commit is contained in:
120
src/map.cc
120
src/map.cc
@ -1,68 +1,82 @@
|
||||
#include "map.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
game_map::game_map(RNG &rng, const feature enabled_features):
|
||||
enabled_features{enabled_features} {
|
||||
|
||||
game_map::game_map(int lvl) {
|
||||
level = lvl;
|
||||
// TODO: randomly generate a map
|
||||
}
|
||||
|
||||
game_map::game_map(const std::string &map_data, int lvl) {
|
||||
level = lvl;
|
||||
std::istringstream iss{map_data};
|
||||
game_map::game_map(const std::string &map_data,
|
||||
RNG &rng, const feature enabled_features):
|
||||
enabled_features{enabled_features} {
|
||||
int map_size = MAP_HEIGHT * MAP_WIDTH;
|
||||
map.reserve(map_size);
|
||||
|
||||
std::string line;
|
||||
for (int i = 0; i < map_size; ++i) {
|
||||
if (map_data[i] >= '0' && map_data[i] <= '9')
|
||||
map.push_back(map_data[i] - '0');
|
||||
else
|
||||
map.push_back(map_data[i]);
|
||||
|
||||
for (int i = 0; i < MAP_HEIGHT; ++i) {
|
||||
getline(iss, line);
|
||||
map[i] = line;
|
||||
if ((map_data[i] >= '0' && map_data[i] <= '9') ||
|
||||
map_data[i] == '+' || map_data[i] == '#')
|
||||
empty_spots.push_back(remap_index(i));
|
||||
}
|
||||
|
||||
down_stairs = rng.get_rand_in_vector(empty_spots);
|
||||
|
||||
|
||||
if (enabled_features | FEATURE_REVISIT) {
|
||||
up_stairs = rng.get_rand_in_vector(
|
||||
remove_from_list(empty_spots, {down_stairs}));
|
||||
map[remap_position(up_stairs)] = '<';
|
||||
map[remap_position(down_stairs)] = '>';
|
||||
} else {
|
||||
map[remap_position(down_stairs)] = '\\';
|
||||
}
|
||||
}
|
||||
|
||||
game_map::~game_map() {}
|
||||
|
||||
int game_map::get_level() const {
|
||||
return this->level;
|
||||
const position_list game_map::get_available_positions() const {
|
||||
return empty_spots;
|
||||
}
|
||||
|
||||
std::vector<position> game_map::get_available_positions() const {
|
||||
std::vector<position> result;
|
||||
void game_map::print(display &out) const {
|
||||
for (std::size_t i = 0; i < map.size(); ++i)
|
||||
out.print_char(remap_index(i), map[i] <= 9 ? '.' : map[i],
|
||||
map[i] == '\\' || map[i] == '>' ||
|
||||
map[i] == '<' ? COLOR_PAIR(COLOR_BLUE) : A_NORMAL);
|
||||
}
|
||||
|
||||
position game_map::get_up_stairs() const {
|
||||
return up_stairs;
|
||||
}
|
||||
|
||||
position game_map::get_down_stairs() const {
|
||||
return down_stairs;
|
||||
}
|
||||
|
||||
int game_map::get_up_stairs_room() const {
|
||||
return map[remap_position(up_stairs)];
|
||||
}
|
||||
|
||||
int game_map::get_down_stairs_room() const {
|
||||
return map[remap_position(down_stairs)];
|
||||
}
|
||||
|
||||
const std::vector<position_list>game_map::get_room_list() const {
|
||||
std::vector<position_list> result;
|
||||
result.reserve(10);
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
result.push_back({});
|
||||
|
||||
for (std::size_t i = 0; i < map.size(); ++i)
|
||||
if (map[i] <= 9)
|
||||
result[map[i]].push_back(remap_index(i));
|
||||
|
||||
result.shrink_to_fit();
|
||||
|
||||
for (std::size_t i = 0; i < result.size(); ++i)
|
||||
result[i].shrink_to_fit();
|
||||
|
||||
for (int line = 0; line < MAP_HEIGHT; ++line)
|
||||
for (int x = 0; x < MAP_WIDTH; ++x)
|
||||
if (map[line][x] == '.' ||
|
||||
map[line][x] == '#' ||
|
||||
map[line][x] == '+')
|
||||
result.push_back(position{x, line});
|
||||
return result;
|
||||
}
|
||||
|
||||
void game_map::print() const {
|
||||
|
||||
// TODO: write a print function using ncurses
|
||||
}
|
||||
|
||||
void game_map::print(display &display) const {
|
||||
for (int i = 0; i < MAP_HEIGHT; ++i)
|
||||
display.print_str(position{0, i}, map[i]);
|
||||
}
|
||||
|
||||
void game_map::apply_potion(character *who, const stat_name statn,
|
||||
const int amount) {
|
||||
effects.push_back(effect{who, statn, amount});
|
||||
who->apply_buff(statn, amount);
|
||||
}
|
||||
|
||||
void game_map::enter_level(character *who) {
|
||||
for (auto eff : effects)
|
||||
if (eff.who == who)
|
||||
who->apply_buff(eff.statn, eff.amount);
|
||||
}
|
||||
|
||||
void game_map::leave_level(character *who) {
|
||||
who->set_ATK(STARTING_ATK[who->get_race()]);
|
||||
who->set_DEF(STARTING_DEF[who->get_race()]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user