Changeset - r12515:abd5af2c2638
[Not reviewed]
master
0 5 0
rubidium - 15 years ago 2009-07-26 16:17:49
rubidium@openttd.org
(svn r16962) -Codechange: more work towards multi tile waypoints
5 files changed with 51 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/base_station_base.h
Show inline comments
 
@@ -32,12 +32,36 @@ struct TileArea {
 

	
 
	TileIndex tile; ///< The base tile of the area
 
	uint8 w;        ///< The width of the area
 
	uint8 h;        ///< The height of the area
 
};
 

	
 

	
 
/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
 
struct StationRect : public Rect {
 
	enum StationRectMode
 
	{
 
		ADD_TEST = 0,
 
		ADD_TRY,
 
		ADD_FORCE
 
	};
 

	
 
	StationRect();
 
	void MakeEmpty();
 
	bool PtInExtendedRect(int x, int y, int distance = 0) const;
 
	bool IsEmpty() const;
 
	bool BeforeAddTile(TileIndex tile, StationRectMode mode);
 
	bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
 
	bool AfterRemoveTile(BaseStation *st, TileIndex tile);
 
	bool AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h);
 

	
 
	static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
 

	
 
	StationRect& operator = (Rect src);
 
};
 

	
 
/** Base class for all station-ish types */
 
struct BaseStation : StationPool::PoolItem<&_station_pool> {
 
	TileIndex xy;                   ///< Base tile of the station
 
	ViewportSign sign;              ///< NOSAVE: Dimensions of sign
 
	byte delete_ctr;                ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
 

	
 
@@ -54,13 +78,24 @@ struct BaseStation : StationPool::PoolIt
 
	Date build_date;                ///< Date of construction
 

	
 
	uint16 random_bits;             ///< Random bits assigned to this station
 
	byte waiting_triggers;          ///< Waiting triggers (NewGRF) for this station
 
	uint8 cached_anim_triggers;     ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
 

	
 
	BaseStation(TileIndex tile) : xy(tile) { }
 
	TileArea train_station;         ///< Tile area the train 'station' part covers
 
	StationRect rect;               ///< NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions
 

	
 
	/**
 
	 * Initialize the base station.
 
	 * @param tile The location of the station sign
 
	 */
 
	BaseStation(TileIndex tile) :
 
		xy(tile),
 
		train_station(INVALID_TILE, 0, 0)
 
	{
 
	}
 

	
 
	virtual ~BaseStation();
 

	
 
	/**
 
	 * Check whether a specific tile belongs to this station.
 
	 * @param tile the tile to check
src/saveload/afterload.cpp
Show inline comments
 
@@ -602,17 +602,20 @@ bool AfterLoadGame()
 
		}
 
	}
 

	
 
	for (TileIndex t = 0; t < map_size; t++) {
 
		switch (GetTileType(t)) {
 
			case MP_STATION: {
 
				Station *st = Station::GetByTile(t);
 
				if (st == NULL) break;
 
				BaseStation *bst = BaseStation::GetByTile(t);
 

	
 
				/* Set up station spread; waypoints do not have one */
 
				st->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
 
				/* Set up station spread */
 
				bst->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
 

	
 
				/* Waypoints don't have road stops/oil rigs in the old format */
 
				if (!Station::IsExpected(bst)) break;
 
				Station *st = Station::From(bst);
 

	
 
