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

Planetary Conditions Enums #5203

Merged
merged 39 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8c4a96c
light enum
kuronekochomusuke Feb 24, 2024
23fca2f
typos
kuronekochomusuke Feb 24, 2024
b539019
fix warnings
kuronekochomusuke Feb 24, 2024
5841696
weather enum
kuronekochomusuke Feb 25, 2024
94572f0
fix warnings
kuronekochomusuke Feb 25, 2024
5e78be6
fix warnings
kuronekochomusuke Feb 25, 2024
468b224
wind enum
kuronekochomusuke Feb 25, 2024
0e17bca
fix tests
kuronekochomusuke Feb 25, 2024
7dfbc4e
fix warning
kuronekochomusuke Feb 25, 2024
5b3a09a
wind direction enum
kuronekochomusuke Feb 25, 2024
ed9a93a
atmosphere enum
kuronekochomusuke Feb 25, 2024
1cb068c
fix tests
kuronekochomusuke Feb 25, 2024
72e0714
fog enum
kuronekochomusuke Feb 25, 2024
823b314
blowing sand enum
kuronekochomusuke Feb 25, 2024
1df2446
emi enum
kuronekochomusuke Feb 25, 2024
75d62fc
code cleanup
kuronekochomusuke Feb 25, 2024
b18ad89
code cleanup
kuronekochomusuke Feb 26, 2024
7715de0
code cleanup
kuronekochomusuke Feb 26, 2024
2b3e8a7
remove static functions
kuronekochomusuke Feb 27, 2024
c9c40bb
fix warnings
kuronekochomusuke Feb 28, 2024
2fa6de3
remove idicators from messages
kuronekochomusuke Feb 28, 2024
9542933
split functions for mekhq
kuronekochomusuke Feb 29, 2024
bcaf32d
split function for mekhq
kuronekochomusuke Feb 29, 2024
1679b9e
fix tests
kuronekochomusuke Feb 29, 2024
6f7ece9
use enum in combobox
kuronekochomusuke Feb 29, 2024
7ad4fcb
use enum functions
kuronekochomusuke Mar 2, 2024
f947e3c
code cleanup
kuronekochomusuke Mar 2, 2024
44b7255
Merge remote-tracking branch 'origin/master' into planetaryConditions…
kuronekochomusuke Mar 2, 2024
6fa0e4a
external id to enum
kuronekochomusuke Mar 3, 2024
f94e63f
code cleanup
kuronekochomusuke Mar 3, 2024
1156684
Merge remote-tracking branch 'origin/master' into planetaryConditions…
kuronekochomusuke Mar 9, 2024
27248b6
move to planetaryconditions package
kuronekochomusuke Mar 20, 2024
cb629b5
fix package imports
kuronekochomusuke Mar 20, 2024
802d851
remove space from resource name
kuronekochomusuke Mar 20, 2024
8e70405
add isX() functions
kuronekochomusuke Mar 20, 2024
2f787bb
fix test imports
kuronekochomusuke Mar 20, 2024
993983e
store indicator in enum
kuronekochomusuke Mar 20, 2024
23686a3
fix warnings
kuronekochomusuke Mar 20, 2024
dbc04f0
Merge remote-tracking branch 'origin/master' into planetaryConditions…
kuronekochomusuke Mar 20, 2024
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
4 changes: 4 additions & 0 deletions megamek/i18n/megamek/common/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ PlanetaryConditions.DisplayableName.Weather.Blizzard=Blizzard
PlanetaryConditions.DisplayableName.Weather.Ice\ Storm=Ice Storm
PlanetaryConditions.DisplayableName.Weather.Light\ Hail=Light Hail
PlanetaryConditions.DisplayableName.Weather.Heavy\ Hail=Heavy Hail
PlanetaryConditions.DisplayableName.Weather.Lightning\ Storm=Lightning Storm
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
PlanetaryConditions.DisplayableName.WindStrength.Calm=Calm
PlanetaryConditions.DisplayableName.WindStrength.Light\ Gale=Light Gale
PlanetaryConditions.DisplayableName.WindStrength.Moderate\ Gale=Moderate Gale
Expand Down Expand Up @@ -295,6 +296,9 @@ PlanetaryConditions.Indicator.Weather.SnowFlurries=\u2744 \u2744 \u2744 \u2022
PlanetaryConditions.Indicator.Weather.HeavySnow=\u2744 \u2744 \u2744 \u2744
PlanetaryConditions.Indicator.Weather.Sleet=\u26C6 \u2022
PlanetaryConditions.Indicator.Weather.IceStorm=\u26C6 \u26C6
PlanetaryConditions.Indicator.Weather.LightHail=\u2591
PlanetaryConditions.Indicator.Weather.HeavyHail=\u2592
PlanetaryConditions.Indicator.Weather.LightningStorm=\u2608
PlanetaryConditions.Indicator.Atmosphere.Vacuum=\u2726 \u2727 \u2727 \u25AF \u2727 \u2727
PlanetaryConditions.Indicator.Atmosphere.Trace=\u2726 \u2726 \u2727 \u25AF \u2727 \u2727
PlanetaryConditions.Indicator.Atmosphere.Thin=\u2726 \u2726 \u2726 \u25AF \u2727 \u2727
Expand Down
8 changes: 4 additions & 4 deletions megamek/src/megamek/client/bot/princess/Princess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2025,10 +2025,10 @@ private void evadeIfNotFiring(MovePath path, boolean possibleToInflictDamage) {
*/
private void turnOnSearchLight(MovePath path, boolean possibleToInflictDamage) {
Entity pathEntity = path.getEntity();
if (possibleToInflictDamage &&
pathEntity.hasSearchlight() &&
!pathEntity.isUsingSearchlight() &&
(path.getGame().getPlanetaryConditions().getLight() >= PlanetaryConditions.L_FULL_MOON)) {
if (possibleToInflictDamage
&& pathEntity.hasSearchlight()
&& !pathEntity.isUsingSearchlight()
&& path.getGame().getPlanetaryConditions().isDark()) {
path.addStep(MoveStepType.SEARCHLIGHT);
}
}
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/EquipChoicePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public EquipChoicePanel(Entity entity, ClientGUI clientgui, Client client) {

// Set up searchlight
if (!entity.getsAutoExternalSearchlight()
&& (client.getGame().getPlanetaryConditions().getLight() > PlanetaryConditions.L_DUSK)) {
&& client.getGame().getPlanetaryConditions().isDark()) {
add(labSearchlight, GBC.std());
add(chSearchlight, GBC.eol());
chSearchlight.setSelected(entity.hasSearchlight()
Expand Down
69 changes: 37 additions & 32 deletions megamek/src/megamek/client/ui/swing/PlanetaryConditionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import megamek.client.ui.swing.dialog.DialogButton;
import megamek.common.Configuration;
import megamek.common.PlanetaryConditions;
import megamek.common.enums.Light;
import megamek.common.enums.Weather;
import megamek.common.util.ImageUtil;
import megamek.common.util.fileUtils.MegaMekFile;

Expand Down Expand Up @@ -232,11 +234,11 @@

/** Fills the dialog comboboxes. */
private void setupCombos() {
for (int i = 0; i < PlanetaryConditions.L_SIZE; i++) {
comLight.addItem(PlanetaryConditions.getLightDisplayableName(i));
for (Light condition : Light.values()) {
comLight.addItem(condition.toString());
}
for (int i = 0; i < PlanetaryConditions.WE_SIZE; i++) {
comWeather.addItem(PlanetaryConditions.getWeatherDisplayableName(i));
for (Weather condition : Weather.values()) {
comWeather.addItem(condition.toString());
}
for (int i = 0; i < PlanetaryConditions.WI_SIZE; i++) {
comWind.addItem(PlanetaryConditions.getWindDisplayableName(i));
Expand Down Expand Up @@ -289,8 +291,8 @@
/** Updates the dialog fields with values from the stored conditions. */
private void refreshValues() {
removeListeners();
comLight.setSelectedIndex(conditions.getLight());
comWeather.setSelectedIndex(conditions.getWeather());
comLight.setSelectedIndex(conditions.getLight().ordinal());
comWeather.setSelectedIndex(conditions.getWeather().ordinal());
comWind.setSelectedIndex(conditions.getWindStrength());
comWindFrom.setSelectedIndex(conditions.getMinWindStrength());
comWindTo.setSelectedIndex(conditions.getMaxWindStrength());
Expand All @@ -313,8 +315,8 @@
*/
private void setConditions() {
// make the changes to the planetary conditions
conditions.setLight(comLight.getSelectedIndex());
conditions.setWeather(comWeather.getSelectedIndex());
conditions.setLight(Light.getLight(comLight.getSelectedIndex()));
conditions.setWeather(Weather.getWeather(comWeather.getSelectedIndex()));
conditions.setWindStrength(comWind.getSelectedIndex());
conditions.setWindDirection(comWindDirection.getSelectedIndex());
refreshWindRange();
Expand All @@ -340,7 +342,7 @@
StringBuilder windTip = new StringBuilder();
StringBuilder atmoTip = new StringBuilder();
StringBuilder sandTip = new StringBuilder();
int weather = comWeather.getSelectedIndex();
Weather weather = Weather.getWeather(comWeather.getSelectedIndex());
int temp = 0;
float grav = (float) 1.0;
try {
Expand Down Expand Up @@ -392,21 +394,23 @@
}

// The following temperature checks are not exactly what the rules demand, but see the comment above.
if (((weather == WE_LIGHT_SNOW) || (weather == WE_SLEET)
|| (weather == WE_LIGHT_HAIL) || (weather == WE_HEAVY_HAIL))
if ((Weather.isLightSnow(weather)
|| Weather.isSleet(weather)
|| Weather.isLightHail(weather)
|| Weather.isHeaveHail(weather))
&& (temp > -40)) {
tempTip.append(Messages.getString("PlanetaryConditionsDialog.invalid.lightSnowTemp"));
wthrTip.append(Messages.getString("PlanetaryConditionsDialog.invalid.lightSnowTemp"));
}

if (((weather == WE_HEAVY_SNOW) || (weather == WE_MOD_SNOW)
|| (weather == WE_SNOW_FLURRIES))
if ((Weather.isHeavySnow(weather) || Weather.isModerateSnow(weather)
|| Weather.isSnowFlurries(weather))
&& (temp > -50)) {
tempTip.append(Messages.getString("PlanetaryConditionsDialog.invalid.modSnowTemp"));
wthrTip.append(Messages.getString("PlanetaryConditionsDialog.invalid.modSnowTemp"));
}

if ((weather == WE_ICE_STORM) && (temp > -60)) {
if (Weather.isIceStorm(weather) && (temp > -60)) {
tempTip.append(Messages.getString("PlanetaryConditionsDialog.invalid.iceStormTemp"));
wthrTip.append(Messages.getString("PlanetaryConditionsDialog.invalid.iceStormTemp"));
}
Expand Down Expand Up @@ -453,13 +457,13 @@
boolean isTraceThin = comAtmosphere.getSelectedIndex() == ATMO_THIN
| comAtmosphere.getSelectedIndex() == ATMO_TRACE;
boolean isDense = !isVacuum && !isTraceThin;
int weather = comWeather.getSelectedIndex();
boolean specificWind = (weather == WE_SNOW_FLURRIES) || (weather == WE_ICE_STORM)
|| (weather == WE_GUSTING_RAIN) || (weather == WE_LIGHTNING_STORM);
Weather weather = Weather.getWeather(comWeather.getSelectedIndex());
boolean specificWind = Weather.isSnowFlurries(weather) || Weather.isIceStorm(weather)
|| Weather.isGustingRain(weather) || Weather.isLightningStorm(weather);

removeListeners();
if (isTraceThin) {
comWeather.setSelectedIndex(PlanetaryConditions.WE_NONE);
comWeather.setSelectedIndex(Weather.WEATHER_NONE.ordinal());
comFog.setSelectedIndex(PlanetaryConditions.FOG_NONE);
}
if (isVacuum) {
Expand All @@ -468,19 +472,20 @@
chkShiftWindDir.setSelected(false);
chkShiftWindStr.setSelected(false);
comWind.setSelectedIndex(WI_NONE);
comWeather.setSelectedIndex(WE_NONE);
comWeather.setSelectedIndex(Weather.WEATHER_NONE.ordinal());
comFog.setSelectedIndex(FOG_NONE);
}
if (specificWind) {
chkShiftWindStr.setSelected(false);
switch (weather) {
case WE_LIGHTNING_STORM:
case WE_SNOW_FLURRIES:
case WE_ICE_STORM:
case LIGHTNING_STORM:
case SNOW_FLURRIES:
case ICE_STORM:
comWind.setSelectedIndex(WI_MOD_GALE);
break;
case WE_GUSTING_RAIN:
case GUSTING_RAIN:
comWind.setSelectedIndex(WI_STRONG_GALE);
default:
}
}
addListeners();
Expand All @@ -503,21 +508,21 @@

/** Sets the temperature to at most -40, -50 or -60 for snow conditions. */
private void adaptTemperature() {
int weather = comWeather.getSelectedIndex();
Weather weather = Weather.getWeather(comWeather.getSelectedIndex());
int maxTemp = 200;
switch (weather) {

Check warning

Code scanning / CodeQL

Missing enum case in switch Warning

Switch statement does not have a case for
CLEAR
,
DOWNPOUR
,
GUSTING_RAIN
, or 4 more.
case WE_LIGHT_SNOW:
case WE_SLEET:
case WE_LIGHT_HAIL:
case WE_HEAVY_HAIL:
case LIGHT_SNOW:
case SLEET:
case LIGHT_HAIL:
case HEAVY_HAIL:
maxTemp = -40;
break;
case WE_HEAVY_SNOW:
case WE_MOD_SNOW:
case WE_SNOW_FLURRIES:
case HEAVY_SNOW:
case MOD_SNOW:
case SNOW_FLURRIES:
maxTemp = -50;
break;
case WE_ICE_STORM:
case ICE_STORM:
maxTemp = -60;
}
setMaximumTemperature(maxTemp);
Expand Down
24 changes: 13 additions & 11 deletions megamek/src/megamek/client/ui/swing/boardview/BoardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import megamek.common.actions.*;
import megamek.common.annotations.Nullable;
import megamek.common.enums.IlluminationLevel;
import megamek.common.enums.Light;
import megamek.common.event.*;
import megamek.common.options.GameOptions;
import megamek.common.options.OptionsConstants;
Expand Down Expand Up @@ -1388,7 +1389,7 @@ private Image createBlurredShadow(Image orig) {
g.dispose();
mask = createShadowMask(mask);
mask = blurOp.filter(mask, null);
if (game.getPlanetaryConditions().getLight() != PlanetaryConditions.L_DAY) {
if (!game.getPlanetaryConditions().isDay()) {
mask = blurOp.filter(mask, null);
}
shadowImageCache.put(orig.hashCode(), mask);
Expand Down Expand Up @@ -1431,6 +1432,7 @@ private void updateShadowMap() {
return;
}

PlanetaryConditions conditions = game.getPlanetaryConditions();
long stT = System.nanoTime();

// 1) create or get the hex shadow
Expand All @@ -1456,10 +1458,9 @@ private void updateShadowMap() {

// Compute shadow angle based on planentary conditions.
double[] lightDirection = {-19, 7};
if ((game.getPlanetaryConditions().getLight() == PlanetaryConditions.L_MOONLESS) ||
(game.getPlanetaryConditions().getLight() == PlanetaryConditions.L_PITCH_BLACK)) {
if (conditions.isVeryDark()) {
lightDirection = new double[]{0, 0};
} else if (game.getPlanetaryConditions().getLight() == PlanetaryConditions.L_DUSK) {
} else if (conditions.isDusk()) {
// TODO: replace when made user controlled
lightDirection = new double[]{-38, 14};
} else {
Expand Down Expand Up @@ -2392,6 +2393,7 @@ private void drawHex(Coords c, Graphics boardGraph, boolean saveBoardImage) {

final Hex hex = game.getBoard().getHex(c);
final Point hexLoc = getHexLocation(c);
PlanetaryConditions conditions = game.getPlanetaryConditions();

// Check the cache to see if we already have the image
HexImageCacheEntry cacheEntry = hexImageCache.get(c);
Expand Down Expand Up @@ -2544,7 +2546,7 @@ private void drawHex(Coords c, Graphics boardGraph, boolean saveBoardImage) {
Point p2DST = new Point(hex_size.width, hex_size.height);

Composite svComp = g.getComposite();
if (game.getPlanetaryConditions().getLight() == PlanetaryConditions.L_DAY) {
if (conditions.isDay()) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.55f));
} else {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.45f));
Expand Down Expand Up @@ -2649,7 +2651,7 @@ private void drawHex(Coords c, Graphics boardGraph, boolean saveBoardImage) {
// Darken the hex for nighttime, if applicable
if (GUIP.getDarkenMapAtNight()
&& IlluminationLevel.determineIlluminationLevel(game, c).isNone()
&& (game.getPlanetaryConditions().getLight() > PlanetaryConditions.L_DAY)) {
&& conditions.isIlluminationEffective()) {
for (int x = 0; x < hexImage.getWidth(); ++x) {
for (int y = 0; y < hexImage.getHeight(); ++y) {
hexImage.setRGB(x, y, getNightDarkenedColor(hexImage.getRGB(x, y)));
Expand Down Expand Up @@ -2864,7 +2866,7 @@ private void drawOrthograph(Coords c, Graphics boardGraph) {
// Darken the hex for nighttime, if applicable
if (GUIP.getDarkenMapAtNight()
&& IlluminationLevel.determineIlluminationLevel(game, c).isNone()
&& (game.getPlanetaryConditions().getLight() > PlanetaryConditions.L_DAY)) {
&& game.getPlanetaryConditions().isIlluminationEffective()) {
for (int x = 0; x < scaledImage.getWidth(null); ++x) {
for (int y = 0; y < scaledImage.getHeight(); ++y) {
scaledImage.setRGB(x, y, getNightDarkenedColor(scaledImage.getRGB(x, y)));
Expand Down Expand Up @@ -3026,13 +3028,13 @@ public int getNightDarkenedColor(int rgb) {
int al = (rgb >> 24);

switch (game.getPlanetaryConditions().getLight()) {
case PlanetaryConditions.L_FULL_MOON:
case PlanetaryConditions.L_MOONLESS:
case FULL_MOON:
case MOONLESS:
rd = rd / 4; // 1/4 red
gr = gr / 4; // 1/4 green
bl = bl / 2; // half blue
break;
case PlanetaryConditions.L_PITCH_BLACK:
case PITCH_BLACK:
int gy = (rd + gr + bl) / 16;
if (Math.random() < 0.3) {
gy = gy * 4 / 5;
Expand All @@ -3044,7 +3046,7 @@ public int getNightDarkenedColor(int rgb) {
gr = gy + gr / 5;
bl = gy + bl / 5;
break;
case PlanetaryConditions.L_DUSK:
case DUSK:
bl = bl * 3 / 4;
break;
default:
Expand Down
Loading
Loading