-
Notifications
You must be signed in to change notification settings - Fork 95
Missile_lockedonto, second attempt #2042
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -333,6 +337,7 @@ public void update() { | |
| currentController = null; | ||
| entityTarget = null; | ||
| engineTarget = null; | ||
| updateTargetRegistration(); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -390,6 +395,7 @@ public void update() { | |
| currentController = null; | ||
| entityTarget = null; | ||
| engineTarget = null; | ||
| updateTargetRegistration(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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); | ||
| } | ||
|
|
@@ -788,6 +795,7 @@ private void handleControl(IWrapperEntity controller) { | |
| } | ||
| } else { | ||
| entityTarget = null; | ||
| updateTargetRegistration(); | ||
| state = state.demote(GunState.CONTROLLED); | ||
| } | ||
| } else { | ||
|
|
@@ -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) { | ||
|
|
@@ -900,6 +909,7 @@ private void handleControl(IWrapperEntity controller) { | |
| } | ||
| } | ||
| } | ||
| updateTargetRegistration(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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() { | ||
|
||
| // 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(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is called for though? Or did i misunderstand you?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| // 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) { | ||
|
|
||

There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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