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

Allow bot vs bot in ScenarioV2 and test setup #5835

Merged
merged 1 commit into from
Aug 1, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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