Skip to content

Commit

Permalink
Merge pull request #5982 from SJuliez/Story-message-3-finished
Browse files Browse the repository at this point in the history
MM Scenario improvements, next part
  • Loading branch information
IllianiCBT authored Sep 17, 2024
2 parents 803a80a + c3f86de commit 8991afa
Show file tree
Hide file tree
Showing 8 changed files with 679 additions and 15 deletions.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ factions:
armor:
LT: 2
CT: 15
ammo:
CT:
- slot: 11
shots: 5
- slot: 12
shots: 5
crew:
name: Col. Oliver Nage
portrait: Male/MekWarrior/MW_M_15.png
Expand All @@ -74,6 +80,8 @@ factions:
CT: 15
internal:
LT: 10
crits:
RT: 3
crew:
name: Maj. Abraham Morrison
portrait: Male/MekWarrior/MW_M_13.png
Expand All @@ -87,6 +95,12 @@ factions:
armor:
HD: 5
RL: 10
ammo:
LT:
- slot: 1
shots: 3
- slot: 2
shots: 3
crew:
name: Lt. Alicia Devon
piloting: 4
Expand All @@ -98,6 +112,12 @@ factions:
remaining:
armor:
CT: 12
ammo:
LT:
- slot: 4
shots: 4
- slot: 5
shots: 4
crew:
name: Sgt. Jonathan Taylor
piloting: 4
Expand Down Expand Up @@ -151,6 +171,13 @@ factions:
- fullname: Dervish DV-6M
id: 203
deploymentround: 2
ammo:
LT:
- slot: 3
shots: 4
RT:
- slot: 3
shots: 4
crew:
name: Brian Martell
piloting: 4
Expand Down
12 changes: 10 additions & 2 deletions megamek/data/scenarios/Kell Hounds/ToSaveAPrince/ToSaveAPrince.mms
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ factions:
id: 106
force: 2nd Sword of Light|21||Zakahashi's Zombies|22||Support Lance|24
remaining:
RTR: 0
armor:
RTR: 0
crits:
LA: 5
crew:
name: Cletus Palmer
piloting: 4
Expand All @@ -105,7 +108,12 @@ factions:
id: 107
force: 2nd Sword of Light|21||Zakahashi's Zombies|22||Support Lance|24
remaining:
CT: 10
armor:
CT: 10
crits:
CT: 11
LL: [ 5, 6 ]
RL: [ 5, 6 ]
crew:
name: Tom Meyer
callsign: Hands
Expand Down
63 changes: 58 additions & 5 deletions megamek/docs/Scenarios/ScenarioV2 HowTo.mms
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ singleplayer: yes # default: yes; the first player is

# Game Map -------------------------------------------------------------------------------------------
map:
boardcolumns: 2 # a 2x1 map, default: 1
# boardrows: 1 # default: 1
# Optional: the columns to arrange boards in. Default: 1
# The number of rows follows from the number of boards given and the columns
cols: 2 # a 2x1 map, 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
Expand Down Expand Up @@ -171,6 +172,12 @@ planetaryconditions: # default: standard conditions
# Forces -------------------------------------------------------------------------------------------

factions:
# The first player is assumed to be the human player, while the rest get bots assigned by default.
# To have the bots play all factions, insert a player without any units as the first player
# Only this line is required:
# - name: Human Observer


- name: Player A
team: 1 # default: each player goes into their own team
deploy: N # default: same as the home edge
Expand All @@ -188,11 +195,15 @@ factions:
- vibra: 2
camo: clans/wolf/Alpha Galaxy.jpg # image file, relative to the scenario file, or in data/camos otherwise
# use slashes

# Units are always an array (use dashes)
units:
# - include: Annihilator ANH-13.mmu
- fullname: Atlas AS7-D
# type: TW_UNIT # default: TW_UNIT other: ASElement
# pre-deployed:
offboard: N # default: not offboard; values: N, E, S, W (TODO)
# Optional: when pre-deployed, set the facing. 5 = NW
facing: 5
at: [7, 4] # position 0704 (pre-deployed)
# x: 7 # alternative way to give position
# y: 4 # must have both x and y or neither
Expand All @@ -208,11 +219,52 @@ factions:
# the force ids are used to distinguish different forces with the same name (e.g. multiple "Assault Lance")
force: 2nd Sword of Light|21||Zakahashi's Zombies|22||Assault Lance|23

