MCPcopy Create free account
hub / github.com/EasyRPG/Player / GetEncountersAt

Method GetEncountersAt

src/game_map.cpp:1538–1582  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1536}
1537
1538std::vector<int> Game_Map::GetEncountersAt(int x, int y) {
1539 int terrain_tag = GetTerrainTag(Main_Data::game_player->GetX(), Main_Data::game_player->GetY());
1540
1541 std::function<bool(int)> is_acceptable = [=](int troop_id) {
1542 const lcf::rpg::Troop* troop = lcf::ReaderUtil::GetElement(lcf::Data::troops, troop_id);
1543 if (!troop) {
1544 Output::Warning("GetEncountersAt: Invalid troop ID {} in encounter list", troop_id);
1545 return false;
1546 }
1547
1548 const auto& terrain_set = troop->terrain_set;
1549
1550 // RPG_RT optimisation: Omitted entries are the default value (true)
1551 return terrain_set.size() <= (unsigned)(terrain_tag - 1) ||
1552 terrain_set[terrain_tag - 1];
1553 };
1554
1555 std::vector<int> out;
1556
1557 for (unsigned int i = 0; i < lcf::Data::treemap.maps.size(); ++i) {
1558 lcf::rpg::MapInfo& map = lcf::Data::treemap.maps[i];
1559
1560 if (map.ID == GetMapId()) {
1561 for (const auto& enc : map.encounters) {
1562 if (is_acceptable(enc.troop_id)) {
1563 out.push_back(enc.troop_id);
1564 }
1565 }
1566 } else if (map.parent_map == GetMapId() && map.type == lcf::rpg::TreeMap::MapType_area) {
1567 // Area
1568 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);
1569 Rect player_rect(x, y, 1, 1);
1570
1571 if (!player_rect.IsOutOfBounds(area_rect)) {
1572 for (const lcf::rpg::Encounter& enc : map.encounters) {
1573 if (is_acceptable(enc.troop_id)) {
1574 out.push_back(enc.troop_id);
1575 }
1576 }
1577 }
1578 }
1579 }
1580
1581 return out;
1582}
1583
1584static void OnEncounterEnd(BattleResult result) {
1585 if (result != BattleResult::Defeat) {

Callers

nothing calls this directly

Calls 4

IsOutOfBoundsMethod · 0.80
GetXMethod · 0.45
GetYMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected