Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default case of battle encounters terrain tag check #1218

Merged
merged 2 commits into from Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/game_map.cpp
Expand Up @@ -895,17 +895,19 @@ void Game_Map::ResetEncounterSteps() {
}
}

void Game_Map::GetEncountersAt(int x, int y, std::vector<int>& out) {
std::vector<int> Game_Map::GetEncountersAt(int x, int y) {
int terrain_tag = GetTerrainTag(Main_Data::game_player->GetX(), Main_Data::game_player->GetY());

std::function<bool(int)> is_acceptable = [=](int troop_id) {
std::vector<bool>& terrain_set = Data::troops[troop_id - 1].terrain_set;

// RPG_RT optimisation: Omitted entries are the default value (false)
return (terrain_set.size() > (unsigned)(terrain_tag - 1) &&
terrain_set[terrain_tag - 1]);
// RPG_RT optimisation: Omitted entries are the default value (true)
return terrain_set.size() <= (unsigned)(terrain_tag - 1) ||
terrain_set[terrain_tag - 1];
};

std::vector<int> out;

for (unsigned int i = 0; i < Data::treemap.maps.size(); ++i) {
RPG::MapInfo& map = Data::treemap.maps[i];

Expand All @@ -929,6 +931,8 @@ void Game_Map::GetEncountersAt(int x, int y, std::vector<int>& out) {
}
}
}

return out;
}

bool Game_Map::PrepareEncounter() {
Expand All @@ -939,8 +943,7 @@ bool Game_Map::PrepareEncounter() {
int x = Main_Data::game_player->GetX();
int y = Main_Data::game_player->GetY();

std::vector<int> encounters;
GetEncountersAt(x, y, encounters);
std::vector<int> encounters = GetEncountersAt(x, y);

if (encounters.empty()) {
// No enemies on this map :(
Expand Down
9 changes: 6 additions & 3 deletions src/game_map.h
Expand Up @@ -298,11 +298,14 @@ namespace Game_Map {
void ResetEncounterSteps();

/**
* Gets possible encounters at a location. Also scans areas.
* Gets possible encounters at a location.
* Respects areas and terrain settings.
*
* @param out Possible encounters
* @param x x position
* @param y y position
* @return Possible encounters
*/
void GetEncountersAt(int x, int y, std::vector<int>& out);
std::vector<int> GetEncountersAt(int x, int y);

/**
* Updates all battle data based on the current player position and starts
Expand Down