offboard: N # default: not offboard; values: N, E, S, W
crew: # default: unnamed 4/5 pilot
# pre-applied damage may assign remaining armor and internal structure values. Values
# higher than the undamaged values of the unit are ignored. Negative values set to 0 (TODO)
remaining:
armor:
# remaining armor values, use the usual location names
LT: 2
CTR: 0
internal:
# remaining internal structure is independent of armor and does not create any crits
# TODO: have 0 internal destroy the location
LA: 2

# location crits
# this usually requires looking up the unit file
crits:
# the usual location names. Give the slots as an array ([ 4, 8 ] or using dashes on separate lines)
# slots are 1-based, i.e. CT has slots 1 to 12 (not 0)
# location crits will mark the equipment as damaged, but never have any secondary effects
# like explosions or pilot hits. Crits that destroy a unit are invalid (e.g. 3 engine hits)
LA: 4
RT: [ 1, 3 ]
CT: 1
# non-location crits (TODO)
# motive: 1
# firecontrol: 1

# ammo types and reduced amount
# this usually requires looking up the unit file and possibly AmmoType.java for the type designations
ammo:
LA:
slot: 5
shots: 2
# type: xyz (TODO)

# Optional: give details of the crew/pilot - currently only for single pilots (TODO)
# by default, the pilot is an unnamed 4/5 pilot
# all fields in crew are optional
crew:
name: Cpt. Frederic Nguyen
callsign: MAGIC
piloting: 4
gunnery: 3
# Optional: pilot hits, 0 to 6
hits: 3
# Optional: a portrait, relative to data/images/portraits
portrait: Male/MechWarrior/MW_M_13.png

# Carryable objects. These currently have no real owner, but if they are not pre-deployed, the present
# player will deploy them. When pre-deployed (at: [ x, y ]), the owner is currently irrelevant.
Expand Down Expand Up @@ -438,3 +490,4 @@ trigger:
units: 201
- type: phasestart
phase: movement

1 change: 0 additions & 1 deletion megamek/src/megamek/client/ui/dialogs/MMStoryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void actionPerformed(ActionEvent evt) {
}

