Changeset - r11234:5b224faa57dc
[Not reviewed]
master
0 3 0
smatz - 16 years ago 2009-02-26 14:07:42
smatz@openttd.org
(svn r15588) -Fix: change owner of waypoints and deleted stations when merging companies or when a company benkrupts
3 files changed with 39 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -395,12 +395,30 @@ void ChangeOwnershipOfCompanyItems(Owner
 
		}
 

	
 
		/* update signals in buffer */
 
		UpdateSignalsInBuffer();
 
	}
 

	
 
	/* convert owner of stations (including deleted ones, but excluding buoys) */
 
	Station *st;
 
	FOR_ALL_STATIONS(st) {
 
		if (st->owner == old_owner) {
 
			/* if a company goes bankrupt, set owner to OWNER_NONE so the sign doesn't disappear immediately
 
			 * also, drawing station window would cause reading invalid company's colour */
 
			st->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
 
		}
 
	}
 

	
 
	/* do the same for waypoints (we need to do this here so deleted waypoints are converted too) */
 
	Waypoint *wp;
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->owner == old_owner) {
 
			wp->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
 
		}
 
	}
 

	
 
	/* In all cases clear replace engine rules.
 
	 * Even if it was copied, it could interfere with new owner's rules */
 
	RemoveAllEngineReplacementForCompany(GetCompany(old_owner));
 

	
 
	if (new_owner == INVALID_OWNER) {
 
		RemoveAllGroupsForCompany(old_owner);
src/saveload/afterload.cpp
Show inline comments
 
@@ -1612,20 +1612,12 @@ bool AfterLoadGame()
 
					TryReserveRailTrack(v->tile, DiagDirToDiagTrack(GetTunnelBridgeDirection(v->tile)));
 
				} else if ((v->u.rail.track & TRACK_BIT_MASK) != TRACK_BIT_NONE) {
 
					TryReserveRailTrack(v->tile, TrackBitsToTrack(v->u.rail.track));
 
				}
 
			}
 
		}
 

	
 
		/* Give owners to waypoints, based on rail tracks it is sitting on.
 
		 * If none is available, specify OWNER_NONE */
 
		Waypoint *wp;
 
		FOR_ALL_WAYPOINTS(wp) {
 
			Owner owner = (IsRailWaypointTile(wp->xy) ? GetTileOwner(wp->xy) : OWNER_NONE);
 
			wp->owner = IsValidCompanyID(owner) ? owner : OWNER_NONE;
 
		}
 
	}
 

	
 
	if (CheckSavegameVersion(102)) {
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			/* Now all crossings should be in correct state */
 
			if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t, false);
 
@@ -1719,12 +1711,32 @@ bool AfterLoadGame()
 
				case 0: layout = 2; break;
 
			}
 
			t->layout = layout - 1;
 
		}
 
	}
 

	
 
	if (CheckSavegameVersion(114)) {
 
		/* There could be (deleted) stations with invalid owner, set owner to OWNER NONE.
 
		 * The conversion affects oil rigs and buoys too, but it doesn't matter as
 
		 * they have st->owner == OWNER_NONE already. */
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			if (!IsValidCompanyID(st->owner)) st->owner = OWNER_NONE;
 
		}
 

	
 
		/* Give owners to waypoints, based on rail tracks it is sitting on.
 
		 * If none is available, specify OWNER_NONE.
 
		 * This code was in CheckSavegameVersion(101) in the past, but in some cases,
 
		 * the owner of waypoints could be incorrect. */
 
		Waypoint *wp;
 
		FOR_ALL_WAYPOINTS(wp) {
 
			Owner owner = IsTileType(wp->xy, MP_RAILWAY) ? GetTileOwner(wp->xy) : OWNER_NONE;
 
			wp->owner = IsValidCompanyID(owner) ? owner : OWNER_NONE;
 
		}
 
	}
 

	
 
	GamelogPrintDebug(1);
 

	
 
	bool ret = InitializeWindowsAndCaches();
 
	/* Restore the signals */
 
	signal(SIGSEGV, prev_segfault);
 
	signal(SIGABRT, prev_abort);
src/station_cmd.cpp
Show inline comments
 
@@ -3117,16 +3117,14 @@ void DeleteOilRig(TileIndex tile)
 

	
 
static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	if (!IsTileOwner(tile, old_owner)) return;
 

	
 
	if (new_owner != INVALID_OWNER) {
 
		Station *st = GetStationByTile(tile);
 

	
 
		/* for buoys, owner of tile is owner of water, st->owner == OWNER_NONE */
 
		SetTileOwner(tile, new_owner);
 
		if (!IsBuoy(tile)) st->owner = new_owner; // do not set st->owner for buoys
 
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
 
	} else {
 
		if (IsDriveThroughStopTile(tile)) {
 
			/* Remove the drive-through road stop */
 
			DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
 
			assert(IsTileType(tile, MP_ROAD));
0 comments (0 inline, 0 general)