Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -71,6 +71,7 @@ public abstract class AEntityVehicleE_Powered extends AEntityVehicleD_Moving {
//Map containing incoming missiles and radar info, sorted by distance.
public final List<EntityBullet> missilesIncoming = new ArrayList<>();
public final List<AEntityD_Definable<?>> radarsTracking = new ArrayList<>();
public final List<PartGun> gunsLockedOn = new ArrayList<>();

public AEntityVehicleE_Powered(AWrapperWorld world, IWrapperPlayer placingPlayer, ItemVehicle item, IWrapperNBT data) {
super(world, placingPlayer, item, data);
Expand Down Expand Up @@ -197,6 +198,7 @@ public void update() {

//Check to make sure we are still being tracked.
radarsTracking.removeIf(tracker -> !tracker.isValid || (!tracker.aircraftOnRadar.contains(this) && !tracker.groundersOnRadar.contains(this)));
gunsLockedOn.removeIf(gun -> !gun.isValid || (gun.engineTarget != null && gun.engineTarget.vehicleOn != this));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this condition, what if the gun's engine target is null (doesn't exist). This logic will not remove it since it returns false.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a commit that changed it a little


//If we are supposed to de-spawn, do so.
if (outOfHealth && ConfigSystem.settings.general.vehicleDeathDespawnTime.value > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,8 @@ public ComputedVariable createComputedVariable(String variable, boolean createDe
return new ComputedVariable(this, variable, partialTicks -> radarsTracking.isEmpty() ? 0 : 1, false);
case ("missile_incoming"):
return new ComputedVariable(this, variable, partialTicks -> missilesIncoming.isEmpty() ? 0 : 1, false);
case ("missile_lockedonto"):
return new ComputedVariable(this, variable, partialTicks -> gunsLockedOn.isEmpty() ? 0 : 1, false);
default: {
//Missile incoming variables.
//Variable is in the form of missile_X_variablename.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public class PartGun extends APart {
private final Point3D normalizedConeVector = new Point3D();
private final Point3D normalizedEntityVector = new Point3D();

//Track previous targets to detect changes for registration
private PartEngine prevEngineTarget = null;
private IWrapperEntity prevEntityTarget = null;

//Global data.
private static final int RAYTRACE_DISTANCE = 750;
private static final double DEFAULT_CONE_ANGLE = 2.0;
Expand Down Expand Up @@ -333,6 +337,7 @@ public void update() {
currentController = null;
entityTarget = null;
engineTarget = null;
updateTargetRegistration();
}
}
}
Expand Down Expand Up @@ -390,6 +395,7 @@ public void update() {
currentController = null;
entityTarget = null;
engineTarget = null;
updateTargetRegistration();
}
}

Expand Down Expand Up @@ -598,6 +604,7 @@ public void update() {
state = GunState.INACTIVE;
entityTarget = null;
engineTarget = null;
updateTargetRegistration();
if (resetPosition) {
handleMovement(defaultYaw - internalOrientation.angles.y, defaultPitch - internalOrientation.angles.x);
}
Expand Down Expand Up @@ -788,6 +795,7 @@ private void handleControl(IWrapperEntity controller) {
}
} else {
entityTarget = null;
updateTargetRegistration();
state = state.demote(GunState.CONTROLLED);
}
} else {
Expand Down Expand Up @@ -839,6 +847,7 @@ private void handleControl(IWrapperEntity controller) {
//First set targets to null to clear any existing targets.
engineTarget = null;
entityTarget = null;
updateTargetRegistration();

//If we have a start point, it means we're a cone-based target system and need to find a target.
if (startPoint != null) {
Expand Down Expand Up @@ -900,6 +909,7 @@ private void handleControl(IWrapperEntity controller) {
}
}
}
updateTargetRegistration();
}
}

Expand Down Expand Up @@ -1342,6 +1352,43 @@ public double getLeadAngleY() {
return angle;
}

/**
* Registers this gun with the target vehicle's gunsLockedOn list.
*/
private void registerWithTargetVehicle() {
// Only register if we're locking onto a vehicle (via engineTarget)
if (engineTarget != null && engineTarget.vehicleOn != null && engineTarget.vehicleOn != vehicleOn) {
AEntityVehicleE_Powered targetVehicle = engineTarget.vehicleOn;
if (!targetVehicle.gunsLockedOn.contains(this)) {
targetVehicle.gunsLockedOn.add(this);
}
}
}

/**
* Unregisters this gun from the previous target vehicle's gunsLockedOn list.
*/
private void unregisterFromPreviousTargetVehicle() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I don't see a need to have this, and the code that checks for the gun states to run at the same time. Either the gun can handle registeration internally when things change, or it won't handle it and the vehicle should. Is there a reason you have it check for gun targeting on the vehicle? Did something get de-synced during testing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nuked it and it seems to work fine both singleplayer and dedicated server

// Unregister from previous engine target vehicle
if (prevEngineTarget != null && prevEngineTarget.vehicleOn != null && prevEngineTarget.vehicleOn != vehicleOn) {
prevEngineTarget.vehicleOn.gunsLockedOn.remove(this);
}
}

/**
* Updates target registration. Call this whenever entityTarget or engineTarget changes.
*/
private void updateTargetRegistration() {
// Check if engine target changed
if (engineTarget != prevEngineTarget) {
unregisterFromPreviousTargetVehicle();
prevEngineTarget = engineTarget;
registerWithTargetVehicle();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final request here. I see that you put this code into a sub-routine, but that doesn't get called from anywhere else. I feel it would be cleaner to just put that sub-routine code here. Once that's done this should be good to merge.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is called for though? Or did i misunderstand you?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

}
// Note: entityTarget targets are players/mobs, not vehicles, so we don't register for those
prevEntityTarget = entityTarget;
}

@Override
public ComputedVariable createComputedVariable(String variable, boolean createDefaultIfNotPresent) {
switch (variable) {
Expand Down