void Game_Map::GetEncountersAt(int x, int y, std::vector<int>& out) { for (unsigned int i = 0; i < Data::treemap.maps.size(); ++i) { RPG::MapInfo& map = Data::treemap.maps[i]; if (map.ID == location.map_id) { std::vector<RPG::Encounter>& encounters = map.encounters; for (std::vector<RPG::Encounter>::iterator it = encounters.begin(); it != encounters.end(); ++it) { out.push_back((*it).troop_id); } } else if (map.parent_map == location.map_id && map.type == 2) { // Area Rect area_rect(map.area_rect.l, map.area_rect.t, map.area_rect.r - map.area_rect.l, map.area_rect.b - map.area_rect.t); Rect player_rect(x, y, 1, 1); if (!player_rect.IsOutOfBounds(area_rect)) { std::vector<RPG::Encounter>& encounters = map.encounters; for (std::vector<RPG::Encounter>::iterator it = encounters.begin(); it != encounters.end(); ++it) { out.push_back((*it).troop_id); } } } } }
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) { const RPG::Troop* troop = ReaderUtil::GetElement(Data::troops, troop_id); if (!troop) { Output::Warning("GetEncountersAt: Invalid troop ID %d in encounter list", troop_id); return false; } const std::vector<bool>& terrain_set = troop->terrain_set; // 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]; if (map.ID == location.map_id) { for (const RPG::Encounter& enc : map.encounters) { if (is_acceptable(enc.troop_id)) { out.push_back(enc.troop_id); } } } else if (map.parent_map == location.map_id && map.type == RPG::TreeMap::MapType_area) { // Area Rect area_rect(map.area_rect.l, map.area_rect.t, map.area_rect.r - map.area_rect.l, map.area_rect.b - map.area_rect.t); Rect player_rect(x, y, 1, 1); if (!player_rect.IsOutOfBounds(area_rect)) { for (const RPG::Encounter& enc : map.encounters) { if (is_acceptable(enc.troop_id)) { out.push_back(enc.troop_id); } } } } } return out; }