Skip to content

Commit

Permalink
Merge pull request #5835 from SJuliez/bot-bot-scenario
Browse files Browse the repository at this point in the history
Allow bot vs bot in ScenarioV2 and test setup
  • Loading branch information
HammerGS authored Aug 1, 2024
2 parents c325ae1 + 7920791 commit 7b33c02
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
19 changes: 19 additions & 0 deletions megamek/data/scenarios/Test Setups/BotvBot.mms
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MMSVersion: 2
name: Bot vs Bot as Scenario
description: A test fight bot vs bot
map: AGoAC Maps/16x17 Grassland 2.board

factions:
- name: Observer

- name: Legion of Vega
units:
- fullname: Atlas AS7-D
- fullname: Locust LCT-1M

- name: 2nd Air Cavalry, Federated Suns
units:
- fullname: Atlas AS7-D
- fullname: Locust LCT-1M


67 changes: 34 additions & 33 deletions megamek/src/megamek/common/scenario/ScenarioV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import megamek.common.icons.FileCamouflage;
import megamek.common.jacksonadapters.BoardDeserializer;
import megamek.common.jacksonadapters.MMUReader;
import megamek.common.options.SBFRuleOptions;
import megamek.common.planetaryconditions.PlanetaryConditions;
import megamek.common.strategicBattleSystems.SBFGame;
import megamek.server.IGameManager;
Expand Down Expand Up @@ -187,7 +186,7 @@ private List<Player> readPlayers(IGame game) throws ScenarioLoaderException, IOE

for (Iterator<JsonNode> it = node.get(PARAM_FACTIONS).elements(); it.hasNext(); ) {
JsonNode playerNode = it.next();
MMUReader.requireFields("Player", playerNode, NAME, UNITS);
MMUReader.requireFields("Player", playerNode, NAME);

Player player = new Player(playerId, playerNode.get(NAME).textValue());
result.add(player);
Expand Down Expand Up @@ -216,40 +215,42 @@ private List<Player> readPlayers(IGame game) throws ScenarioLoaderException, IOE

//TODO minefields

JsonNode unitsNode = playerNode.get(UNITS);
if (game instanceof Game) {
List<Entity> units = new MMUReader(scenariofile).read(unitsNode, Entity.class).stream()
.filter(o -> o instanceof Entity)
.map(o -> (Entity) o)
.collect(Collectors.toList());
int entityId = Math.max(smallestFreeUnitID(units), game.getNextEntityId());
for (Entity unit : units) {
unit.setOwner(player);
if (unit.getId() == Entity.NONE) {
unit.setId(entityId);
entityId++;
if (playerNode.has(UNITS)) {
JsonNode unitsNode = playerNode.get(UNITS);
if (game instanceof Game) {
List<Entity> units = new MMUReader(scenariofile).read(unitsNode, Entity.class).stream()
.filter(o -> o instanceof Entity)
.map(o -> (Entity) o)
.collect(Collectors.toList());
int entityId = Math.max(smallestFreeUnitID(units), game.getNextEntityId());
for (Entity unit : units) {
unit.setOwner(player);
if (unit.getId() == Entity.NONE) {
unit.setId(entityId);
entityId++;
}
((Game) game).addEntity(unit);
// Grounded DropShips don't set secondary positions unless they're part of a game and can verify
// they're not on a space map.
if (unit.isLargeCraft() && !unit.isAirborne()) {
unit.setAltitude(0);
}
}
((Game) game).addEntity(unit);
// Grounded DropShips don't set secondary positions unless they're part of a game and can verify
// they're not on a space map.
if (unit.isLargeCraft() && !unit.isAirborne()) {
unit.setAltitude(0);
} else if (game instanceof SBFGame) {
List<InGameObject> units = new MMUReader(scenariofile).read(unitsNode).stream()
.filter(o -> o instanceof InGameObject)
.map(o -> (InGameObject) o)
.collect(Collectors.toList());
int entityId = Math.max(smallestFreeUnitID(units), game.getNextEntityId());
for (InGameObject unit : units) {
if (unit.getId() == Entity.NONE) {
unit.setId(entityId);
entityId++;
}
unit.setOwnerId(player.getId());
((SBFGame) game).addUnit(unit);
}
}
} else if (game instanceof SBFGame) {
List<InGameObject> units = new MMUReader(scenariofile).read(unitsNode).stream()
.filter(o -> o instanceof InGameObject)
.map(o -> (InGameObject) o)
.collect(Collectors.toList());
int entityId = Math.max(smallestFreeUnitID(units), game.getNextEntityId());
for (InGameObject unit : units) {
if (unit.getId() == Entity.NONE) {
unit.setId(entityId);
entityId++;
}
unit.setOwnerId(player.getId());
((SBFGame) game).addUnit(unit);
}
}
// TODO: look at unit individual camo and see if it's a file in the scenario directory; the entity parsers
// cannot handle this as they don't know it's a scenario
Expand Down

0 comments on commit 7b33c02

Please sign in to comment.