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

ScenarioV2 extension, sky map #5570

Merged
merged 5 commits into from
Jun 30, 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
Binary file added megamek/data/images/hexes/atmospheric_map/sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion megamek/data/images/hexes/hq_saxarba.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ base 8 "" "lunar" "saxarba/theme_lunar/base_lunar_8.png;saxarba/theme_lunar/base
base 9 "" "lunar" "saxarba/theme_lunar/base_lunar_9.png;saxarba/theme_lunar/base_lunar_9b.png;saxarba/theme_lunar/base_lunar_9c.png;saxarba/theme_lunar/base_lunar_9d.png;saxarba/theme_lunar/base_lunar_9e.png;saxarba/theme_lunar/base_lunar_9f.png"
base 10 "" "lunar" "saxarba/theme_lunar/base_lunar_10.png;saxarba/theme_lunar/base_lunar_10b.png;saxarba/theme_lunar/base_lunar_10c.png;saxarba/theme_lunar/base_lunar_10d.png;saxarba/theme_lunar/base_lunar_10e.png;saxarba/theme_lunar/base_lunar_10f.png"


base * "sky:1" "" "atmospheric_map/sky.png"

# To avoid errors
super * "fluff:*" "" "saxarba/misc/blank.png"
Expand Down
1 change: 1 addition & 0 deletions megamek/data/images/hexes/saxarba.tileset
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ base 8 "" "lunar" "saxarba/theme_lunar/base_lunar_8.png;saxarba/theme_lunar/base
base 9 "" "lunar" "saxarba/theme_lunar/base_lunar_9.png;saxarba/theme_lunar/base_lunar_9b.png;saxarba/theme_lunar/base_lunar_9c.png;saxarba/theme_lunar/base_lunar_9d.png;saxarba/theme_lunar/base_lunar_9e.png;saxarba/theme_lunar/base_lunar_9f.png"
base 10 "" "lunar" "saxarba/theme_lunar/base_lunar_10.png;saxarba/theme_lunar/base_lunar_10b.png;saxarba/theme_lunar/base_lunar_10c.png;saxarba/theme_lunar/base_lunar_10d.png;saxarba/theme_lunar/base_lunar_10e.png;saxarba/theme_lunar/base_lunar_10f.png"

base * "sky:1" "" "atmospheric_map/sky.png"

# To avoid errors
super * "fluff:*" "" "saxarba/misc/blank.png"
Expand Down
153 changes: 124 additions & 29 deletions megamek/data/scenarios/Examples/ExampleV2.mms
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

MMSVersion: 2 # Required to be recognized as a Scenario file of this format
name: Example Scenario V2 # Required title of the scenario; displayed in the scenario chooser
name: V2_test # Required title of the scenario; displayed in the scenario chooser
gametype: SBF # default: TW; other values: AS, BF, SBF
planet: Bellatrix # default: show no planet info

Expand All @@ -25,15 +25,81 @@ singleplayer: yes # default: yes; the first player is

# Game Map -------------------------------------------------------------------------------------------
map:
boardcolumns: 2 # a 2x1 map
boardrows: 1
boardcolumns: 2 # a 2x1 map, default: 1
# boardrows: 1 # default: 1
boards:
- board1.board # all files are first searched relative to the scenario file, and
- board2.board # if not found there, then relative to the appropriate data/... directory
- board1.board # all files are first searched relative to the scenario file, and
- board2.board # if not found there, then relative to the appropriate data/... directory

# OR for a single board:
# board: theBoard.board
map: AGoAC Maps/16x17 Grassland 2.board

# OR "board node"
map:
file: AGoAC Maps/16x17 Grassland 2.board

# surprise board from the given boards; require board nodes (file:)
# can modify individually and total
map:
surprise:
- file: AGoAC Maps/16x17 Grassland 2.board
modify: rotate
- file: AGoAC Maps/16x17 Grassland 3.board
- file: AGoAC Maps/16x17 Grassland 4.board
modify: rotate

# add modifiers to a single board
map:
file: AGoAC Maps/16x17 Grassland 2.board
modify: rotate

# atmospheric map without terrain
map:
type: sky
width: 65
height: 35

# space map
map:
type: space
width: 65
height: 35

