Skip to content

Commit

Permalink
Merge pull request #6216 from kuronekochomusuke/addBoardAutoTags
Browse files Browse the repository at this point in the history
add additional board auto tags
  • Loading branch information
HammerGS authored Nov 29, 2024
2 parents 2c8972b + 32e2987 commit 9f4d658
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions megamek/src/megamek/utilities/BoardsTagger.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
import java.util.*;
import java.util.stream.Collectors;

import megamek.common.Board;
import megamek.common.Building;
import megamek.common.Configuration;
import megamek.common.Hex;
import megamek.common.*;
import megamek.logging.MMLogger;

/**
Expand Down Expand Up @@ -86,7 +83,16 @@ public enum Tags {
TAG_WATER("Water"),
TAG_ICE("IceTerrain"),
TAG_FLAT("Flat"),
TAG_SNOWTERRAIN("SnowTerrain");
TAG_SNOWTERRAIN("SnowTerrain"),
TAG_HANGAR("Hangar"),
TAG_FORTRESS("Fortress"),
TAG_GUNEMPLACEMENT("GunEmplacement"),
TAG_HEAVYBUILDING("HeavyBuilding"),
TAG_HARDENEDBUILDING("HardenedBuilding"),
TAG_ARMOREDBUILDING("ArmoredBuilding"),
TAG_IMPASSABLE("Impassable"),
TAG_ELEVATOR("Elevator"),
TAG_MULTIPLETHEME("MultipleTheme");

private String tagName;
private static final Map<String, Tags> internalTagMap;
Expand Down Expand Up @@ -218,6 +224,15 @@ private static void tagBoard(File boardFile) {
int water = 0;
int ice = 0;
int snowTerrain = 0;
int hangar = 0;
int fortress = 0;
int gunEnplacement = 0;
int heavyBuilding = 0;
int hardenedBuilding = 0;
int armoredBuilding = 0;
int impassable = 0;
int elevator = 0;
int multipleTheme = 0;

for (int x = 0; x < board.getWidth(); x++) {
for (int y = 0; y < board.getHeight(); y++) {
Expand Down Expand Up @@ -266,6 +281,16 @@ private static void tagBoard(File boardFile) {
lowBuildings += (height <= 2) ? 1 : 0;
highBuildings += (height > 2) ? 1 : 0;
}
if (hex.containsTerrain(BUILDING)) {
hangar += hex.terrainLevel(BLDG_CLASS) == Building.HANGAR ? 1 : 0;
fortress += hex.terrainLevel(BLDG_CLASS) == Building.FORTRESS ? 1 : 0;
gunEnplacement += hex.terrainLevel(BLDG_CLASS) == Building.GUN_EMPLACEMENT ? 1 : 0;
heavyBuilding += hex.terrainLevel(BUILDING) == Building.HEAVY ? 1 : 0;
hardenedBuilding += hex.terrainLevel(BUILDING) == Building.HARDENED ? 1 : 0;
armoredBuilding += hex.containsTerrain(BLDG_ARMOR) && hex.terrainLevel(Terrains.BLDG_ARMOR) > 0 ? 1 : 0;
}
impassable += hex.containsTerrain(IMPASSABLE) ? 1 : 0;
elevator += hex.containsTerrain(ELEVATOR) ? 1 : 0;
}
}

Expand Down Expand Up @@ -316,6 +341,24 @@ private static void tagBoard(File boardFile) {
matchingTags.put(Tags.TAG_HEAVYURBAN, (stdBuildings >= normSide * 4) && (roads > normSide / 3));
matchingTags.put(Tags.TAG_SNOWTERRAIN, (snowTerrain > normSide * 2));
matchingTags.put(Tags.TAG_FLAT, (levelExtent <= 2) && (weighedLevels < normSide * 5));
matchingTags.put(Tags.TAG_HANGAR, hangar > 10);
matchingTags.put(Tags.TAG_FORTRESS, fortress > 10);
matchingTags.put(Tags.TAG_GUNEMPLACEMENT, gunEnplacement > 10);
matchingTags.put(Tags.TAG_HEAVYBUILDING, heavyBuilding > 10);
matchingTags.put(Tags.TAG_HARDENEDBUILDING, hardenedBuilding > 10);
matchingTags.put(Tags.TAG_ARMOREDBUILDING, armoredBuilding > 10);
matchingTags.put(Tags.TAG_IMPASSABLE, impassable > 0);
matchingTags.put(Tags.TAG_ELEVATOR, elevator > 0);

multipleTheme = 0;
multipleTheme += deserts > 0 ? 1 : 0;
multipleTheme += lunar > 0 ? 1 : 0;
multipleTheme += grass > 0 ? 1 : 0;
multipleTheme += tropical > 0 ? 1 : 0;
multipleTheme += mars > 0 ? 1 : 0;
multipleTheme += snowTheme > 0 ? 1 : 0;
multipleTheme += volcanic > 0 ? 1 : 0;
matchingTags.put(Tags.TAG_MULTIPLETHEME, multipleTheme > 1);

// Remove (see below) any auto tags that might be present so that auto tags that
// no longer apply
Expand Down

0 comments on commit 9f4d658

Please sign in to comment.