From 2ef15dfb84ebaab1dbf274a8c5e32092045bc590 Mon Sep 17 00:00:00 2001 From: cim Date: Sun, 29 Jun 2014 17:08:34 +0100 Subject: [PATCH 1/3] Try again to fix docking code --- Resources/Scripts/oolite-populator.js | 1 + Resources/Scripts/oolite-priorityai.js | 27 +++++++++++++++++++++++++- src/Core/Entities/DockEntity.m | 2 +- src/Core/Entities/StationEntity.m | 4 ++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Resources/Scripts/oolite-populator.js b/Resources/Scripts/oolite-populator.js index 659db1b1..1a9e3faa 100644 --- a/Resources/Scripts/oolite-populator.js +++ b/Resources/Scripts/oolite-populator.js @@ -1336,6 +1336,7 @@ this._addFreighter = function(pos) t[0].homeSystem = system.ID; t[0].destinationSystem = this._weightedNearbyTradeSystem(); goods = "PLENTIFUL_GOODS"; + t[0].fuel = 7; } else { diff --git a/Resources/Scripts/oolite-priorityai.js b/Resources/Scripts/oolite-priorityai.js index ffa7c4a3..ea60e47e 100644 --- a/Resources/Scripts/oolite-priorityai.js +++ b/Resources/Scripts/oolite-priorityai.js @@ -2947,6 +2947,21 @@ PriorityAIController.prototype.behaviourDockWithStation = function() this.ship.performFaceDestination(); // and will reconsider in a little bit break; + case "TRY_AGAIN_LATER": + if (this.distance(station) < 5000) + { + if (this.__ltcache.oolite_dockingclearpos) + { + this.ship.destination = this.__ltcache.oolite_dockingclearpos; + } + else + { + this.ship.destination = station.position.add(Vector3D.randomDirection(8000+station.collisionRadius)); + this.__ltcache.oolite_dockingclearpos = this.ship.destination; + } + } + this.ship.performFlyToRangeFromDestination(); + break; case "APPROACH_COORDINATES": if (this.ship.escortGroup && this.ship.escortGroup.count > 1) { @@ -2960,7 +2975,6 @@ PriorityAIController.prototype.behaviourDockWithStation = function() // and fall through case "APPROACH": case "BACK_OFF": - case "TRY_AGAIN_LATER": this.ship.performFlyToRangeFromDestination(); break; } @@ -4845,6 +4859,7 @@ PriorityAIController.prototype.responsesAddDocking = function(handlers) { handlers.stationWithdrewDockingClearance = this.responseComponent_docking_stationWithdrewDockingClearance; handlers.shipAchievedDesiredRange = this.responseComponent_docking_shipAchievedDesiredRange; + handlers.shipAIFrustrated = this.responseComponent_docking_shipAIFrustrated; } /* Override of standard handlers for use while escorting */ @@ -5912,6 +5927,16 @@ PriorityAIController.prototype.responseComponent_docking_shipAchievedDesiredRang } +PriorityAIController.prototype.responseComponent_docking_shipAIFrustrated = function() +{ + var station = this.getParameter("oolite_dockingStation",null); + station.abortDockingForShip(this.ship); + this.communicate("oolite_abortDocking",{},3); + this.setParameter("oolite_dockingStation",null); + this.reconsiderNow(); +} + + PriorityAIController.prototype.responseComponent_docking_stationWithdrewDockingClearance = function() { this.setParameter("oolite_dockingStation",null); diff --git a/src/Core/Entities/DockEntity.m b/src/Core/Entities/DockEntity.m index 955c3c4f..80c9b549 100644 --- a/src/Core/Entities/DockEntity.m +++ b/src/Core/Entities/DockEntity.m @@ -322,7 +322,7 @@ MA 02110-1301, USA. // some error has occurred - log it, and send the try-again message OOLogERR(@"station.issueDockingInstructions.failed", @"couldn't addShipToShipsOnApproach:%@ in %@, retrying later -- shipsOnApproach:\n%@", ship, self, shipsOnApproach); - return OOMakeDockingInstructions(station, [ship position], 0, 100, @"TRY_AGAIN_LATER", nil, NO, -1); + return OOMakeDockingInstructions(station, [ship position], 200, 100, @"TRY_AGAIN_LATER", nil, NO, -1); } diff --git a/src/Core/Entities/StationEntity.m b/src/Core/Entities/StationEntity.m index af283da4..9272ad7a 100644 --- a/src/Core/Entities/StationEntity.m +++ b/src/Core/Entities/StationEntity.m @@ -581,7 +581,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, } if (chosenDock == nil) { - if (player_is_ahead || ([docking isEqualToString:@"TOO_BIG_TO_DOCK"] && !alldockstoosmall)) + if (player_is_ahead || ([docking isEqualToString:@"TOO_BIG_TO_DOCK"] && !alldockstoosmall) || docking == nil) { // either player is manually docking and we can't allocate new docks, // or the last dock was too small, and there may be an acceptable one @@ -589,7 +589,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, docking = @"TRY_AGAIN_LATER"; } // no docks accept this ship (or the player is blocking them) - return OOMakeDockingInstructions(self, [ship position], 0, 100, docking, nil, NO, -1); + return OOMakeDockingInstructions(self, [ship position], 200, 100, docking, nil, NO, -1); } From 80cc3023799a97f35ce0a754d8ecae7b218cec5c Mon Sep 17 00:00:00 2001 From: cim Date: Sun, 29 Jun 2014 17:19:09 +0100 Subject: [PATCH 2/3] Fix assassin chase routines --- Resources/AIs/oolite-assassinAI.js | 10 +++++----- Resources/Scripts/oolite-priorityai.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Resources/AIs/oolite-assassinAI.js b/Resources/AIs/oolite-assassinAI.js index 032fb20e..f9cdebb0 100644 --- a/Resources/AIs/oolite-assassinAI.js +++ b/Resources/AIs/oolite-assassinAI.js @@ -67,11 +67,6 @@ this.aiStarted = function() { behaviour: ai.behaviourEnterWitchspace, reconsider: 15 }, - { - condition: ai.conditionHasRememberedTarget, - behaviour: ai.behaviourFollowCurrentTarget, - reconsider: 15 - }, /* Check for couriers */ { preconfiguration: ai.configurationCheckScanner, @@ -104,6 +99,11 @@ this.aiStarted = function() { behaviour: ai.behaviourDestroyCurrentTarget, reconsider: 20 }, + { + condition: ai.conditionHasRememberedTarget, + behaviour: ai.behaviourFollowCurrentTarget, + reconsider: 15 + }, { preconfiguration: ai.configurationAppointGroupLeader, condition: ai.conditionIsGroupLeader, diff --git a/Resources/Scripts/oolite-priorityai.js b/Resources/Scripts/oolite-priorityai.js index ea60e47e..fee5cefb 100644 --- a/Resources/Scripts/oolite-priorityai.js +++ b/Resources/Scripts/oolite-priorityai.js @@ -6012,7 +6012,7 @@ PriorityAIController.prototype.responseComponent_expectWitchspace_shipTargetLost { target = this.getParameter("oolite_rememberedTarget"); } - if (target) { + if (target && target.position) { var pos = target.position; var ws = system.wormholes; // most likely to be most recent From c585ac71ddf112cc7860bf46feb6d0ad319c13a9 Mon Sep 17 00:00:00 2001 From: cim Date: Sun, 29 Jun 2014 17:54:27 +0100 Subject: [PATCH 3/3] Fix format string --- src/Core/Entities/PlayerEntity.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index b4d039e6..6f808544 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -9327,7 +9327,7 @@ static NSString *last_outfitting_key=nil; NSString *available = OOPadStringToEms(((available_units > 0) ? (NSString *)[NSString stringWithFormat:@"%d",available_units] : DESC(@"commodity-quantity-none")), 2.5); NSUInteger priceDecimal = pricePerUnit % 10; - NSString *price = [NSString stringWithFormat:@" %@.%u ",OOPadStringToEms([NSString stringWithFormat:@"%lu",(unsigned long)(pricePerUnit/10)],1.5),priceDecimal]; + NSString *price = [NSString stringWithFormat:@" %@.%lu ",OOPadStringToEms([NSString stringWithFormat:@"%lu",(unsigned long)(pricePerUnit/10)],1.5),priceDecimal]; // this works with up to 9999 tons of gemstones. Any more than that, they deserve the formatting they get! :)