Skip to content

Commit

Permalink
Merge branch 'master' into multi-fluff
Browse files Browse the repository at this point in the history
  • Loading branch information
HammerGS authored Aug 3, 2024
2 parents 890ac0f + 5051a8a commit 6696ed3
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 80 deletions.
23 changes: 23 additions & 0 deletions megamek/data/scenarios/Examples/ExampleV2.mms
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,29 @@ factions:
piloting: 4
gunnery: 3

# Carryable objects. These currently have no real owner, but if they are not pre-deployed, the present
# player will deploy them. When pre-deployed (they have a position), the owner is irrelevant.
objects:

# All objects require a name and weight. Currently the type is automatically Briefcase, later new
# types may be incoming; currently no ID, might make sense
- name: Black Briefcase With Codes
# weight in tons, need not be integer
weight: 1
# pre-deployed at a position
at: [ 2, 3 ]
# currently the only available status: invulnerable
# ideas:
# forbidden_owner (may only be picked up by enemies) - this would require them to have an owner
# respawn (respawns if destroyed or removed from the map)
status: invulnerable

- name: Cargo Crate
weight: 5

- name: Ambassador Hisho
weight: 0.08

- name: "Player B"
home: "E"
units:
Expand Down
49 changes: 49 additions & 0 deletions megamek/data/scenarios/Test Setups/Carryables.mms
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
MMSVersion: 2
name: Test Setup for Carryables
planet: None
description: A few units on a small map with a few carryable objects for testing; most objects predeployed, some to deploy
map: buildingsnobasement/dropport2.board

factions:
- name: Test Player

units:
- fullname: Locust LCT-1M
at: [ 9, 10 ]

- fullname: Hunchback HBK-4G
at: [ 10, 10 ]

- fullname: Charger CGR-1A1
at: [ 11, 10 ]

- fullname: Atlas AS7-D
at: [ 10, 11 ]

objects:
- name: Test Paperweight (invulnerable)
at: [ 14, 11 ]
weight: 0.02
status: invulnerable

- name: Crate (can be damaged)
weight: 1
at: [ 3, 11 ]

- name: This is medium weight (invulnerable)
weight: 50
at: [ 2, 2 ]
status: invulnerable

- name: This is massive (can be damaged)
weight: 150
at: [ 8, 15 ]

- name: Deploy this (can be damaged)
weight: 20

- name: Deploy this 2 (invulnerable)
weight: 3
status: invulnerable


