Changeset - r12238:3f15dba5bf63
[Not reviewed]
master
0 1 0
smatz - 15 years ago 2009-06-26 12:25:53
smatz@openttd.org
(svn r16663) -Codechange: make removing of railway station tiles faster
1 file changed with 24 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -1148,12 +1148,14 @@ CommandCost CmdRemoveFromRailroadStation
 
	if (ey < sy) Swap(ey, sy);
 
	tile = TileXY(sx, sy);
 

	
 
	int size_x = ex - sx + 1;
 
	int size_y = ey - sy + 1;
 

	
 
	SmallVector<Station *, 4> affected_stations;
 

	
 
	/* Do the action for every tile into the area */
 
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
 
		/* Make sure the specified tile is a railroad station */
 
		if (!IsRailwayStationTile(tile2)) {
 
			continue;
 
		}
 
@@ -1200,39 +1202,45 @@ CommandCost CmdRemoveFromRailroadStation
 
			st->rect.AfterRemoveTile(st, tile2);
 
			AddTrackToSignalBuffer(tile2, track, owner);
 
			YapfNotifyTrackLayoutChange(tile2, track);
 

	
 
			DeallocateSpecFromStation(st, specindex);
 

	
 
			/* now we need to make the "spanned" area of the railway station smaller
 
			 * if we deleted something at the edges.
 
			 * we also need to adjust train_tile. */
 
			MakeRailwayStationAreaSmaller(st);
 
			st->MarkTilesDirty(false);
 
			UpdateStationSignCoord(st);
 
			affected_stations.Include(st);
 

	
 
			if (v != NULL) {
 
				/* Restore station reservation. */
 
				if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
 
				TryPathReserve(v, true, true);
 
				for (; v->Next() != NULL; v = v->Next()) ;
 
				if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true);
 
			}
 

	
 
			/* if we deleted the whole station, delete the train facility. */
 
			if (st->train_tile == INVALID_TILE) {
 
				st->facilities &= ~FACIL_TRAIN;
 
				InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
 
				UpdateStationVirtCoordDirty(st);
 
				DeleteStationIfEmpty(st);
 
			}
 

	
 
			st->RecomputeIndustriesNear();
 
		}
 
	} END_TILE_LOOP(tile2, size_x, size_y, tile)
 

	
 
	for (Station **stp = affected_stations.Begin(); stp != affected_stations.End(); stp++) {
 
		Station *st = *stp;
 

	
 
		/* now we need to make the "spanned" area of the railway station smaller
 
		 * if we deleted something at the edges.
 
		 * we also need to adjust train_tile. */
 
		MakeRailwayStationAreaSmaller(st);
 
		st->MarkTilesDirty(false);
 
		UpdateStationSignCoord(st);
 

	
 
		/* if we deleted the whole station, delete the train facility. */
 
		if (st->train_tile == INVALID_TILE) {
 
			st->facilities &= ~FACIL_TRAIN;
 
			InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
 
			UpdateStationVirtCoordDirty(st);
 
			DeleteStationIfEmpty(st);
 
		}
 

	
 
		st->RecomputeIndustriesNear();
 
	}
 

	
 
	/* If we've not removed any tiles, give an error */
 
	if (quantity == 0) return CMD_ERROR;
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_rail_station * quantity);
 
}
 

	
0 comments (0 inline, 0 general)