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

Scenario Additions (Planetary Cond. / Dialog skip) #2775

Merged
merged 6 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
77 changes: 64 additions & 13 deletions megamek/data/scenarios/Example.mms
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#
# A MegaMek Scenario file
#
# Future features for the scenario language
# Alternate victory conditions
# Staggered entry (reinforcements)
# Specified critical slot damage
#

# Versionstamp required to be recognized as a Scenario file
Expand All @@ -16,6 +12,7 @@ Name=Example Scenario
# Scenario description
Description=This is an example scenario to show different scenario features

# Map Setup ------------------------------------------------------
# Size of the map in mapboards
BoardWidth=2
BoardHeight=1
Expand All @@ -27,10 +24,59 @@ RandomDirs=MapSet2,MapSet3,MapSet4,MapSet5,MapSet6,MapSet7
# Any unspecified boards will be set to RANDOM
Maps=RANDOM,RANDOM

# Faction list
# Game/Rule Options ----------------------------------------------
# This is an xml file which can be created by copying your
# mmconf/gameoptions.xml
# path is specified relative to the scenario file
# This is one way to set victory conditions
GameOptionsFile=Example_options.xml
# The Game Options can be fixed. In this case the Game Options Dialog shown before the
# scenario starts is skipped.
FixedGameOptions=true

# Planetary Conditions ------------------------------------------
# Planetary Conditions can be fixed. In this case the Planetary Conditions Dialog shown before the
# scenario starts is skipped.
FixedPlanetaryConditions=true
# Temperature: Only integer values are allowed
PlanetaryConditionsTemperature=-14
PlanetaryConditionsGravity=1.12
# Light: Default = Daylight; 1 = Dusk; 2 = Full Moon Night; 3 = Moonless Night; 4 = Pitch Black
PlanetaryConditionsLight=1
# Weather: Default = None; 1/2/3/4 = Light/Moderate/Heavy/Gusting Rain; 5 = Downpour;
# 6/7/9 Light/Moderate/Heavy Snow; 8 = Snow Flurries; 10 = Sleet; 11 = Blizzard;
# 12 = Ice Storm; 13/14 = Light/Heavy Hail
PlanetaryConditionsWeather=13
# Wind: Default = None; 1/2/3 = Light/Moderate/Strong Gale; 4 = Storm; 5 = Tornado F1-3; 6 = Tornado F4
PlanetaryConditionsWind=4
# Wind Direction: Default = Random; 0 = N; 1 = NE; 2 = SE; 3 = S; 4 = SW; 5 = NW
PlanetaryConditionsWindDir=2
# Atmospheric Pressure: Default = Standard; 0 = Vacuum; 1 = Trace; 2 = Thin; 4 = High; 5 = Very High
PlanetaryConditionsAtmosphere=2
# Fog: Default = No Fog; 1 = Light Fog; 2 = Heavy Fog
PlanetaryConditionsFog=1
# Shifting Wind
# Strength: Default = off; default min. Wind = 0 (see Wind above); default max. Wind = 6
# Direction: Default = off;
PlanetaryConditionsWindShiftingStr=true
PlanetaryConditionsWindMin=1
PlanetaryConditionsWindMax=3
PlanetaryConditionsWindShiftingDir=true
# Blowing Sand: Default = off
PlanetaryConditionsBlowingSand=true
# EMI: Default = off
PlanetaryConditionsEMI=true
# Allow Terrain Changes: Default = on
PlanetaryConditionsAllowTerrainChanges=false

# Faction (= Player) list ---------------------------------------
# A scenario can be set to single player style. In this case the first player is
# the human player and all other players are Princess bots. This will skip the
# Player/Camo assignment dialog and the "Host game" dialog and directly connect
# to a localhost Server and use the correct player name.
SinglePlayer=true
# The player name used to log into the server MUST match this name to play as
# that faction. Player names can *not* include spaces.
#
Factions=PlayerA,PlayerB,PlayerC

# Faction location
Expand All @@ -53,7 +99,13 @@ Team_PlayerC=2
Minefields_PlayerA=2,0,2
Minefields_PlayerB=1,0,3

