From 30cf8d19719b8e7c563521c3eeac00ca4a68eecc Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 7 Mar 2011 19:18:38 +0000 Subject: [PATCH] (svn r22224) [1.1] -Backport from trunk: - Fix: Compilation when compiling with --disable-ai (r22222) - Fix: When downloading a file via HTTP failed mid-way and OpenTTD fell back to the old system the partial downloaded amount would be counted twice [FS#4543] (r22208) - Fix: The 'center' (for movement) of vehicles is (currently still) always at 4/8th original vehicle length from the front, so trains should stop at the same location regardless of the length of the front engine [FS#4545] (r22206) - Fix: Make the base costs for building and demolishing NewObjects also local to the individual NewGRFs (r22204) - Fix: Removing a station order could stop when removing first automatic order (r22200) - Fix: Invalidate the object build window when using the date cheat (r22193) --- src/ai/ai.hpp | 2 +- src/articulated_vehicles.cpp | 2 +- src/cheat_gui.cpp | 1 + src/ground_vehicle.hpp | 2 +- src/network/network_content.cpp | 10 +++++++--- src/network/network_content.h | 4 ++-- src/network/network_content_gui.cpp | 2 +- src/newgrf.cpp | 2 +- src/newgrf_object.h | 4 ++-- src/order_cmd.cpp | 6 ++++-- src/roadveh_cmd.cpp | 8 ++++---- src/table/pricebase.h | 4 ++-- src/train_cmd.cpp | 20 ++++++++++++++------ src/vehicle_type.h | 3 +++ 14 files changed, 44 insertions(+), 26 deletions(-) diff --git a/src/ai/ai.hpp b/src/ai/ai.hpp index 1c61d917fa..73e95efee7 100644 --- a/src/ai/ai.hpp +++ b/src/ai/ai.hpp @@ -168,7 +168,7 @@ public: static void GameLoop() {} static bool HasAI(const struct ContentInfo *ci, bool md5sum) { return false; } static void Rescan() {} - static char *GetConsoleList(char *p, const char *last) { return p; } + static char *GetConsoleList(char *p, const char *last, bool newest_only = false) { return p; } static void nop() { } }; diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 95ec4871a0..0ef4d9bc47 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -328,7 +328,7 @@ void AddArticulatedParts(Vehicle *first) v = rv; rv->subtype = 0; - gcache->cached_veh_length = 8; // Callback is called when the consist is finished + gcache->cached_veh_length = VEHICLE_LENGTH; // Callback is called when the consist is finished rv->state = RVSB_IN_DEPOT; rv->roadtype = front->roadtype; diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 6959689b22..abb8445be6 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -125,6 +125,7 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2) EnginesMonthlyLoop(); SetWindowDirty(WC_STATUS_BAR, 0); InvalidateWindowClassesData(WC_BUILD_STATION, 0); + InvalidateWindowClassesData(WC_BUILD_OBJECT, 0); ResetSignalVariant(); return _cur_year; } diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp index 6beb4e8fd3..941ddca155 100644 --- a/src/ground_vehicle.hpp +++ b/src/ground_vehicle.hpp @@ -42,7 +42,7 @@ struct GroundVehicleCache { /* Cached NewGRF values, recalculated on load and each time a vehicle is added to/removed from the consist. */ uint16 cached_total_length; ///< Length of the whole vehicle (valid only for the first engine). EngineID first_engine; ///< Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself. - uint8 cached_veh_length; ///< Length of this vehicle in units of 1/8 of normal length. It is cached because this can be set by a callback. + uint8 cached_veh_length; ///< Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can be set by a callback. /* Cached UI information. */ uint16 last_speed; ///< The last speed we did display, so we only have to redraw when this changes. diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index e0ff5ab28c..7e52c86545 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -453,7 +453,7 @@ DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT) return false; } - this->OnDownloadProgress(this->curInfo, (uint)toRead); + this->OnDownloadProgress(this->curInfo, (int)toRead); if (toRead == 0) this->AfterDownload(); } @@ -526,6 +526,10 @@ void ClientNetworkContentSocketHandler::OnFailure() this->http_response_index = -2; if (this->curFile != NULL) { + /* Revert the download progress when we are going for the old system. */ + long size = ftell(this->curFile); + if (size > 0) this->OnDownloadProgress(this->curInfo, (int)-size); + fclose(this->curFile); this->curFile = NULL; } @@ -559,7 +563,7 @@ void ClientNetworkContentSocketHandler::OnReceiveData(const char *data, size_t l this->OnFailure(); } else { /* Just received the data. */ - this->OnDownloadProgress(this->curInfo, (uint)length); + this->OnDownloadProgress(this->curInfo, (int)length); } /* Nothing more to do now. */ return; @@ -1023,7 +1027,7 @@ void ClientNetworkContentSocketHandler::OnReceiveContentInfo(const ContentInfo * } } -void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, uint bytes) +void ClientNetworkContentSocketHandler::OnDownloadProgress(const ContentInfo *ci, int bytes) { for (ContentCallback **iter = this->callbacks.Begin(); iter != this->callbacks.End(); /* nothing */) { ContentCallback *cb = *iter; diff --git a/src/network/network_content.h b/src/network/network_content.h index 779f94ea0d..4239a005f7 100644 --- a/src/network/network_content.h +++ b/src/network/network_content.h @@ -49,7 +49,7 @@ struct ContentCallback { * @param ci the content info of the file * @param bytes the number of bytes downloaded since the previous call */ - virtual void OnDownloadProgress(const ContentInfo *ci, uint bytes) {} + virtual void OnDownloadProgress(const ContentInfo *ci, int bytes) {} /** * We have finished downloading a file @@ -89,7 +89,7 @@ protected: void OnConnect(bool success); void OnDisconnect(); void OnReceiveContentInfo(const ContentInfo *ci); - void OnDownloadProgress(const ContentInfo *ci, uint bytes); + void OnDownloadProgress(const ContentInfo *ci, int bytes); void OnDownloadComplete(ContentID cid); void OnFailure(); diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 70cc0d8a1f..ee3a325d9f 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -175,7 +175,7 @@ public: } } - virtual void OnDownloadProgress(const ContentInfo *ci, uint bytes) + virtual void OnDownloadProgress(const ContentInfo *ci, int bytes) { if (ci->id != this->cur_id) { strecpy(this->name, ci->filename, lastof(this->name)); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 6d99789842..bc150ff2dd 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -6901,7 +6901,7 @@ static bool HandleNode(byte type, uint32 id, ByteReader *buf, AllowedSubtags sub } } } - grfmsg(2, "StaticGRFInfo: unkown type/id combination found, type=%c, id=%x", type, id); + grfmsg(2, "StaticGRFInfo: unknown type/id combination found, type=%c, id=%x", type, id); return SkipUnknownInfo(buf, type); } diff --git a/src/newgrf_object.h b/src/newgrf_object.h index 1c023a7a02..243d0f3a33 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -74,13 +74,13 @@ struct ObjectSpec { * Get the cost for building a structure of this type. * @return The cost for building. */ - Money GetBuildCost() const { return (_price[PR_BUILD_OBJECT] * this->build_cost_multiplier); } + Money GetBuildCost() const { return GetPrice(PR_BUILD_OBJECT, this->build_cost_multiplier, this->grf_prop.grffile, 0); } /** * Get the cost for clearing a structure of this type. * @return The cost for clearing. */ - Money GetClearCost() const { return (_price[PR_CLEAR_OBJECT] * this->clear_cost_multiplier); } + Money GetClearCost() const { return GetPrice(PR_CLEAR_OBJECT, this->clear_cost_multiplier, this->grf_prop.grffile, 0); } bool IsAvailable() const; uint Index() const; diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index ccfb330dbe..f7ed91158d 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1637,6 +1637,7 @@ void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination) int id = -1; FOR_VEHICLE_ORDERS(v, order) { id++; +restart: OrderType ot = order->GetType(); if (ot == OT_GOTO_DEPOT && (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) continue; @@ -1646,9 +1647,10 @@ void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination) * dummy orders. They should just vanish. Also check the actual order * type as ot is currently OT_GOTO_STATION. */ if (order->IsType(OT_AUTOMATIC)) { + order = order->next; // DeleteOrder() invalidates current order DeleteOrder(v, id); - id--; - continue; + if (order != NULL) goto restart; + break; } order->MakeDummy(); diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 29e47bd926..69c1a555d0 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -100,7 +100,7 @@ int RoadVehicle::GetDisplayImageWidth(Point *offset) const offset->x = reference_width / 2; offset->y = 0; } - return this->gcache.cached_veh_length * reference_width / 8; + return this->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH; } static SpriteID GetRoadVehIcon(EngineID engine) @@ -161,11 +161,11 @@ void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID eng */ static uint GetRoadVehLength(const RoadVehicle *v) { - uint length = 8; + uint length = VEHICLE_LENGTH; uint16 veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, v->engine_type, v); if (veh_len != CALLBACK_FAILED) { - length -= Clamp(veh_len, 0, 7); + length -= Clamp(veh_len, 0, VEHICLE_LENGTH - 1); } return length; @@ -262,7 +262,7 @@ CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engin v->roadtype = HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD; v->compatible_roadtypes = RoadTypeToRoadTypes(v->roadtype); - v->gcache.cached_veh_length = 8; + v->gcache.cached_veh_length = VEHICLE_LENGTH; if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE); diff --git a/src/table/pricebase.h b/src/table/pricebase.h index 662a763d47..84d23b3bd7 100644 --- a/src/table/pricebase.h +++ b/src/table/pricebase.h @@ -60,8 +60,8 @@ extern const PriceBaseSpec _price_base_specs[] = { { 5600, PCAT_RUNNING, GSF_SHIPS, INVALID_PRICE }, ///< PR_RUNNING_SHIP {1000000, PCAT_CONSTRUCTION, GSF_END, INVALID_PRICE }, ///< PR_BUILD_INDUSTRY { 1600, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_HOUSE }, ///< PR_CLEAR_INDUSTRY - { 40, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_ROUGH }, ///< PR_BUILD_OBJECT - { 40, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_ROUGH }, ///< PR_CLEAR_OBJECT + { 40, PCAT_CONSTRUCTION, GSF_OBJECTS, PR_CLEAR_ROUGH }, ///< PR_BUILD_OBJECT + { 40, PCAT_CONSTRUCTION, GSF_OBJECTS, PR_CLEAR_ROUGH }, ///< PR_CLEAR_OBJECT { 600, PCAT_CONSTRUCTION, GSF_END, PR_BUILD_DEPOT_TRAIN }, ///< PR_BUILD_WAYPOINT_RAIL { 80, PCAT_CONSTRUCTION, GSF_END, PR_CLEAR_DEPOT_TRAIN }, ///< PR_CLEAR_WAYPOINT_RAIL { 350, PCAT_CONSTRUCTION, GSF_END, PR_BUILD_STATION_DOCK }, ///< PR_BUILD_WAYPOINT_BUOY diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index e234c9d28c..f62063aba8 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -240,7 +240,7 @@ void Train::ConsistChanged(bool same_length) veh_len = GetVehicleCallback(CBID_VEHICLE_LENGTH, 0, 0, u->engine_type, u); } if (veh_len == CALLBACK_FAILED) veh_len = rvi_u->shorten_factor; - veh_len = 8 - Clamp(veh_len, 0, 7); + veh_len = VEHICLE_LENGTH - Clamp(veh_len, 0, VEHICLE_LENGTH - 1); /* verify length hasn't changed */ if (same_length && veh_len != u->gcache.cached_veh_length) RailVehicleLengthChanged(u); @@ -313,8 +313,11 @@ int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, i } /* Subtract half the front vehicle length of the train so we get the real - * stop location of the train. */ - return stop - (v->gcache.cached_veh_length + 1) / 2; + * stop location of the train. + * Actually, the center of all vehicles is half a normal vehicle's length + * from the front of the vehicle, so even in case the vehicle is 1/8th + * long, the center is still at 1/2 of VEHICLE_LENGTH. Basically FS#3569. */ + return stop - VEHICLE_LENGTH / 2; } @@ -461,7 +464,7 @@ int Train::GetDisplayImageWidth(Point *offset) const offset->x = reference_width / 2; offset->y = vehicle_pitch; } - return this->gcache.cached_veh_length * reference_width / 8; + return this->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH; } static SpriteID GetDefaultTrainSprite(uint8 spritenum, Direction direction) @@ -3403,8 +3406,13 @@ static bool TrainApproachingLineEnd(Train *v, bool signal) default: break; } - /* do not reverse when approaching red signal */ - if (!signal && x + (v->gcache.cached_veh_length + 1) / 2 >= TILE_SIZE) { + /* Do not reverse when approaching red signal. Make sure the vehicle's front + * does not cross the tile boundary when we do reverse, but as the vehicle's + * location is based on their center, use half a vehicle's length as offset. + * Actually, the center of all vehicles is half a normal vehicle's length + * from the front of the vehicle, so even in case the vehicle is 1/8th + * long, the center is still at 1/2 of VEHICLE_LENGTH. Basically FS#3569. */ + if (!signal && x + VEHICLE_LENGTH / 2 >= TILE_SIZE) { /* we are too near the tile end, reverse now */ v->cur_speed = 0; ReverseTrainDirection(v); diff --git a/src/vehicle_type.h b/src/vehicle_type.h index 4b4150a637..32c79421df 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -67,6 +67,9 @@ enum DepotCommand { static const uint MAX_LENGTH_VEHICLE_NAME_CHARS = 32; ///< The maximum length of a vehicle name in characters including '\0' static const uint MAX_LENGTH_VEHICLE_NAME_PIXELS = 150; ///< The maximum length of a vehicle name in pixels +/** The length of a vehicle in tile units. */ +static const uint VEHICLE_LENGTH = 8; + /** Vehicle acceleration models. */ enum AccelerationModel { AM_ORIGINAL,