From e57c5446439a2589c49e347fffadab1d6a1528d2 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 13 Nov 2013 21:17:29 +0000 Subject: [PATCH] (svn r25977) [1.3] -Backport from trunk: - Fix: [Script] Do not return ERR_UNKNOWN when trying to move an order to its current location [FS#5648] (r25612) - Fix: Various misreferences in AI and GS changelog [FS#5649] (r25607) - Fix: [Script] If a NewGRF returned station type that could not be built by an AI via callback 18, an unknown error would be thrown instead of falling back to the default station [FS#5641] (r25605) - Fix: Only the front engine's date of last service was updated [FS#5550] (r25604) --- src/fontcache.cpp | 2 +- src/script/api/ai_changelog.hpp | 4 ++-- src/script/api/script_order.cpp | 1 + src/script/api/script_order.hpp | 1 + src/script/api/script_rail.cpp | 5 +++-- src/vehicle.cpp | 20 +++++++++++++++----- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 8127899629..9e0fd1e166 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -80,7 +80,7 @@ public: virtual uint GetGlyphWidth(GlyphID key); virtual bool GetDrawGlyphShadow(); virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; } - virtual const void *GetFontTable(uint32 tag, size_t &length) { printf("%p\n", &length); length = 0; return NULL; } + virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return NULL; } }; /** diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index 5a2eb1a918..4338c29a3e 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -72,10 +72,10 @@ * \li AIOrder::SetOrderRefit * \li AIRail::GetMaintenanceCostFactor * \li AIRoad::GetMaintenanceCostFactor + * \li AITile::GetTownAuthority * \li AITown::GetCargoGoal * \li AITown::GetGrowthRate * \li AITown::GetLastMonthReceived - * \li AITown::GetTownAuthority * \li AITownEffectList (to walk over all available town effects) * \li AIVehicle::ERR_VEHICLE_TOO_LONG in case vehicle length limit is reached * \li AIVehicle::GetMaximumOrderDistance @@ -95,7 +95,7 @@ * Other changes: * \li AITown::GetLastMonthProduction no longer has prerequisites based on town * effects. - * \li AITown::GetLastMonthTransported no longer has prerequisites based on + * \li AITown::GetLastMonthTransported resp. AITown::GetLastMonthSupplied no longer has prerequisites based on * town effects. * \li AITown::GetLastMonthTransportedPercentage no longer has prerequisites * based on town effects. diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp index 8b55cabb4b..3087caa651 100644 --- a/src/script/api/script_order.cpp +++ b/src/script/api/script_order.cpp @@ -627,6 +627,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance) EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_move)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_target)); + EnforcePrecondition(false, order_position_move != order_position_target); int order_pos_move = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_move); int order_pos_target = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_target); diff --git a/src/script/api/script_order.hpp b/src/script/api/script_order.hpp index 68702afdb0..63089a2bd4 100644 --- a/src/script/api/script_order.hpp +++ b/src/script/api/script_order.hpp @@ -524,6 +524,7 @@ public: * @param order_position_target The target order * @pre IsValidVehicleOrder(vehicle_id, order_position_move). * @pre IsValidVehicleOrder(vehicle_id, order_position_target). + * @pre order_position_move != order_position_target. * @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY * @return True if and only if the order was moved. * @note If the order is moved to a lower place (e.g. from 7 to 2) diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index fd1e3e920c..161007de96 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -186,10 +186,11 @@ if (spec == NULL) { DEBUG(grf, 1, "%s returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename); } else { - p2 |= spec->cls_id | index << 8; + /* We might have gotten an usable station spec. Try to build it, but if it fails we'll fall back to the original station. */ + if (ScriptObject::DoCommand(tile, p1, p2 | spec->cls_id | index << 8, CMD_BUILD_RAIL_STATION)) return true; } - } + return ScriptObject::DoCommand(tile, p1, p2, CMD_BUILD_RAIL_STATION); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 6fc5c906ab..f4376ce7b5 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -87,14 +87,24 @@ bool Vehicle::NeedsAutorenewing(const Company *c, bool use_renew_setting) const return true; } +/** + * Service a vehicle and all subsequent vehicles in the consist + * + * @param *v The vehicle or vehicle chain being serviced + */ void VehicleServiceInDepot(Vehicle *v) { - v->date_of_last_service = _date; - v->breakdowns_since_last_service = 0; - v->reliability = v->GetEngine()->reliability; - /* Prevent vehicles from breaking down directly after exiting the depot. */ - v->breakdown_chance /= 4; + assert(v != NULL); SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated + + do { + v->date_of_last_service = _date; + v->breakdowns_since_last_service = 0; + v->reliability = v->GetEngine()->reliability; + /* Prevent vehicles from breaking down directly after exiting the depot. */ + v->breakdown_chance /= 4; + v = v->Next(); + } while (v != NULL && v->HasEngineType()); } /**