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

Dumper equipment update #4613

Merged
merged 3 commits into from
Jul 10, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
1
</BlockVersion>

# Write the version number just in case...
##Write the version number just in case...
<Version>
MAM0
</Version>
Expand All @@ -16,9 +16,9 @@ LargeSupportTank
Brunel Dump Truck
</Name>

<model>
<Model>

</model>
</Model>

<mul id:>
3866
Expand All @@ -28,6 +28,10 @@ Brunel Dump Truck
2637
</year>

<originalBuildYear>
2637
</originalBuildYear>

<type>
IS Level 3
</type>
Expand All @@ -36,6 +40,9 @@ IS Level 3
Wheeled
</motion_type>

<transporters>
</transporters>

<cruiseMP>
3
</cruiseMP>
Expand All @@ -44,14 +51,6 @@ Wheeled
1
</engine_type>

<fuel>
4
</fuel>

<barrating>
6
</barrating>

<armor>
21
13
Expand All @@ -61,14 +60,6 @@ Wheeled
10
</armor>

<structural_tech_rating>
3
</structural_tech_rating>

<armor_tech_rating>
2
</armor_tech_rating>

<Body Equipment>
ISOffRoadChassis
</Body Equipment>
Expand All @@ -91,16 +82,42 @@ Backhoe

<Rear Equipment>
Dumper (Rear)
Cargo:SIZE:50.0
</Rear Equipment>

<tonnage>
150.0
</tonnage>
<barrating>
6
</barrating>

<source>
TRO: Vehicle Annex (Revised)
</source>
<structural_tech_rating>
3
</structural_tech_rating>

<engine_tech_rating>
3
</engine_tech_rating>

<armor_tech_rating>
2
</armor_tech_rating>

<history>
Armor is based on fluff. No Record Sheet available.
</history>

<source>
TRO: Vehicle Annex (Revised)
</source>

<tonnage>
150.0
</tonnage>

<fuel>
4.0
</fuel>

<fuelType>
PETROCHEMICALS
</fuelType>

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
1
</BlockVersion>

# Write the version number just in case...
##Write the version number just in case...
<Version>
MAM0
</Version>
Expand All @@ -16,9 +16,9 @@ SupportTank
Lesseps Dump Truck
</Name>

<model>
<Model>

</model>
</Model>

<mul id:>
4499
Expand All @@ -28,6 +28,10 @@ Lesseps Dump Truck
2523
</year>

<originalBuildYear>
2523
</originalBuildYear>

<type>
IS Level 3
</type>
Expand All @@ -36,6 +40,9 @@ IS Level 3
Wheeled
</motion_type>

<transporters>
</transporters>

<cruiseMP>
3
</cruiseMP>
Expand All @@ -44,25 +51,13 @@ Wheeled
11
</engine_type>

<fuel>
4
</fuel>

<armor>
28
19
19
12
</armor>

<barrating>
5
</barrating>

<structural_tech_rating>
3
</structural_tech_rating>

<Body Equipment>
ISOffRoadChassis
</Body Equipment>
Expand All @@ -79,11 +74,24 @@ Backhoe

<Rear Equipment>
Dumper (Rear)
Cargo:SIZE:20.0
</Rear Equipment>

<transporters>
cargobay:20:1
</transporters>
<barrating>
5
</barrating>

<structural_tech_rating>
3
</structural_tech_rating>

<engine_tech_rating>
3
</engine_tech_rating>

<armor_tech_rating>
3
</armor_tech_rating>

<source>
TRO: Vehicle Annex (Revised)
Expand All @@ -92,3 +100,8 @@ TRO: Vehicle Annex (Revised)
<tonnage>
50.0
</tonnage>

<fuel>
4.0
</fuel>