# combined map with surprise maps
# when combining maps, full board nodes must be used (file:)
map:
cols: 1
boards:
- file: unofficial/SimonLandmine/TheValley/30x15 TheValley-NorthEnd.board
- surprise:
- unofficial/SimonLandmine/TheValley/30x15 TheValley-Open1.board
- unofficial/SimonLandmine/TheValley/30x15 TheValley-Open2.board
- unofficial/SimonLandmine/TheValley/30x15 TheValley-Open3.board
- unofficial/SimonLandmine/TheValley/30x15 TheValley-Open4.board
- unofficial/SimonLandmine/TheValley/30x15 TheValley-Open5.board
- unofficial/SimonLandmine/TheValley/30x15 TheValley-Quarry.board
- unofficial/SimonLandmine/TheValley/30x15 TheValley-Forest.board
- unofficial/SimonLandmine/TheValley/30x15 TheValley-Forest2.board
- file: unofficial/SimonLandmine/TheValley/30x15 TheValley-SouthEnd1.board

# Multiple maps
maps: # map and maps are 100% synonymous
- file: AGoAC Maps/16x17 Grassland 2.board
- boardcolumns: 2 # a 2x1 map, default: 1
boardrows: 1 # default: 1
boards:
- board1.board
- board2.board
id: 1
- type: sky # sky is atmospheric without terrain
width: 65
height: 35
- type: space
width: 20
height: 20


# old comments:
## Directories to choose random boards from
## RandomDirs=Map Set 2,Map Set 3,Map Set 4,Map Set 5,Map Set 6,Map Set 7
## Maps can be specified by name. The order is left-to-right, top-to-bottom
Expand Down Expand Up @@ -87,32 +153,61 @@ factions:
camo: clans/wolf/Alpha Galaxy.jpg # image file, relative to the scenario file, or in data/camos otherwise
# use slashes
units:
- include: Annihilator ANH-13.mmu
# at: [7, 4] # alternative way to indicate position
x: 7 # position, indicates that the unit is deployed
y: 4 # must have both x and y or neither
elevation: 5 # default: 5 for airborne ground; can be used in place of altitude
altitude: 8 # default: 5 for aero
status: prone, hidden # default: none; other values: shutdown, hulldown
offboard: N # default: not offboard; values: N, E, S, W
crew: # default: unnamed 4/5 pilot
name: Cpt. Frederic Nguyen
piloting: 4
gunnery: 3
- type: ASElement # default: TW standard unit
fullname: Atlas AS7-D
x: 5
y: 3
reinforce: 2 # default: deploy at start; here: reinforce at the start of round 2
# cannot be combined with a position
crew:
name: Cpt. Rhonda Snord
piloting: 4
gunnery: 3
# - include: Annihilator ANH-13.mmu
- fullname: Atlas AS7-D
# type: TW_UNIT # default: TW_UNIT other: ASElement
# pre-deployed:
at: [7, 4] # position 0704 (pre-deployed)
# x: 7 # alternative way to give position
# y: 4 # must have both x and y or neither
# NOT pre-deployed:
deploymentround: 2 # default: deploy at start; here: reinforce at the start of round 2
# ---
# elevation: 5 # default: 5 for airborne ground; can be used in place of altitude
# altitude: 8 # default: 5 for aero
status: prone, hidden # default: none; values: shutdown, hulldown, prone, hidden
offboard: N # default: not offboard; values: N, E, S, W
crew: # default: unnamed 4/5 pilot
name: Cpt. Frederic Nguyen
piloting: 4
gunnery: 3
- type: ASElement # default: TW standard unit
fullname: Atlas AS7-D
x: 5
y: 3
# cannot be combined with a position
crew:
name: Cpt. Rhonda Snord
piloting: 4
gunnery: 3

- name: "Player B"
home: "E"

