Class TrainAmmoSharing
canShareAmmoWith(megamek.common.units.Entity, megamek.common.units.Entity) for the ruling.
This is the single definition of which units may supply each other. The client offers exactly this set in the ammo dropdown and the server validates against it, so the two cannot drift apart.
Extracted fromEntity and TWGameManager so the rule does not add to either of those already very
large classes; this mirrors the codebase's other Entity-operating utilities (BridgeLayerLogic,
megamek.common.compute.Compute).-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanShareAmmoWith(Entity shooter, Entity ammoCarrier) Whether one unit may fire another's ammo.static voiddropUncoupledAmmoLinks(Entity entity) Drops any weapon link pointing at ammo the unit may no longer fire, and reloads the weapon from a bin it may still use.static List<AmmoMounted> getSharedAmmo(Entity shooter) static voidrelinkExternalAmmo(Entity entity, Game game) Reconnects weapons linked to another unit's ammo bin after the owning unit has been transferred.
-
Method Details
-
dropUncoupledAmmoLinks
Drops any weapon link pointing at ammo the unit may no longer fire, and reloads the weapon from a bin it may still use.A weapon linked to a trailer's ammo bin keeps that link when the train uncouples, and the firing path never re-checks the coupling:
The replacement is chosen before the stale link is cleared, so a unit that carries the same munition itself keeps firing that munition rather than falling back to whatever sits in its first bin.AmmoWeaponHandler.checkAmmotakes whatevergetLinkedreturns, and the server only consultscanShareAmmoWith(megamek.common.units.Entity, megamek.common.units.Entity)when the player changes ammo. Left alone, a tractor goes on firing a detached trailer's ammo from any distance. Call this on every unit whose train membership changed.- Parameters:
entity- the unit whose weapon links should be re-checked
-
relinkExternalAmmo
Reconnects weapons linked to another unit's ammo bin after the owning unit has been transferred.Packets are Java-serialized object graphs and a
Mountedholds a hard reference to its owning entity, so a weapon linked to a trailer's bin drags a copy of that trailer along with it. The receiving side would otherwise hold a detached duplicate rather than the unit the game knows about. Links to bins the unit owns itself are left alone, and a link whose carrier has left the game is cleared so nothing keeps firing a detached copy.- Parameters:
entity- the unit whose weapon links should be checkedgame- the game holding the canonical units, ornullto do nothing