From 876d064c4d3ab080a6a3b594c208503ea153108e Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 4 Jul 2009 17:20:48 +0000 Subject: [PATCH] (svn r16741) [0.7] -Backport from trunk: - Fix: When loading a savegame Engine::grffile might be left NULL in certain cases (dynamic_engines enabled, articulated vehicle with only wagon-override action3s) (r16737) - Fix: Show Close instead of Cancel when there is nothing to canel in the content downloading window [FS#2991] (r16732) - Fix: [NoAI] AIDepotList contained wrong tiles for hangars when st->xy != st->airport_tile (r16731) - Fix: The Join station window did not show all stations nearby in some cases (r16728) - Fix: Invalidate subsidies with invalid source or destination when converting older savegames (r16710) - Fix: The list of animated tiles could have duplicates (only for old savegames) and tiles that were not animated [FS#2994] (r16709) --- src/ai/api/ai_depotlist.cpp | 2 +- src/industry_cmd.cpp | 4 +++ src/landscape.cpp | 4 +++ src/network/network_content_gui.cpp | 2 ++ src/newgrf.cpp | 6 +++- src/saveload/afterload.cpp | 55 +++++++++++++++++++++++++++++ src/station_cmd.cpp | 3 ++ src/station_gui.cpp | 25 +++++++++---- 8 files changed, 92 insertions(+), 9 deletions(-) diff --git a/src/ai/api/ai_depotlist.cpp b/src/ai/api/ai_depotlist.cpp index f4cdb1a08e..c53804d046 100644 --- a/src/ai/api/ai_depotlist.cpp +++ b/src/ai/api/ai_depotlist.cpp @@ -25,7 +25,7 @@ AIDepotList::AIDepotList(AITile::TransportType transport_type) if (st->owner == ::_current_company) { const AirportFTAClass *afc = st->Airport(); for (uint i = 0; i < afc->nof_depots; i++) { - this->AddItem(st->xy + ToTileIndexDiff(afc->airport_depots[i])); + this->AddItem(st->airport_tile + ToTileIndexDiff(afc->airport_depots[i])); } } } diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 768584d33c..e382ab8e28 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -142,6 +142,10 @@ Industry::~Industry() if (GetIndustryIndex(tile_cur) == this->index) { /* MakeWaterKeepingClass() can also handle 'land' */ MakeWaterKeepingClass(tile_cur, OWNER_NONE); + + /* MakeWaterKeepingClass() doesn't remove animation if the tiles + * become watery, but be on the safe side an always remote it. */ + DeleteAnimatedTile(tile_cur); } } else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { DeleteOilRig(tile_cur); diff --git a/src/landscape.cpp b/src/landscape.cpp index e599203c55..6d88595074 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -22,6 +22,7 @@ #include "effectvehicle_func.h" #include "landscape_type.h" #include "settings_type.h" +#include "animated_tile_func.h" #include "table/sprites.h" @@ -471,6 +472,9 @@ void DrawFoundation(TileInfo *ti, Foundation f) void DoClearSquare(TileIndex tile) { + /* If the tile can have animation and we clear it, delete it from the animated tile list. */ + if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != NULL) DeleteAnimatedTile(tile); + MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0); MarkTileDirtyByTile(tile); } diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 4324423522..badb5a44d3 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -388,6 +388,8 @@ public: this->SetWidgetDisabledState(NCLWW_SELECT_ALL, !show_select_all); this->SetWidgetDisabledState(NCLWW_SELECT_UPDATE, !show_select_upgrade); + this->widget[NCLWW_CANCEL].data = filesize == 0 ? STR_AI_CLOSE : STR_AI_CANCEL; + this->DrawWidgets(); /* Edit box to filter for keywords */ diff --git a/src/newgrf.cpp b/src/newgrf.cpp index ebdc417231..fa74aa526d 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -354,7 +354,11 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern /* Check if the engine is registered in the override manager */ EngineID engine = _engine_mngr.GetID(type, internal_id, scope_grfid); - if (engine != INVALID_ENGINE) return GetEngine(engine); + if (engine != INVALID_ENGINE) { + Engine *e = GetEngine(engine); + if (e->grffile == NULL) e->grffile = file; + return e; + } } /* Check if there is an unreserved slot */ diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index b00ca1688f..553164c353 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -28,6 +28,7 @@ #include "../company_func.h" #include "../road_cmd.h" #include "../ai/ai.hpp" +#include "../animated_tile_func.h" #include "table/strings.h" @@ -1845,6 +1846,60 @@ bool AfterLoadGame() } } + if (CheckSavegameVersion(122)) { + /* Animated tiles would sometimes not be actually animated or + * in case of old savegames duplicate. */ + + extern TileIndex *_animated_tile_list; + extern uint _animated_tile_count; + + for (uint i = 0; i < _animated_tile_count; /* Nothing */) { + /* Remove if tile is not animated */ + bool remove = _tile_type_procs[GetTileType(_animated_tile_list[i])]->animate_tile_proc == NULL; + + /* and remove if duplicate */ + for (uint j = 0; !remove && j < i; j++) { + remove = _animated_tile_list[i] == _animated_tile_list[j]; + } + + if (remove) { + DeleteAnimatedTile(_animated_tile_list[i]); + } else { + i++; + } + } + + /* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */ + for (Subsidy *s = _subsidies; s < endof(_subsidies); s++) { + if (s->cargo_type == CT_INVALID) continue; + if (s->age >= 12) { + /* Station -> Station */ + const Station *from = IsValidStationID(s->from) ? GetStation(s->from) : NULL; + const Station *to = IsValidStationID(s->to) ? GetStation(s->to) : NULL; + if (from != NULL && to != NULL && from->owner == to->owner && IsValidCompanyID(from->owner)) continue; + } else { + const CargoSpec *cs = GetCargo(s->cargo_type); + switch (cs->town_effect) { + case TE_PASSENGERS: + case TE_MAIL: + /* Town -> Town */ + if (IsValidTownID(s->from) && IsValidTownID(s->to)) continue; + break; + case TE_GOODS: + case TE_FOOD: + /* Industry -> Town */ + if (IsValidIndustryID(s->from) && IsValidTownID(s->to)) continue; + break; + default: + /* Industry -> Industry */ + if (IsValidIndustryID(s->from) && IsValidIndustryID(s->to)) continue; + break; + } + } + s->cargo_type = CT_INVALID; + } + } + GamelogPrintDebug(1); bool ret = InitializeWindowsAndCaches(); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 954525617c..87832301c8 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1038,6 +1038,8 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin } } + /* Remove animation if overbuilding */ + DeleteAnimatedTile(tile); byte old_specindex = IsTileType(tile, MP_STATION) ? GetCustomStationSpecIndex(tile) : 0; MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p1, 0, 4)); /* Free the spec if we overbuild something */ @@ -3048,6 +3050,7 @@ void BuildOilRig(TileIndex tile) st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG); assert(IsTileType(tile, MP_INDUSTRY)); + DeleteAnimatedTile(tile); MakeOilrig(tile, st->index, GetWaterClass(tile)); st->owner = OWNER_NONE; diff --git a/src/station_gui.cpp b/src/station_gui.cpp index cb5f749c4c..06fb0e27b1 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1000,8 +1000,14 @@ void ShowStationViewWindow(StationID station) AllocateWindowDescFront(&_station_view_desc, station); } +/** Struct containing TileIndex and StationID */ +struct TileAndStation { + TileIndex tile; ///< TileIndex + StationID station; ///< StationID +}; + +static SmallVector _deleted_stations_nearby; static SmallVector _stations_nearby_list; -static SmallMap _deleted_stations_nearby; /** Context for FindStationsNearby */ struct FindNearbyStationContext { @@ -1020,11 +1026,14 @@ static bool AddNearbyStation(TileIndex tile, void *user_data) { FindNearbyStationContext *ctx = (FindNearbyStationContext *)user_data; - /* First check if there was a deleted station here */ - SmallPair *dst = _deleted_stations_nearby.Find(tile); - if (dst != _deleted_stations_nearby.End()) { - _stations_nearby_list.Include(dst->second); - return false; + /* First check if there were deleted stations here */ + for (uint i = 0; i < _deleted_stations_nearby.Length(); i++) { + TileAndStation *ts = _deleted_stations_nearby.Get(i); + if (ts->tile == tile) { + *_stations_nearby_list.Append() = _deleted_stations_nearby[i].station; + _deleted_stations_nearby.Erase(ts); + i--; + } } /* Check if own station and if we stay within station spread */ @@ -1072,7 +1081,9 @@ static const Station *FindStationsNearby(TileIndex tile, int w, int h, bool dist if (st->facilities == 0 && st->owner == _local_company) { /* Include only within station spread (yes, it is strictly less than) */ if (max(DistanceMax(tile, st->xy), DistanceMax(TILE_ADDXY(tile, w - 1, h - 1), st->xy)) < _settings_game.station.station_spread) { - _deleted_stations_nearby.Insert(st->xy, st->index); + TileAndStation *ts = _deleted_stations_nearby.Append(); + ts->tile = st->xy; + ts->station = st->index; /* Add the station when it's within where we're going to build */ if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&