protected void initialize() {
setAlwaysOnTop(true);
setLayout(new BorderLayout());
add(getMainPanel(), BorderLayout.CENTER);
add(getButtonPanel(), BorderLayout.SOUTH);
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/common/AbstractGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public abstract class AbstractGame implements IGame {
* should only ever be present on the server. Only the results of events should
* be sent to clients.
*/
protected final List<TriggeredEvent> scriptedEvents = new ArrayList<>();
protected final List<TriggeredEvent> scriptedEvents = new CopyOnWriteArrayList<>();

/**
* Piles of carry-able objects, sorted by coordinates
Expand Down
102 changes: 96 additions & 6 deletions megamek/src/megamek/common/jacksonadapters/EntityDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import megamek.common.Coords;
import megamek.common.Entity;
import megamek.common.IAero;
import megamek.common.MekSummary;
import megamek.common.*;
import megamek.common.icons.Camouflage;
import megamek.common.scenario.Scenario;

Expand All @@ -58,6 +55,10 @@ public class EntityDeserializer extends StdDeserializer<Entity> {
private static final String ARMOR = "armor";
private static final String INTERNAL = "internal";
private static final String FORCE = "force";
private static final String CRITS = "crits";
private static final String AMMO = "ammo";
private static final String SLOT = "slot";
private static final String SHOTS = "shots";

public EntityDeserializer() {
this(null);
Expand Down Expand Up @@ -86,6 +87,8 @@ public Entity deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE
assignForce(entity, node);
CrewDeserializer.parseCrew(node, entity);
assignRemaining(entity, node);
assignCrits(entity, node);
assignAmmos(entity, node);
return entity;
}

Expand Down Expand Up @@ -165,7 +168,17 @@ private void assignRemaining(Entity entity, JsonNode node) {
for (int location = 0; location < entity.locations(); location++) {
String locationAbbr = entity.getLocationAbbr(location);
if (armorNode.has(locationAbbr)) {
entity.setArmor(armorNode.get(locationAbbr).intValue(), location);
// don't allow more than the maximum armor
int newArmor = Math.min(armorNode.get(locationAbbr).intValue(), entity.getArmor(location));
entity.setArmor(newArmor, location);
}
if (entity.hasRearArmor(location)) {
String rearLocationAbbr = entity.getLocationAbbr(location) + "R";
if (armorNode.has(rearLocationAbbr)) {
int newArmor = Math.min(armorNode.get(rearLocationAbbr).intValue(),
entity.getArmor(location, true));
entity.setArmor(newArmor, location, true);
}
}
}
}
Expand All @@ -174,7 +187,9 @@ private void assignRemaining(Entity entity, JsonNode node) {
for (int location = 0; location < entity.locations(); location++) {
String locationAbbr = entity.getLocationAbbr(location);
if (internalNode.has(locationAbbr)) {
entity.setInternal(internalNode.get(locationAbbr).intValue(), location);
int newIS = Math.min(internalNode.get(locationAbbr).intValue(),
entity.getInternal(location));
entity.setInternal(newIS, location);
}
}
}
Expand Down Expand Up @@ -248,4 +263,79 @@ private void assignVelocity(Entity entity, JsonNode node) {
((IAero) entity).setNextVelocity(velocity);
}
}

private void assignCrits(Entity entity, JsonNode node) {
if (!(entity instanceof Mek) || !node.has(CRITS)) {
// Implementation very different for different entities; for now: Meks
return;
}
JsonNode critsNode = node.get(CRITS);
for (int location = 0; location < entity.locations(); location++) {
String locationAbbr = entity.getLocationAbbr(location);
if (critsNode.has(locationAbbr)) {
for (int slot : parseArrayOrSingleNode(critsNode.get(locationAbbr))) {
int zeroBasedSlot = slot - 1;
CriticalSlot cs = entity.getCritical(location, zeroBasedSlot);
if ((cs == null) || !cs.isHittable()) {
throw new IllegalArgumentException("Invalid slot " + location + ":" + slot + " on " + entity);
} else {
cs.setHit(true);
if ((cs.getType() == CriticalSlot.TYPE_SYSTEM) && (cs.getIndex() == Mek.SYSTEM_ENGINE)) {
entity.engineHitsThisPhase++;
} else {
Mounted<?> mounted = cs.getMount();
mounted.setDestroyed(true);
}
}
}
}
}
}

private void assignAmmos(Entity entity, JsonNode node) {
if (node.has(AMMO)) {
JsonNode critsNode = node.get(AMMO);
for (int location = 0; location < entity.locations(); location++) {
String locationAbbr = entity.getLocationAbbr(location);
final int finalLoc = location;
if (critsNode.has(locationAbbr)) {
critsNode.get(locationAbbr).iterator().forEachRemaining(n -> assignAmmo(entity, n, finalLoc));
}
}
}
}

private void assignAmmo(Entity entity, JsonNode node, int location) {
int slot = node.get(SLOT).asInt() - 1;
int shots = node.get(SHOTS).asInt();
CriticalSlot cs = entity.getCritical(location, slot);
if (cs != null) {
Mounted<?> ammo = cs.getMount();
if (ammo.getType() instanceof AmmoType) {
// Also make sure we dont exceed the max allowed
ammo.setShotsLeft(Math.min(shots, ammo.getBaseShotsLeft()));
} else {
throw new IllegalArgumentException("Invalid ammo slot " + location + ":" + (slot + 1) + " on " + entity);
}
}
}

/**
* Returns all Integers of a node as a List. The node may be either of the form "node: singleNumber", in
* which case the List will only contain singleNumber, or it may be an array node of the form
* "node: [ firstNumber, secondNumber ]" (or the multi-line form using dashes) in which case the list
* contains all the given numbers.
*
* @param node The node to parse
* @return A list of the given numbers of the node
*/
public static List<Integer> parseArrayOrSingleNode(JsonNode node) {
List<Integer> result = new ArrayList<>();
if (node.isArray()) {
node.iterator().forEachRemaining(n -> result.add(n.asInt()));
} else {
result.add(node.asInt());
}
return result;
}
}

0 comments on commit 8991afa

Please sign in to comment.