setDesiredRangeTo: 15000
scanForNearestShipWithPrimaryRole: player
Result: He found me and started his work as soon as he appeared on my scanner. Far beyond 15000 meters.
I tried to reverse the order (first the scanFor..., then setDesired...), as in many of the default AIs. Same result. I was found way before I reached the specified distance.
In the end I resorted to setting his scanner_range in shipdata. That works. He is now spotting me only if I am closer than 15000 meters.
But it seems to me now that setDesiredRangeTo does not do what it's intended for. At least not in connection with the scan-method.
setDesiredRangeTo: 15000
scanForNearestShipWithPrimaryRole: player
Result: He found me and started his work as soon as he appeared on my scanner. Far beyond 15000 meters.
I tried to reverse the order (first the scanFor..., then setDesired...), as in many of the default AIs. Same result. I was found way before I reached the specified distance.
In the end I resorted to setting his scanner_range in shipdata. That works. He is now spotting me only if I am closer than 15000 meters.
But it seems to me now that setDesiredRangeTo does not do what it's intended for. At least not in connection with the scan-method.
scanForNearestShipWithPrimaryRole uses the entire scanner range to perform its checks. It does not matter what you set desired range to, as this is not used when scanning for ships. This is hardcoded behaviour and as far as I can tell, it works as expected.
Result: He found me and started his work as soon as he appeared on my scanner. Far beyond 15000 meters.....But it seems to me now that setDesiredRangeTo does not do what it's intended for. At least not in connection with the scan-method.
A_C is right. it wont work this way. But now we have ship scripts. Those can do almost everything.
Other way around, surely? Also, “this.ship.target = player” is sufficient. I don’t think there’s any context where using the ID is actually useful, and I expect to remove it.
I don’t think there’s any context where using the ID is actually useful, and I expect to remove it.
In some situations the “player.target = this.ship” didn't work and “player.target = this.ship.Id” did work! That were test with 1.70.
And this week I created a function:
When I transferred the ship as identity I could only access the first element in the array. Probably I do something wrong. It was very strange. With the debug oxp I could list all array elements. They look all the same but when I called for the properties I only could get them from the first. With the next it said that there were no properties.
I could not find the bug and choose the easiest solution: just storing the ID numbers. For me it was enough.
scanForNearestShipWithPrimaryRole uses the entire scanner range to perform its checks. It does not matter what you set desired range to, as this is not used when scanning for ships. This is hardcoded behaviour and as far as I can tell, it works as expected.
Oh, I see. Then it was just my mistake to assume that all scan...-methods need a desired range. (In the OXP howto AI at least scanForNearestMerchantmen and scanForNearestShipWithRole are listed in the Locating Entities-section, which in its header says:
All these methods require a range to be set by setDesiredRange or by <scanner_range> in shipdata.plist,
I assumed (obviously mistakenly) that the same would be the case for all scan-methods, especially for scanForNearestShipWithPrimaryRole, which is something like the successor of scanForNearestShipWithRole.
scanForNearestShipWithRole: is an alias for scanForNearestShipWithPrimaryRole: these days. The wiki is wrong; scanForNearestShipWithRole: does not respect setDesiredRangeTo: and never did (or at least, didn’t in 1.65).
The desired range is used in scanForNearestMerchantmen, checkCourseToDestination, checkDistanceTravelled, dealEnergyDamageWithinDesiredRange, and various AI behaviour states, namely BEHAVIOUR_INTERCEPT_TARGET, BEHAVIOUR_FLEE_TARGET, BEHAVIOUR_FLY_RANGE_FROM_DESTINATION, BEHAVIOUR_FLY_FROM_DESTINATION, BEHAVIOUR_FACE_DESTINATION, BEHAVIOUR_FORMATION_FORM_UP (performEscort), BEHAVIOUR_AVOID_COLLISION, BEHAVIOUR_FLY_THRU_NAVPOINTS. Many things, including some of the listed AI states, also change the desired range.