# Mechlist for each faction
# Player Camos
# Assigns a camo to a player; advisable in single player scenarios where the player can't do this
# The directory and filename must be separated by a comma and the directory must end in a /
Camo_PlayerA=Clans/Wolf/,Alpha Galaxy.jpg
Camo_PlayerB=Clans/Burrock/,Alpha.jpg

# Mechlist for each faction -------------------------------------------------
#
# Units are constructed as Unit_<faction name>_<#>, where the faction name
# matches the one listed in the Faction property and the # is a sequential
Expand Down Expand Up @@ -88,6 +140,11 @@ Unit_PlayerA_1_Commander=true
Unit_PlayerB_1_Commander=true
Unit_PlayerC_1_Commander=true

# Unit Camos
# Assigns a camo to a unit, overriding any player camo
# The directory and filename must be separated by a comma and the directory must end in a /
Unit_PlayerA_1_Camo=Clans/Wolf/,Alpha Galaxy.jpg

# To initially damage units, you can use a unit armor property, which specifies
# armor and internal values. Values above the unit's nominal value for that
# location will be ignored.
Expand Down Expand Up @@ -198,9 +255,3 @@ Unit_PlayerA_2_SetAmmoType=3:1-ISAC20 Flak Ammo
#
# Unit_Kurita_666_Altitude=3

# Set game options file
# This is an xml file which can be created by copying your
# mmconf/gameoptions.xml
# path is specified relative to the scenario file
# This is one way to set victory conditions
GameOptionsFile=Example_options.xml
111 changes: 70 additions & 41 deletions megamek/src/megamek/client/ui/swing/MegaMekGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
Expand Down Expand Up @@ -675,71 +676,99 @@ public String getDescription() {
}

