Skip to content

Commit

Permalink
used enums. show changed tempature
Browse files Browse the repository at this point in the history
  • Loading branch information
kuronekochomusuke committed Mar 2, 2024
1 parent 4116c0e commit 23df016
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 175 deletions.
8 changes: 4 additions & 4 deletions MekHQ/src/mekhq/AtBGameThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ public void run() {
PlanetaryConditions planetaryConditions = new PlanetaryConditions();
planetaryConditions.setLight(scenario.getLight());
planetaryConditions.setWeather(scenario.getWeather());
planetaryConditions.setWindStrength(scenario.getWind());
planetaryConditions.setWind(scenario.getWind());
planetaryConditions.setFog(scenario.getFog());
planetaryConditions.setAtmosphere(scenario.getAtmosphere());
planetaryConditions.setGravity(scenario.getGravity());
planetaryConditions.setEMI(scenario.usesEMI());
planetaryConditions.setBlowingSand(scenario.usesBlowingSand());
planetaryConditions.setTemperature(scenario.getTemperature());
planetaryConditions.setEMI(scenario.getEMI());
planetaryConditions.setBlowingSand(scenario.getBlowingSand());
planetaryConditions.setTemperature(scenario.getModifiedTemperature());
client.sendPlanetaryConditions(planetaryConditions);
Thread.sleep(MekHQ.getMHQOptions().getStartGameDelay());

Expand Down
12 changes: 6 additions & 6 deletions MekHQ/src/mekhq/GameThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ public void run() {
PlanetaryConditions planetaryConditions = new PlanetaryConditions();
planetaryConditions.setLight(scenario.getLight());
planetaryConditions.setWeather(scenario.getWeather());
planetaryConditions.setWindStrength(scenario.getWind());
planetaryConditions.setWind(scenario.getWind());
planetaryConditions.setFog(scenario.getFog());
planetaryConditions.setAtmosphere(scenario.getAtmosphere());
planetaryConditions.setTemperature(scenario.getTemperature());
planetaryConditions.setTemperature(scenario.getModifiedTemperature());
planetaryConditions.setGravity(scenario.getGravity());
planetaryConditions.setEMI(scenario.usesEMI());
planetaryConditions.setBlowingSand(scenario.usesBlowingSand());
planetaryConditions.setEMI(scenario.getEMI());
planetaryConditions.setBlowingSand(scenario.getBlowingSand());
planetaryConditions.setShiftingWindDirection(scenario.canWindShiftDirection());
planetaryConditions.setShiftingWindStrength(scenario.canWindShiftStrength());
planetaryConditions.setMaxWindStrength(scenario.getMaxWindStrength());
planetaryConditions.setMinWindStrength(scenario.getMinWindStrength());
planetaryConditions.setWindMax(scenario.getMaxWindStrength());
planetaryConditions.setWindMin(scenario.getMinWindStrength());

client.sendPlanetaryConditions(planetaryConditions);
Thread.sleep(MekHQ.getMHQOptions().getStartGameDelay());
Expand Down
15 changes: 8 additions & 7 deletions MekHQ/src/mekhq/adapter/PressureAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@

import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import megamek.common.PlanetaryConditions;
import megamek.common.enums.Atmosphere;

public class PressureAdapter extends XmlAdapter<String, Integer> {

@Override
public Integer unmarshal(String v) throws Exception {
switch (v) {
case "Vacuum": return PlanetaryConditions.ATMO_VACUUM;
case "Trace": return PlanetaryConditions.ATMO_TRACE;
case "Vacuum": return Atmosphere.VACUUM.ordinal();
case "Trace": return Atmosphere.TRACE.ordinal();
case "Thin":
case "Low": return PlanetaryConditions.ATMO_THIN;
case "Low": return Atmosphere.THIN.ordinal();
case "Standard":
case "Normal": return PlanetaryConditions.ATMO_STANDARD;
case "High": return PlanetaryConditions.ATMO_HIGH;
case "Very High": return PlanetaryConditions.ATMO_VHIGH;
case "Normal": return Atmosphere.STANDARD.ordinal();
case "High": return Atmosphere.HIGH.ordinal();
case "Very High": return Atmosphere.VERY_HIGH.ordinal();
default: return null;
}
}

@Override
public String marshal(Integer v) throws Exception {
return PlanetaryConditions.getAtmosphereDisplayableName(v);
return Atmosphere.getAtmosphere(v).toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import megamek.codeUtilities.StringUtility;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.enums.Atmosphere;
import megamek.common.enums.Gender;
import megamek.common.enums.SkillLevel;
import megamek.common.icons.Camouflage;
Expand Down Expand Up @@ -784,7 +785,7 @@ private static void setPlanetaryConditions(AtBDynamicScenario scenario, AtBContr
PlanetarySystem pSystem = Systems.getInstance().getSystemById(mission.getSystemId());
Planet p = pSystem.getPrimaryPlanet();
if (null != p) {
int atmosphere = ObjectUtility.nonNull(p.getPressure(campaign.getLocalDate()), scenario.getAtmosphere());
Atmosphere atmosphere = Atmosphere.getAtmosphere(ObjectUtility.nonNull(p.getPressure(campaign.getLocalDate()), scenario.getAtmosphere().ordinal()));
float gravity = ObjectUtility.nonNull(p.getGravity(), scenario.getGravity()).floatValue();
int temperature = ObjectUtility.nonNull(p.getTemperature(campaign.getLocalDate()), scenario.getTemperature());

Expand Down
108 changes: 50 additions & 58 deletions MekHQ/src/mekhq/campaign/mission/AtBScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.EntityWeightClass;
import megamek.common.enums.SkillLevel;
import megamek.common.enums.*;
import megamek.common.enums.Atmosphere;
import megamek.common.icons.Camouflage;
import megamek.common.options.OptionsConstants;
import mekhq.MHQConstants;
Expand Down Expand Up @@ -222,11 +223,11 @@ public void initialize(Campaign c, Lance lance, boolean attacker, LocalDate date
}
}

light = PlanetaryConditions.L_DAY;
weather = PlanetaryConditions.WE_NONE;
wind = PlanetaryConditions.WI_NONE;
fog = PlanetaryConditions.FOG_NONE;
atmosphere = PlanetaryConditions.ATMO_STANDARD;
light = Light.DAY;
weather = Weather.CLEAR;
wind = Wind.CALM;
fog = Fog.FOG_NONE;
atmosphere = Atmosphere.STANDARD;
gravity = (float) 1.0;
deploymentDelay = 0;
setDate(date);
Expand Down Expand Up @@ -324,7 +325,7 @@ private int rollCondition(int[] odds) {
return condition;
}

private int rollLightCondition() {
private Light rollLightCondition() {
int[] odds;
String terrainType = getTerrainType() == null ? "Hills" : getTerrainType();

Expand Down Expand Up @@ -369,19 +370,15 @@ private int rollLightCondition() {
odds = new int[]{50,20,10,10,10};
break;
default:
return PlanetaryConditions.L_DAY;
return Light.DAY;
}

int light = rollCondition(odds);

if (light < PlanetaryConditions.L_DAY || light > PlanetaryConditions.L_PITCH_BLACK) {
return PlanetaryConditions.L_DAY;
}
Light light = Light.getLight(rollCondition(odds));

return light;
}

private int rollWindCondition() {
private Wind rollWindCondition() {
int[] odds;
String terrainType = getTerrainType() == null ? "Hills" : getTerrainType();

Expand Down Expand Up @@ -426,23 +423,19 @@ private int rollWindCondition() {
odds = new int[]{50,15,15,9,5,4,2};
break;
default:
return PlanetaryConditions.WI_NONE;
return Wind.CALM;
}

int wind = rollCondition(odds);
Wind wind = Wind.getWind(rollCondition(odds));

if (wind < PlanetaryConditions.WI_NONE || wind > PlanetaryConditions.WI_TORNADO_F4) {
return PlanetaryConditions.WI_NONE;
}

if (!WeatherRestriction.IsWindRestricted(wind, getAtmosphere(), getTemperature())) {
if (!WeatherRestriction.IsWindRestricted(wind.ordinal(), getAtmosphere().ordinal(), getTemperature())) {
return wind;
} else {
return PlanetaryConditions.WI_NONE;
return Wind.CALM;
}
}

private int rollWeatherCondition() {
private Weather rollWeatherCondition() {
int[] odds;
String terrainType = getTerrainType() == null ? "Hills" : getTerrainType();

Expand All @@ -465,6 +458,9 @@ private int rollWeatherCondition() {
case "HotMountainsWet":
case "HotSea":
case "Jungle":
// hot wet
odds = new int[]{47,16,12,10,8,5,1,0,0,0,1,0};
break;
case "Sea":
case "Swamp":
// wet
Expand Down Expand Up @@ -492,23 +488,19 @@ private int rollWeatherCondition() {
odds = new int[]{87,2,1,1,1,1,2,1,1,1,1,1};
break;
default:
return PlanetaryConditions.WE_NONE;
return Weather.CLEAR;
}

int weather = rollCondition(odds);
Weather weather = Weather.getWeather(rollCondition(odds));

if (weather < PlanetaryConditions.WE_NONE || weather > PlanetaryConditions.WE_ICE_STORM) {
return PlanetaryConditions.WE_NONE;
}

if (!WeatherRestriction.IsWeatherRestricted(weather, getAtmosphere(), getTemperature())) {
if (!WeatherRestriction.IsWeatherRestricted(weather.ordinal(), getAtmosphere().ordinal(), getTemperature())) {
return weather;
} else {
return PlanetaryConditions.WE_NONE;
return Weather.CLEAR;
}
}

private int rollFogCondition() {
private Fog rollFogCondition() {
int[] odds;
String terrainType = getTerrainType() == null ? "Hills" : getTerrainType();

Expand Down Expand Up @@ -548,29 +540,19 @@ private int rollFogCondition() {
odds = new int[]{60,20,20};
break;
default:
return PlanetaryConditions.FOG_NONE;
return Fog.FOG_NONE;
}

int fog = rollCondition(odds);

if (fog < PlanetaryConditions.FOG_NONE || fog > PlanetaryConditions.FOG_HEAVY) {
return PlanetaryConditions.FOG_NONE;
}
Fog fog = Fog.getFog(rollCondition(odds));

if (!WeatherRestriction.IsFogRestricted(fog, getAtmosphere(), getTemperature())) {
if (!WeatherRestriction.IsFogRestricted(fog.ordinal(), getAtmosphere().ordinal(), getTemperature())) {
return fog;
} else {
return PlanetaryConditions.FOG_NONE;
return Fog.FOG_NONE;
}
}

private boolean rollBlowingSandCondition(int wind, int weather, int fog) {
if (weather != PlanetaryConditions.WE_NONE
|| fog != PlanetaryConditions.FOG_NONE
|| wind < PlanetaryConditions.WI_MOD_GALE) {
return false;
}

private BlowingSand rollBlowingSandCondition() {
int[] odds;
String terrainType = getTerrainType() == null ? "Hills" : getTerrainType();

Expand Down Expand Up @@ -606,13 +588,13 @@ private boolean rollBlowingSandCondition(int wind, int weather, int fog) {
odds = new int[]{40,60};
break;
default:
return false;
return BlowingSand.BLOWING_SAND_NONE;
}

return rollCondition(odds) == 1;
return rollCondition(odds) == 1 ? BlowingSand.BLOWING_SAND : BlowingSand.BLOWING_SAND_NONE;
}

private boolean rollEMICondition() {
private EMI rollEMICondition() {
int[] odds;
String terrainType = getTerrainType() == null ? "Hills" : getTerrainType();

Expand Down Expand Up @@ -640,10 +622,14 @@ private boolean rollEMICondition() {
odds = new int[]{90,10};
break;
default:
return false;
return EMI.EMI_NONE;
}

return rollCondition(odds) == 1;
if (getAtmosphere().isDenserThan(Atmosphere.THIN)) {
return rollCondition(odds) == 1 ? EMI.EMI : EMI.EMI_NONE;
} else {
return EMI.EMI_NONE;
}
}

public void setLightConditions() {
Expand All @@ -657,12 +643,18 @@ public void setWeather() {
return;
}

int wind = rollWindCondition();
int weather = rollWeatherCondition();
int fog = rollFogCondition();
boolean blowingSand = rollBlowingSandCondition(wind, weather, fog);
boolean emi = rollEMICondition();
Wind wind = rollWindCondition();
Weather weather = rollWeatherCondition();
Fog fog = rollFogCondition();
BlowingSand blowingSand = rollBlowingSandCondition();
EMI emi = rollEMICondition();

int temp = getTemperature();
temp = PlanetaryConditions.setTempFromWeather(weather, temp);
wind = PlanetaryConditions.setWindFromWeather(weather, wind);
wind = PlanetaryConditions.setWindFromBlowingSand(blowingSand, wind);

setModifiedTemperature(temp);
setWind(wind);
setWeather(weather);
setFog(fog);
Expand All @@ -676,7 +668,7 @@ public void setPlanetaryConditions(Mission mission, Campaign campaign) {
//assume primary planet for now
Planet p = psystem.getPrimaryPlanet();
if (null != p) {
setAtmosphere(ObjectUtility.nonNull(p.getPressure(campaign.getLocalDate()), getAtmosphere()));
setAtmosphere(Atmosphere.getAtmosphere(ObjectUtility.nonNull(p.getPressure(campaign.getLocalDate()), getAtmosphere().ordinal())));
setGravity(ObjectUtility.nonNull(p.getGravity(), getGravity()).floatValue());
}
}
Expand Down
Loading

0 comments on commit 23df016

Please sign in to comment.