2 changes: 1 addition & 1 deletion megamek/docs/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ MEGAMEK VERSION HISTORY:
+ Fix #5796: Prevent NPE when units are ineligible for Physical Attack phase due to having loaded onto a transport this round
+ Fix #5818: correct issue with minimap autodisplay using wrong function
+ PR #5822: Implement RFE 5361: enhance Princess handling of hazardous terrain
+ Issues #2577, #897, #353: Implement placeable/carryable cargo objects (for mechs and protomechs only at the moment) (Carry Objects #5706)
+ Issues #2577, #897, #353: Implement placeable/carryable cargo objects (for mechs and protomechs only at the moment) (Carry Objects #5706, #5816)
+ PR #5839: The Heavy Lifter pilot ability is now implemented
+ Fix #5811, #5831: Updates to unit validation (Heavy Gauss Rifles and RISC Hyper Laser vs. engines), allow Illegal Design quirk to validate illegal units
+ Fix #5769: Possibly fix ID overlap when reinforcing from MUL
Expand Down
44 changes: 44 additions & 0 deletions megamek/src/megamek/common/AbstractGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public abstract class AbstractGame implements IGame {

protected int turnIndex = AWAITING_FIRST_TURN;

/**
* Piles of carry-able objects, sorted by coordinates
*/
protected Map<Coords, List<ICarryable>> groundObjects = new HashMap<>();

@Override
public Forces getForces() {
return forces;
Expand Down Expand Up @@ -351,4 +356,43 @@ public boolean hasBoard(@Nullable BoardLocation boardLocation) {
public boolean hasBoard(int boardId) {
return gameBoards.containsKey(boardId);
}

/**
* Place a carryable object on the ground at the given coordinates
*/
public void placeGroundObject(Coords coords, ICarryable carryable) {
getGroundObjects().computeIfAbsent(coords, k -> new ArrayList<>()).add(carryable);
}

/**
* Remove the given carryable object from the ground at the given coordinates
*/
public void removeGroundObject(Coords coords, ICarryable carryable) {
if (getGroundObjects().containsKey(coords)) {
getGroundObjects().get(coords).remove(carryable);
}
}

/**
* Get a list of all the objects on the ground at the given coordinates
* guaranteed to return non-null, but may return empty list
*/
public List<ICarryable> getGroundObjects(Coords coords) {
return getGroundObjects().getOrDefault(coords, new ArrayList<>());
}

/**
* @return Collection of objects on the ground. Best to use getGroundObjects(Coords)
* if looking for objects in specific hex
*/
public Map<Coords, List<ICarryable>> getGroundObjects() {
return groundObjects;
}

/**
* @param groundObjects the groundObjects to set
*/
public void setGroundObjects(Map<Coords, List<ICarryable>> groundObjects) {
this.groundObjects = groundObjects;
}
}
22 changes: 12 additions & 10 deletions megamek/src/megamek/common/Briefcase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/

package megamek.common;

import java.io.Serializable;
Expand All @@ -25,29 +24,30 @@
* Represents a basic carryable object with no additional other properties
*/
public class Briefcase implements ICarryable, Serializable {
/**
*
*/
private static final long serialVersionUID = 8849879320465375457L;

private double tonnage;
private String name;
private boolean invulnerable;
private int id;
private int ownerId;

public void damage(double amount) {

@Override
public boolean damage(double amount) {
tonnage -= amount;
return tonnage <= 0;
}

public void setTonnage(double value) {
tonnage = value;
}


@Override
public double getTonnage() {
return tonnage;
}


@Override
public boolean isInvulnerable() {
return invulnerable;
}
Expand All @@ -59,11 +59,13 @@ public void setInvulnerable(boolean value) {
public void setName(String value) {
name = value;
}


@Override
public String generalName() {
return name;
}


@Override
public String specificName() {
return name + " (" + tonnage + " tons)";
}
Expand Down
85 changes: 21 additions & 64 deletions megamek/src/megamek/common/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ public final class Game extends AbstractGame implements Serializable, PlanetaryC
*/
private Map<String, BehaviorSettings> botSettings = new HashMap<>();

/**
* Piles of carry-able objects, sorted by coordinates
*/
private Map<Coords, List<ICarryable>> groundObjects = new HashMap<>();

/**
* Constructor
*/
Expand Down Expand Up @@ -3285,78 +3280,40 @@ public Map<String, BehaviorSettings> getBotSettings() {
public void setBotSettings(Map<String, BehaviorSettings> botSettings) {
this.botSettings = botSettings;
}

/**
* Place a carryable object on the ground at the given coordinates
*/
public void placeGroundObject(Coords coords, ICarryable carryable) {
if (!getGroundObjects().containsKey(coords)) {
getGroundObjects().put(coords, new ArrayList<>());
}

getGroundObjects().get(coords).add(carryable);
}

/**
* Remove the given carryable object from the ground at the given coordinates
*/
public void removeGroundObject(Coords coords, ICarryable carryable) {
if (getGroundObjects().containsKey(coords)) {
getGroundObjects().get(coords).remove(carryable);
}
}

/**
* Get a list of all the objects on the ground at the given coordinates
* guaranteed to return non-null, but may return empty list
*/
public List<ICarryable> getGroundObjects(Coords coords) {
return getGroundObjects().containsKey(coords) ? getGroundObjects().get(coords) : new ArrayList<>();
}

/**
* Get a list of all objects on the ground at the given coordinates
* that can be picked up by the given entity
*/
public List<ICarryable> getGroundObjects(Coords coords, Entity entity) {
if (!getGroundObjects().containsKey(coords)) {
return new ArrayList<>();
}
// if the entity doesn't have working actuators etc
if (!entity.canPickupGroundObject()) {
return new ArrayList<>();
}
double maxTonnage = entity.maxGroundObjectTonnage();
ArrayList<ICarryable> result = new ArrayList<>();
for (ICarryable object : getGroundObjects().get(coords)) {
if (maxTonnage >= object.getTonnage()) {
result.add(object);
}
}
return result;
if (!getGroundObjects().containsKey(coords)) {
return new ArrayList<>();
}

// if the entity doesn't have working actuators etc
if (!entity.canPickupGroundObject()) {
return new ArrayList<>();
}

double maxTonnage = entity.maxGroundObjectTonnage();
ArrayList<ICarryable> result = new ArrayList<>();

for (ICarryable object : getGroundObjects().get(coords)) {
if (maxTonnage >= object.getTonnage()) {
result.add(object);
}
}

return result;
}

/**
* @return Collection of objects on the ground. Best to use getGroundObjects(Coords)
* if looking for objects in specific hex
*/
public Map<Coords, List<ICarryable>> getGroundObjects() {
// this is a temporary guard to preserve savegame compatibility. Remove after this entire override after .50
if (groundObjects == null) {
groundObjects = new HashMap<>();
}

return groundObjects;
}

/**
* @param groundObjects the groundObjects to set
*/
public void setGroundObjects(Map<Coords, List<ICarryable>> groundObjects) {
this.groundObjects = groundObjects;
return groundObjects;
}

/**
Expand Down
30 changes: 27 additions & 3 deletions megamek/src/megamek/common/ICarryable.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,41 @@
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/

package megamek.common;

/**
* An interface defining all the required properties of a carryable object.
*/
public interface ICarryable extends InGameObject {

/**
* @return The weight of the carryable object in units of tons.
*/
double getTonnage();
void damage(double amount);

/**
* Damages this carryable object by the given amount of damage. Returns true if the cargo is considered
* destroyed by applying the damage.
* Note: This method does *not* check if the object is invulnerable; it is up to the caller to do that.
* Calling this method on an invulnerable carryable object behaves exactly like calling it on a vulnerable
* one.
*
* @param amount The damage
* @return True if the cargo is destroyed by the damage, false otherwise
* @see #getTonnage()
*/
boolean damage(double amount);

/**
* Returns true if this carryable object should never take damage nor be destroyed, false otherwise.
* Note that the carryable object does *not* itself enforce this; it is up to the caller of
* {@link #damage(double)} to test it.
*
* @return True if this carryable object cannot be damaged
*/
boolean isInvulnerable();


@Override
default boolean isCarryableObject() {
return true;
}
Expand Down
Loading

0 comments on commit 6696ed3

Please sign in to comment.