1 change: 1 addition & 0 deletions megamek/src/megamek/common/EquipmentTypeLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public class EquipmentTypeLookup {
@EquipmentName public static final String WRECKING_BALL = "IS Wrecking Ball";
@EquipmentName public static final String LAM_FUEL_TANK = "LAM Fuel Tank";
@EquipmentName public static final String LAM_BOMB_BAY = "Bomb Bay";
@EquipmentName public static final String CARGO = "Cargo";

@EquipmentName public static final String CL_BA_MORTAR_HEAVY = "CLBAHeavyMortar";
@EquipmentName public static final String CL_BA_MORTAR_LIGHT = "CLBALightMortar";
Expand Down
29 changes: 29 additions & 0 deletions megamek/src/megamek/common/MechFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.*;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.zip.ZipFile;

/**
Expand Down Expand Up @@ -778,6 +779,34 @@ else if ((ent instanceof Infantry) && ((Infantry) ent).canMakeAntiMekAttacks())
ent.setCanon(true);
}
ent.initMilitary();
linkDumpers(ent);
}

/**
* Links each Dumper to the first (unlinked) Cargo equipment if there is one in the same location.
* Works only for variable size Cargo, {@link MiscType#createCargo()}, but not Liquid Storage,
* Cargo containers or bays.
*
* @param entity The entity to add links to
*/
static void linkDumpers(Entity entity) {
List<Mounted> dumpers = entity.getMisc().stream()
.filter(mounted -> mounted.getType().hasFlag(MiscType.F_DUMPER)).collect(Collectors.toList());

List<Mounted> cargos = entity.getMisc().stream()
.filter(mounted -> mounted.is(EquipmentTypeLookup.CARGO)).collect(Collectors.toList());
cargos.forEach(cargo -> cargo.setLinkedBy(null));

for (Mounted dumper : dumpers) {
dumper.setLinked(null);
for (Mounted cargo : cargos) {
if ((cargo.getLinkedBy() == null) && (cargo.getLocation() == dumper.getLocation())) {
dumper.setLinked(cargo);
cargo.setLinkedBy(dumper);
break;
}
}
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions megamek/src/megamek/common/MiscType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import megamek.common.weapons.ppc.ISLightPPC;
import megamek.common.weapons.ppc.ISPPC;
import megamek.common.weapons.ppc.ISSnubNosePPC;
import org.apache.logging.log4j.LogManager;

/**
* @author Ben
Expand Down Expand Up @@ -885,7 +886,7 @@ public double getTonnage(Entity entity, int location, double size, RoundWeight d
} else if (hasFlag(F_BA_MISSION_EQUIPMENT)) {
// Size is weight in kg
return RoundWeight.nearestKg(size / 1000.0);
} else if (hasFlag(MiscType.F_RAM_PLATE)) {
} else if (hasFlag(F_RAM_PLATE)) {
return RoundWeight.nextTon(entity.getWeight() / 10.0);
}
// okay, I'm out of ideas
Expand Down Expand Up @@ -7988,7 +7989,7 @@ public static MiscType createCargo() {
MiscType misc = new MiscType();

misc.name = "Cargo";
misc.setInternalName(misc.name);
misc.setInternalName(EquipmentTypeLookup.CARGO);
misc.addLookupName("Cargo (1 ton)");
misc.addLookupName("Cargo (0.5 tons)");
misc.addLookupName("Cargo (1.5 tons)");
Expand Down
8 changes: 4 additions & 4 deletions megamek/src/megamek/common/Mounted.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,11 @@ public double getTonnage() {
*/
public double getTonnage(RoundWeight defaultRounding) {
if ((getType() instanceof MiscType) && getType().hasFlag(MiscType.F_DUMPER)) {
final Bay bay = getEntity().getBayById(getLinkedBayId());
if (bay != null) {
return defaultRounding.round(bay.getCapacity() * 0.05, getEntity());
Mounted cargo = getLinked();
if (cargo != null) {
return defaultRounding.round(cargo.getSize() * 0.05, getEntity());
}
LogManager.getLogger().warn("Found dumper not linked to a cargo bay. Using zero for the weight.");
LogManager.getLogger().warn("Found dumper not linked to a Cargo equipment. Using zero for the weight.");
return 0.0;
}
double retVal = getType().getTonnage(getEntity(), getLocation(), getSize(), defaultRounding);
Expand Down