units:
# - include: Annihilator ANH-13.mmu
- fullname: Schrek PPC Carrier
type: TW_UNIT
at: [7, 4] # alternative way to indicate position
# x: 7 # position, indicates that the unit is deployed
# y: 4 # must have both x and y or neither
elevation: 5 # default: 5 for airborne ground; can be used in place of altitude
altitude: 8 # default: 5 for aero
status: prone, hidden # default: none; other values: shutdown, hulldown
offboard: N # default: not offboard; values: N, E, S, W
crew: # default: unnamed 4/5 pilot
name: Cpt. Frederic Nguyen
piloting: 4
gunnery: 3
- type: ASElement # default: TW standard unit
fullname: Atlas AS7-D
x: 5
y: 3
reinforce: 2 # default: deploy at start; here: reinforce at the start of round 2
# cannot be combined with a position
crew:
name: Cpt. Rhonda Snord
piloting: 4
gunnery: 3

triggers:
- message:
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ private JComponent initializePanel(GamePhase phase) {
panMain.add(component, main);
break;
case STARTING_SCENARIO:
component = new JLabel(Messages.getString("ClientGUI.StartingScenario"));
component = new StartingScenarioPanel();
UIUtil.scaleComp(component, UIUtil.FONT_SCALE1);
main = CG_STARTINGSCENARIO;
component.setName(main);
Expand Down
15 changes: 14 additions & 1 deletion megamek/src/megamek/client/ui/swing/minimap/Minimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ private void drawMap(boolean forceDraw) {
gg.setColor(terrainColor(h));
if (h.containsTerrain(SPACE)) {
paintSpaceCoord(gg, j, k);
} else if (h.containsTerrain(SKY)) {
paintLowAtmoSkyCoord(gg, j, k);
} else {
paintCoord(gg, j, k, zoom > 1);
}
Expand Down Expand Up @@ -823,7 +825,18 @@ private void paintCoord(Graphics g, int x, int y, boolean border) {
}
g.drawPolygon(xPoints, yPoints, 6);
}


private void paintLowAtmoSkyCoord(Graphics g, int x, int y) {
int[] xPoints = xPoints(x);
int[] yPoints = yPoints(x, y);
int c = 160 + (int) (Math.random() * 80);
g.setColor(new Color(c / 2, c, c));
g.fillPolygon(xPoints, yPoints, 6);
g.setColor(Color.LIGHT_GRAY);
g.drawPolygon(xPoints, yPoints, 6);
}


private void paintSpaceCoord(Graphics g, int x, int y) {
int baseX = (x * (HEX_SIDE[zoom] + HEX_SIDE_BY_SIN30[zoom])) + leftMargin;
int baseY = (((2 * y) + 1 + (x % 2)) * HEX_SIDE_BY_COS30[zoom]) + topMargin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private static List<Scenario> getScenarioInfos() {
String userDir = PreferenceManager.getClientPreferences().getUserDir();
if (!userDir.isBlank()) {
File subDir = new File(userDir, Configuration.scenariosDir().toString());
parseScenariosInDirectory(subDir);
scenarios.addAll(parseScenariosInDirectory(subDir));
}
return scenarios;
}
Expand All @@ -145,7 +145,7 @@ private static List<Scenario> getScenarioInfos() {
* @return a List of scenarios
*/
private static List<Scenario> parseScenariosInDirectory(final File directory) {
LogManager.getLogger().info("Parsing scenarios from " + directory);
LogManager.getLogger().info("Parsing scenarios from {}", directory);
List<Scenario> scenarios = new ArrayList<>();
for (String scenarioFile : CommonSettingsDialog.filteredFilesWithSubDirs(directory, MMConstants.SCENARIO_EXT)) {
try {
Expand Down
43 changes: 42 additions & 1 deletion megamek/src/megamek/common/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,47 @@ public Board(int width, int height, Hex[] hexes, Vector<Building> bldgs,
infernos = infMap;
createBldgByCoords();
}

/**
* Returns a new atmospheric (low altitude) board with no terrain (sky map) of the given
* size.
*
* @param width the width of the board
* @param height the height of the board
* @return the new board, ready to be used
*/
public static Board getSkyBoard(int width, int height) {
Hex[] data = new Hex[width * height];
int index = 0;
for (int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
data[index++] = new Hex(0, "sky:1", "", new Coords(w, h));
}
}
Board result = new Board(width, height, data);
result.setType(Board.T_ATMOSPHERE);
return result;
}

/**
* Returns a new space board of the given size.
*
* @param width the width of the board
* @param height the height of the board
* @return the new board, ready to be used
*/
public static Board getSpaceBoard(int width, int height) {
Hex[] data = new Hex[width * height];
int index = 0;
for (int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
data[index++] = new Hex(0, "space:1", "", new Coords(w, h));
}
}
Board result = new Board(width, height, data);
result.setType(Board.T_SPACE);
return result;
}
//endregion Constructors

/**
Expand Down Expand Up @@ -219,7 +260,7 @@ public Coords getCenter() {
* @param width the width dimension.
* @param height the height dimension.
* @param data new hex data appropriate for the board.
* @param errBuff A buffer for storing error messages, if any. This is allowed to be null.
* @param errors A buffer for storing error messages, if any. This is allowed to be null.
*/
public void newData(final int width, final int height, final Hex[] data,
final @Nullable List<String> errors) {
Expand Down
1 change: 1 addition & 0 deletions megamek/src/megamek/common/Compute.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public static float randomFloat() {
* @param list The list of items to select from
* @return An element in the list
* @param <T> The list type
* @throws IllegalArgumentException when the given list is empty
*/
public static<T> T randomListElement(List<T> list) {
if (list.isEmpty()) {
Expand Down
21 changes: 21 additions & 0 deletions megamek/src/megamek/common/MechSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,27 @@ public String formatSUA(BattleForceSUA sua, String delimiter, ASSpecialAbilityCo
}
}

/**
* Loads and returns the entity for the given full name. If the entity cannot be loaded, the error is logged
* and null is returned. This is a shortcut for first loading the MechSummary using
* {@link MechSummaryCache#getMech(String)} and then {@link #loadEntity()}.
*
* @return The loaded entity or null in case of an error
*/
public static @Nullable Entity loadEntity(String fullName) {
try {
MechSummary ms = MechSummaryCache.getInstance().getMech(fullName);
if (ms != null) {
return new MechFileParser(ms.sourceFile, ms.entryName).getEntity();
} else {
LogManager.getLogger().error("MechSummary entry not found for {}", fullName);
}
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
}
return null;
}

@Override
public String toString() {
return getName();
Expand Down
7 changes: 5 additions & 2 deletions megamek/src/megamek/common/Terrains.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public class Terrains implements Serializable {

public static final int BLACK_ICE = 55;

// This is for low atmosphere maps to indicate that an empty hex is to be drawn as sky, not grassland
public static final int SKY = 56;

/**
* Keeps track of the different type of terrains that can have exits.
*/
Expand All @@ -156,11 +159,11 @@ public class Terrains implements Serializable {
"bldg_armor", "bridge", "bridge_cf", "bridge_elev", "fuel_tank", "fuel_tank_cf", "fuel_tank_elev",
"fuel_tank_magn", "impassable", "elevator", "fortified", "screen", "fluff", "arms", "legs", "metal_deposit",
"bldg_base_collapsed", "bldg_fluff", "road_fluff", "ground_fluff", "water_fluff", "cliff_top", "cliff_bottom",
"incline_top", "incline_bottom", "incline_high_top", "incline_high_bottom", "foliage_elev", "black_ice" };
"incline_top", "incline_bottom", "incline_high_top", "incline_high_bottom", "foliage_elev", "black_ice", "sky" };

/** Terrains in this set are hidden in the Editor, not saved to board files and handled internally. */
public static final HashSet<Integer> AUTOMATIC = new HashSet<>(Arrays.asList(
INCLINE_TOP, INCLINE_BOTTOM, INCLINE_HIGH_TOP, INCLINE_HIGH_BOTTOM, CLIFF_BOTTOM));
INCLINE_TOP, INCLINE_BOTTOM, INCLINE_HIGH_TOP, INCLINE_HIGH_BOTTOM, CLIFF_BOTTOM, SKY));

public static final int SIZE = names.length;

Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/common/icons/Camouflage.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public int hashCode() {
return Objects.hash(getFilename(), getCategory(), rotationAngle, scale);
}

private static String getDirectory(File file) {
public static String getDirectory(File file) {
String result = file.getParent().replace("\\", "/");
return result + (!result.endsWith("/") ? "/" : "");
}
Expand Down
Loading
Loading