				switch (GetStationType(t)) {
 
					case STATION_TRUCK:
 
					case STATION_BUS:
 
						if (CheckSavegameVersion(6)) {
 
							/* From this version on there can be multiple road stops of the
src/station.cpp
Show inline comments
 
@@ -36,13 +36,12 @@ BaseStation::~BaseStation()
 
	free(this->name);
 
	free(this->speclist);
 
}
 

	
 
Station::Station(TileIndex tile) :
 
	SpecializedStation<Station, false>(tile),
 
	train_station(INVALID_TILE, 0, 0),
 
	airport_tile(INVALID_TILE),
 
	dock_tile(INVALID_TILE),
 
	indtype(IT_INVALID),
 
	time_since_load(255),
 
	time_since_unload(255),
 
	last_vehicle_type(VEH_INVALID)
 
@@ -420,13 +419,13 @@ bool StationRect::BeforeAddRect(TileInde
 
		if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
 
	END_TILE_LOOP(tile, width, height, top_left);
 

	
 
	return false;
 
}
 

	
 
bool StationRect::AfterRemoveTile(Station *st, TileIndex tile)
 
bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
 
{
 
	int x = TileX(tile);
 
	int y = TileY(tile);
 

	
 
	/* look if removed tile was on the bounding rect edge
 
	 * and try to reduce the rect by this edge
 
@@ -470,13 +469,13 @@ bool StationRect::AfterRemoveTile(Statio
 
			return true; // empty remaining rect
 
		}
 
	}
 
	return false; // non-empty remaining rect
 
}
 

	
 
bool StationRect::AfterRemoveRect(Station *st, TileIndex tile, int w, int h)
 
bool StationRect::AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h)
 
{
 
	assert(PtInExtendedRect(TileX(tile), TileY(tile)));
 
	assert(PtInExtendedRect(TileX(tile) + w - 1, TileY(tile) + h - 1));
 

	
 
	bool empty = this->AfterRemoveTile(st, tile);
 
	if (w != 1 || h != 1) empty = empty || AfterRemoveTile(st, TILE_ADDXY(tile, w - 1, h - 1));
src/station_base.h
Show inline comments
 
@@ -38,35 +38,12 @@ struct GoodsEntry {
 
	byte rating;
 
	byte last_speed;
 
	byte last_age;
 
	CargoList cargo; ///< The cargo packets of cargo waiting in this station
 
};
 

	
 
/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
 
struct StationRect : public Rect {
 
	enum StationRectMode
 
	{
 
		ADD_TEST = 0,
 
		ADD_TRY,
 
		ADD_FORCE
 
	};
 

	
 
	StationRect();
 
	void MakeEmpty();
 
	bool PtInExtendedRect(int x, int y, int distance = 0) const;
 
	bool IsEmpty() const;
 
	bool BeforeAddTile(TileIndex tile, StationRectMode mode);
 
	bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
 
	bool AfterRemoveTile(Station *st, TileIndex tile);
 
	bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
 

	
 
	static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
 

	
 
	StationRect& operator = (Rect src);
 
};
 

	
 

	
 
typedef SmallVector<Industry *, 2> IndustryVector;
 

	
 
/** Station data structure */
 
struct Station : SpecializedStation<Station, false> {
 
public:
 
@@ -82,13 +59,12 @@ public:
 
		if (airport_tile == INVALID_TILE) return GetAirport(AT_DUMMY);
 
		return GetAirport(airport_type);
 
	}
 

	
 
	RoadStop *bus_stops;    ///< All the road stops
 
	RoadStop *truck_stops;  ///< All the truck stops
 
	TileArea train_station; ///< Tile area the train station part covers
 
	TileIndex airport_tile; ///< The location of the airport
 
	TileIndex dock_tile;    ///< The location of the dock
 

	
 
	IndustryType indtype;   ///< Industry type to get the name from
 

	
 
	StationHadVehicleOfTypeByte had_vehicle_of_type;
 
@@ -102,14 +78,12 @@ public:
 
	byte last_vehicle_type;
 
	std::list<Vehicle *> loading_vehicles;
 
	GoodsEntry goods[NUM_CARGO];  ///< Goods at this station
 

	
 
	IndustryVector industries_near; ///< Cached list of industries near the station that can accept cargo, @see DeliverGoodsToIndustry()
 

	
 
	StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions
 

	
 
	Station(TileIndex tile = INVALID_TILE);
 
	~Station();
 

	
 
	void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy);
 

	
 
	/**
src/waypoint_cmd.cpp
Show inline comments
 
@@ -181,12 +181,14 @@ CommandCost CmdBuildTrainWaypoint(TileIn
 

	
 
			wp->xy = tile;
 
			InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
 
		}
 
		wp->owner = owner;
 

	
 
		wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
 

	
 
		bool reserved = HasBit(GetRailReservationTrackBits(tile), AxisToTrack(axis));
 
		MakeRailWaypoint(tile, owner, wp->index, axis, 0, GetRailType(tile));
 
		SetRailStationReservation(tile, reserved);
 
		MarkTileDirtyByTile(tile);
 

	
 
		SetCustomStationSpecIndex(tile, AllocateSpecToStation(GetCustomStationSpec(STAT_CLASS_WAYP, p1), wp, true));
 
@@ -246,12 +248,13 @@ CommandCost RemoveTrainWaypoint(TileInde
 
			AddTrackToSignalBuffer(tile, track, wp->owner);
 
		}
 
		YapfNotifyTrackLayoutChange(tile, track);
 
		if (v != NULL) TryPathReserve(v, true);
 

	
 
		DeallocateSpecFromStation(wp, specindex);
 
		wp->rect.AfterRemoveTile(wp, tile);
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_train_depot);
 
}
 

	
 
/**
 
@@ -293,12 +296,13 @@ CommandCost CmdBuildBuoy(TileIndex tile,
 
			wp = new Waypoint(tile);
 
		} else {
 
			/* Move existing (recently deleted) buoy to the new location */
 
			wp->xy = tile;
 
			InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
 
		}
 
		wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
 

	
 
		wp->string_id = STR_SV_STNAME_BUOY;
 

	
 
		wp->facilities |= FACIL_DOCK;
 
		wp->owner = OWNER_NONE;
 

	
 
@@ -341,12 +345,14 @@ CommandCost RemoveBuoy(TileIndex tile, D
 
		/* We have to set the water tile's state to the same state as before the
 
		 * buoy was placed. Otherwise one could plant a buoy on a canal edge,
 
		 * remove it and flood the land (if the canal edge is at level 0) */
 
		MakeWaterKeepingClass(tile, GetTileOwner(tile));
 
		MarkTileDirtyByTile(tile);
 

	
 
		wp->rect.AfterRemoveTile(wp, tile);
 

	
 
		wp->UpdateVirtCoord();
 
		wp->delete_ctr = 0;
 
	}
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_truck_station);
 
}
0 comments (0 inline, 0 general)