// popup options dialog
GameOptionsDialog god = new GameOptionsDialog(frame, g.getOptions(), false);
god.update(g.getOptions());
god.setEditable(true);
god.setVisible(true);
for (IBasicOption opt : god.getOptions()) {
IOption orig = g.getOptions().getOption(opt.getName());
orig.setValue(opt.getValue());
if (!sl.hasFixedGameOptions()) {
GameOptionsDialog god = new GameOptionsDialog(frame, g.getOptions(), false);
god.update(g.getOptions());
god.setEditable(true);
SJuliez marked this conversation as resolved.
Show resolved Hide resolved
god.setVisible(true);
for (IBasicOption opt : god.getOptions()) {
IOption orig = g.getOptions().getOption(opt.getName());
orig.setValue(opt.getValue());
}
}

// popup planetary conditions dialog
PlanetaryConditionsDialog pcd = new PlanetaryConditionsDialog(frame, g.getPlanetaryConditions());
pcd.update(g.getPlanetaryConditions());
pcd.setVisible(true);
g.setPlanetaryConditions(pcd.getConditions());

// get player types and colors set
if (!sl.hasFixedPlanetCond()) {
PlanetaryConditionsDialog pcd = new PlanetaryConditionsDialog(frame, g.getPlanetaryConditions());
pcd.update(g.getPlanetaryConditions());
SJuliez marked this conversation as resolved.
Show resolved Hide resolved
pcd.setVisible(true);
g.setPlanetaryConditions(pcd.getConditions());
}

String playerName;
int port;
String serverPW;
String localName;
Player[] pa = new Player[g.getPlayersVector().size()];
int[] playerTypes = new int[pa.length];
g.getPlayersVector().copyInto(pa);
ScenarioDialog sd = new ScenarioDialog(frame, pa);
sd.setVisible(true);
if (!sd.bSet) {
return;
}

HostDialog hd = new HostDialog(frame);
boolean hasSlot = false;
if (!("".equals(sd.localName))) {
hasSlot = true;
}
hd.setPlayerName(sd.localName);
hd.setVisible(true);

if (!hd.dataValidation("MegaMek.HostScenarioAlert.title")) {
return;
}
// get player types and colors set
if (!sl.isSinglePlayer()) {
ScenarioDialog sd = new ScenarioDialog(frame, pa);
sd.setVisible(true);
if (!sd.bSet) {
return;
}

HostDialog hd = new HostDialog(frame);
if (!("".equals(sd.localName))) {
hasSlot = true;
}
hd.setPlayerName(sd.localName);
hd.setVisible(true);

sd.localName = hd.getPlayerName();
if (!hd.dataValidation("MegaMek.HostScenarioAlert.title")) {
return;
}

sd.localName = hd.getPlayerName();
localName = hd.getPlayerName();
playerName = hd.getPlayerName();
port = hd.getPort();
serverPW = hd.getServerPass();
playerTypes = Arrays.copyOf(sd.playerTypes, playerTypes.length);

} else {
hasSlot = true;
playerName = pa[0].getName();
localName = playerName;
port = 2346;
serverPW = "";
playerTypes[0] = 0;
for (int i = 1; i < playerTypes.length; i++) {
playerTypes[i] = ScenarioDialog.T_BOT;
}
}

// kick off a RNG check
Compute.d6();

// start server
try {
server = new Server(hd.getServerPass(), hd.getPort());
server = new Server(serverPW, port);
} catch (Exception ex) {
MegaMek.getLogger().error("Could not create server socket on port " + hd.getPort(), ex);
MegaMek.getLogger().error("Could not create server socket on port " + port, ex);
JOptionPane.showMessageDialog(frame,
Messages.getFormattedString("MegaMek.StartServerError", hd.getPort(), ex.getMessage()),
Messages.getFormattedString("MegaMek.StartServerError", port, ex.getMessage()),
Messages.getString("MegaMek.HostScenarioAlert.title"), JOptionPane.ERROR_MESSAGE);
return;
}
server.setGame(g);

// apply any scenario damage
sl.applyDamage(server);
ClientGUI gui = null;
if (!"".equals(sd.localName)) {
if (!"".equals(localName)) {
// initialize game
client = new Client(hd.getPlayerName(), "localhost", hd.getPort());
client = new Client(playerName, "localhost", port);
gui = new ClientGUI(client, controller);
controller.clientgui = gui;
gui.initialize();
if (!client.connect()) {
JOptionPane.showMessageDialog(frame,
Messages.getFormattedString("MegaMek.ServerConnectionError", "localhost", hd.getPort()),
Messages.getFormattedString("MegaMek.ServerConnectionError", "localhost", port),
Messages.getString("MegaMek.HostScenarioAlert.title"), JOptionPane.ERROR_MESSAGE);
frame.setVisible(false);
client.die();
Expand All @@ -752,14 +781,14 @@ public String getDescription() {

// setup any bots
for (int x = 0; x < pa.length; x++) {
if (sd.playerTypes[x] == ScenarioDialog.T_BOT) {
if (playerTypes[x] == ScenarioDialog.T_BOT) {
MegaMek.getLogger().info("Adding bot " + pa[x].getName() + " as Princess");
BotClient c = new Princess(pa[x].getName(), "localhost", hd.getPort(), LogLevel.ERROR);
BotClient c = new Princess(pa[x].getName(), "localhost", port, LogLevel.ERROR);
c.getGame().addGameListener(new BotGUI(c));
c.connect();
} else if (sd.playerTypes[x] == ScenarioDialog.T_OBOT) {
} else if (playerTypes[x] == ScenarioDialog.T_OBOT) {
MegaMek.getLogger().info("Adding bot " + pa[x].getName() + " as TestBot");
BotClient c = new TestBot(pa[x].getName(), "localhost", hd.getPort());
BotClient c = new TestBot(pa[x].getName(), "localhost", port);
c.getGame().addGameListener(new BotGUI(c));
c.connect();
}
Expand All @@ -771,7 +800,7 @@ public String getDescription() {
Enumeration<IPlayer> pE = server.getGame().getPlayers();
while (pE.hasMoreElements()) {
IPlayer tmpP = pE.nextElement();
if (tmpP.getName().equals(sd.localName)) {
if (tmpP.getName().equals(localName)) {
tmpP.setObserver(true);
}
}
Expand Down
Loading