Schmedium
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package zombie.vehicles;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import zombie.characters.IsoGameCharacter;
|
||||
|
||||
/**
|
||||
* Resolves the effective driver for constraint auth in chained towing.
|
||||
* For middle vehicles in a chain, prefer the front/lead driver's authority.
|
||||
* For middle vehicles in a chain, scan through links so long trains still resolve authority.
|
||||
*/
|
||||
public final class LandtrainConstraintAuthHelper {
|
||||
private LandtrainConstraintAuthHelper() {
|
||||
@@ -15,24 +17,49 @@ public final class LandtrainConstraintAuthHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
IsoGameCharacter driver = vehicle.getDriver();
|
||||
if (driver != null) {
|
||||
return driver;
|
||||
}
|
||||
IsoGameCharacter driver = findDriverAlongChain(vehicle, true);
|
||||
if (driver != null) return driver;
|
||||
return findDriverAlongChain(vehicle, false);
|
||||
}
|
||||
|
||||
BaseVehicle front = vehicle.getVehicleTowedBy();
|
||||
if (front != null) {
|
||||
driver = front.getDriver();
|
||||
private static IsoGameCharacter findDriverAlongChain(BaseVehicle start, boolean towardFront) {
|
||||
BaseVehicle cursor = start;
|
||||
Set<Integer> visited = new HashSet<>();
|
||||
|
||||
while (cursor != null) {
|
||||
int id = cursor.getId();
|
||||
if (!visited.add(id)) {
|
||||
// Safety: malformed link graph; stop scanning.
|
||||
return null;
|
||||
}
|
||||
|
||||
IsoGameCharacter driver = cursor.getDriver();
|
||||
if (driver != null) {
|
||||
return driver;
|
||||
}
|
||||
}
|
||||
|
||||
BaseVehicle rear = vehicle.getVehicleTowing();
|
||||
if (rear != null) {
|
||||
return rear.getDriver();
|
||||
cursor = towardFront ? cursor.getVehicleTowedBy() : cursor.getVehicleTowing();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isEnterBlockedLandtrain(
|
||||
BaseVehicle vehicle, IsoGameCharacter chr, int seat) {
|
||||
if (isVehicleBeingTowedInLandtrain(vehicle)) {
|
||||
return true;
|
||||
}
|
||||
return vehicle != null && vehicle.isExitBlocked(chr, seat);
|
||||
}
|
||||
|
||||
public static boolean isEnterBlocked2Landtrain(BaseVehicle vehicle, int seat) {
|
||||
if (isVehicleBeingTowedInLandtrain(vehicle)) {
|
||||
return true;
|
||||
}
|
||||
return vehicle != null && vehicle.isExitBlocked2(seat);
|
||||
}
|
||||
|
||||
private static boolean isVehicleBeingTowedInLandtrain(BaseVehicle vehicle) {
|
||||
return vehicle != null && vehicle.getVehicleTowedBy() != null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user