Skip to content

Commit

Permalink
aftermerge corrections, ICarryable comments and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Aug 2, 2024
1 parent 8cf3049 commit 7c8330c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 42 deletions.
8 changes: 4 additions & 4 deletions megamek/src/megamek/common/AbstractGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,15 @@ public boolean hasBoard(int boardId) {
* Place a carryable object on the ground at the given coordinates
*/
public void placeGroundObject(Coords coords, ICarryable carryable) {
groundObjects.computeIfAbsent(coords, k -> new ArrayList<>()).add(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 (groundObjects.containsKey(coords)) {
groundObjects.get(coords).remove(carryable);
if (getGroundObjects().containsKey(coords)) {
getGroundObjects().get(coords).remove(carryable);
}
}

Expand All @@ -378,7 +378,7 @@ public void removeGroundObject(Coords coords, ICarryable carryable) {
* guaranteed to return non-null, but may return empty list
*/
public List<ICarryable> getGroundObjects(Coords coords) {
return groundObjects.getOrDefault(coords, new ArrayList<>());
return getGroundObjects().getOrDefault(coords, new ArrayList<>());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion megamek/src/megamek/common/Briefcase.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public class Briefcase implements ICarryable, Serializable {
private int id;
private int ownerId;

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

public void setTonnage(double value) {
Expand Down
33 changes: 1 addition & 32 deletions megamek/src/megamek/common/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -3280,35 +3280,7 @@ 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
Expand All @@ -3335,11 +3307,8 @@ public List<ICarryable> getGroundObjects(Coords coords, Entity entity) {
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<>();
}
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, detracting the given amount of damage from the weight of the carryable object.
* Returns true if the cargo is considered destroyed by applying the damage.
* Note: This method does *not* check if the object is invulnerable; this must be tested by the caller.
* Calling this method on an invulnerable carryable object behaves exactly like calling it on a vulnerable
* one.
*
* @param amount The damage (a weight to remove in tons)
* @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
4 changes: 2 additions & 2 deletions megamek/src/megamek/server/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21292,12 +21292,12 @@ public Vector<Report> damageEntity(Entity te, HitData hit, int damage,
}

double tonnage = cargo.getTonnage();
cargo.damage(damageLeftToCargo);
boolean cargoDestroyed = cargo.damage(damageLeftToCargo);
damageLeftToCargo -= Math.ceil(tonnage);

// if we have destroyed the cargo, remove it, add a report
// and move on to the next piece of cargo
if (cargo.getTonnage() <= 0) {
if (cargoDestroyed) {
te.dropGroundObject(cargo, false);

r = new Report(6721);
Expand Down

0 comments on commit 7c8330c

Please sign in to comment.