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

Method PrepareEncounter

src/game_map.cpp:1608–1647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1606}
1607
1608bool Game_Map::PrepareEncounter(BattleArgs& args) {
1609 int x = Main_Data::game_player->GetX();
1610 int y = Main_Data::game_player->GetY();
1611
1612 std::vector<int> encounters = GetEncountersAt(x, y);
1613
1614 if (encounters.empty()) {
1615 // No enemies on this map :(
1616 return false;
1617 }
1618
1619 args.troop_id = encounters[Rand::GetRandomNumber(0, encounters.size() - 1)];
1620
1621 if (Feature::HasRpg2kBattleSystem()) {
1622 if (Rand::ChanceOf(1, 32)) {
1623 args.first_strike = true;
1624 }
1625 } else {
1626 const auto* terrain = lcf::ReaderUtil::GetElement(lcf::Data::terrains, GetTerrainTag(x, y));
1627 if (!terrain) {
1628 Output::Warning("PrepareEncounter: Invalid terrain at ({}, {})", x, y);
1629 } else {
1630 if (terrain->special_flags.back_party && Rand::PercentChance(terrain->special_back_party)) {
1631 args.condition = lcf::rpg::System::BattleCondition_initiative;
1632 } else if (terrain->special_flags.back_enemies && Rand::PercentChance(terrain->special_back_enemies)) {
1633 args.condition = lcf::rpg::System::BattleCondition_back;
1634 } else if (terrain->special_flags.lateral_party && Rand::PercentChance(terrain->special_lateral_party)) {
1635 args.condition = lcf::rpg::System::BattleCondition_surround;
1636 } else if (terrain->special_flags.lateral_enemies && Rand::PercentChance(terrain->special_lateral_enemies)) {
1637 args.condition = lcf::rpg::System::BattleCondition_pincers;
1638 }
1639 }
1640 }
1641
1642 SetupBattle(args);
1643 args.on_battle_end = OnEncounterEnd;
1644 args.allow_escape = true;
1645
1646 return true;
1647}
1648
1649void Game_Map::SetupBattle(BattleArgs& args) {
1650 int x = Main_Data::game_player->GetX();

Callers

nothing calls this directly

Calls 5

PercentChanceFunction · 0.85
GetXMethod · 0.45
GetYMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected