Changeset - r19263:8bc163eb7eb2
[Not reviewed]
master
0 9 0
frosch - 13 years ago 2012-04-22 16:28:14
frosch@openttd.org
(svn r24166) -Codechange: Turn NewGRFClass::Get(Tid, uint) and GetCount(Tid) into non-static members GetSpec(uint) and GetSpecCount().
9 files changed with 72 insertions and 80 deletions:
0 comments (0 inline, 0 general)
src/airport_gui.cpp
Show inline comments
 
@@ -54,13 +54,13 @@ void CcBuildAirport(const CommandCost &r
 
static void PlaceAirport(TileIndex tile)
 
{
 
	if (_selected_airport_index == -1) return;
 
	uint32 p2 = _ctrl_pressed;
 
	SB(p2, 16, 16, INVALID_STATION); // no station to join
 

	
 
	uint32 p1 = AirportClass::Get(_selected_airport_class, _selected_airport_index)->GetIndex();
 
	uint32 p1 = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
 
	p1 |= _selected_airport_layout << 8;
 
	CommandContainer cmdcont = { tile, p1, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport, "" };
 
	ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));
 
}
 

	
 
/** Airport build toolbar window handler. */
 
@@ -226,13 +226,13 @@ public:
 
		this->FinishInitNested(desc, TRANSPORT_AIR);
 

	
 
		this->SetWidgetLoweredState(WID_AP_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
 
		this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
 
		this->OnInvalidateData();
 

	
 
		this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
 
		this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
 
		this->SelectFirstAvailableAirport(true);
 
	}
 

	
 
	virtual ~BuildAirportWindow()
 
	{
 
		DeleteWindowById(WC_SELECT_STATION, 0);
 
@@ -245,13 +245,13 @@ public:
 
				SetDParam(0, AirportClass::Get(_selected_airport_class)->name);
 
				break;
 

	
 
			case WID_AP_LAYOUT_NUM:
 
				SetDParam(0, STR_EMPTY);
 
				if (_selected_airport_index != -1) {
 
					const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
 
					const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
 
					StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_LAYOUT_NAME);
 
					if (string != STR_UNDEFINED) {
 
						SetDParam(0, string);
 
					} else if (as->num_table > 1) {
 
						SetDParam(0, STR_STATION_BUILD_AIRPORT_LAYOUT_NAME);
 
						SetDParam(1, _selected_airport_layout + 1);
 
@@ -329,14 +329,15 @@ public:
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case WID_AP_AIRPORT_LIST: {
 
				int y = r.top;
 
				for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < AirportClass::GetCount(_selected_airport_class); i++) {
 
					const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
 
				AirportClass *apclass = AirportClass::Get(_selected_airport_class);
 
				for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < apclass->GetSpecCount(); i++) {
 
					const AirportSpec *as = apclass->GetSpec(i);
 
					if (!as->IsAvailable()) {
 
						GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, PC_BLACK, FILLRECT_CHECKER);
 
					}
 
					DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
 
					y += this->line_height;
 
				}
 
@@ -349,13 +350,13 @@ public:
 
					DrawSprite(this->preview_sprite, COMPANY_SPRITE_COLOUR(_local_company), (r.left + r.right - d.width) / 2, (r.top + r.bottom - d.height) / 2);
 
				}
 
				break;
 

	
 
			case WID_AP_EXTRA_TEXT:
 
				if (_selected_airport_index != -1) {
 
					const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
 
					const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
 
					StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_ADDITIONAL_TEXT);
 
					if (string != STR_UNDEFINED) {
 
						SetDParam(0, string);
 
						DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_BLACK_STRING);
 
					}
 
				}
 
@@ -371,13 +372,13 @@ public:
 
		NWidgetBase *panel_nwi = this->GetWidget<NWidgetBase>(WID_AP_BOTTOMPANEL);
 

	
 
		int right = panel_nwi->pos_x +  panel_nwi->current_x;
 
		int bottom = panel_nwi->pos_y +  panel_nwi->current_y;
 

	
 
		if (_selected_airport_index != -1) {
 
			const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
 
			const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
 
			int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
 

	
 
			/* only show the station (airport) noise, if the noise option is activated */
 
			if (_settings_game.economy.station_noise_level) {
 
				/* show the noise of the selected airport */
 
				SetDParam(0, as->noise_level);
 
@@ -409,13 +410,13 @@ public:
 
	{
 
		if (_selected_airport_index == -1) {
 
			SetTileSelectSize(1, 1);
 
			this->DisableWidget(WID_AP_LAYOUT_DECREASE);
 
			this->DisableWidget(WID_AP_LAYOUT_INCREASE);
 
		} else {
 
			const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
 
			const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
 
			int w = as->size_x;
 
			int h = as->size_y;
 
			Direction rotation = as->rotation[_selected_airport_layout];
 
			if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
 
			SetTileSelectSize(w, h);
 

	
 
@@ -436,13 +437,13 @@ public:
 
				ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class, WID_AP_CLASS_DROPDOWN);
 
				break;
 

	
 
			case WID_AP_AIRPORT_LIST: {
 
				int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
 
				if (num_clicked >= this->vscroll->GetCount()) break;
 
				const AirportSpec *as = AirportClass::Get(_selected_airport_class, num_clicked);
 
				const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(num_clicked);
 
				if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
 
				break;
 
			}
 

	
 
			case WID_AP_BTN_DONTHILIGHT: case WID_AP_BTN_DOHILIGHT:
 
				_settings_client.gui.station_show_coverage = (widget != WID_AP_BTN_DONTHILIGHT);
 
@@ -472,25 +473,27 @@ public:
 
	 * @param change_class If true, change the class if no airport in the current
 
	 *   class is available.
 
	 */
 
	void SelectFirstAvailableAirport(bool change_class)
 
	{
 
		/* First try to select an airport in the selected class. */
 
		for (uint i = 0; i < AirportClass::GetCount(_selected_airport_class); i++) {
 
			const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
 
		AirportClass *sel_apclass = AirportClass::Get(_selected_airport_class);
 
		for (uint i = 0; i < sel_apclass->GetSpecCount(); i++) {
 
			const AirportSpec *as = sel_apclass->GetSpec(i);
 
			if (as->IsAvailable()) {
 
				this->SelectOtherAirport(i);
 
				return;
 
			}
 
		}
 
		if (change_class) {
 
			/* If that fails, select the first available airport
 
			 * from a random class. */
 
			for (AirportClassID j = APC_BEGIN; j < APC_MAX; j++) {
 
				for (uint i = 0; i < AirportClass::GetCount(j); i++) {
 
					const AirportSpec *as = AirportClass::Get(j, i);
 
				AirportClass *apclass = AirportClass::Get(j);
 
				for (uint i = 0; i < apclass->GetSpecCount(); i++) {
 
					const AirportSpec *as = apclass->GetSpec(i);
 
					if (as->IsAvailable()) {
 
						_selected_airport_class = j;
 
						this->SelectOtherAirport(i);
 
						return;
 
					}
 
				}
 
@@ -501,13 +504,13 @@ public:
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		assert(widget == WID_AP_CLASS_DROPDOWN);
 
		_selected_airport_class = (AirportClassID)index;
 
		this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
 
		this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
 
		this->SelectFirstAvailableAirport(false);
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		CheckRedrawStationCoverage(this);
src/newgrf_class.h
Show inline comments
 
@@ -38,18 +38,21 @@ private:
 
public:
 
	uint32 global_id; ///< Global ID for class, e.g. 'DFLT', 'WAYP', etc.
 
	StringID name;    ///< Name of this class.
 

	
 
	void Insert(Tspec *spec);
 

	
 
	/** Get the number of allocated specs within the class. */
 
	uint GetSpecCount() const { return this->count; }
 

	
 
	const Tspec *GetSpec(uint index) const;
 

	
 
	static void Reset();
 
	static Tid Allocate(uint32 global_id);
 
	static void Assign(Tspec *spec);
 
	static NewGRFClass *Get(Tid cls_id);
 

	
 
	static uint GetCount();
 
	static uint GetCount(Tid cls_id);
 
	static const Tspec *Get(Tid cls_id, uint index);
 
	static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
 
};
 

	
 
#endif /* NEWGRF_CLASS_H */
src/newgrf_class_func.h
Show inline comments
 
@@ -114,37 +114,20 @@ DEFINE_NEWGRF_CLASS_METHOD(uint)::GetCou
 
	uint i;
 
	for (i = 0; i < Tmax && classes[i].global_id != 0; i++) {}
 
	return i;
 
}
 

	
 
/**
 
 * Get the number of allocated specs within a particular class.
 
 * @param cls_id The class to get the size of.
 
 * @pre cls_id < GetCount()
 
 * @return The size of the class.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(uint)::GetCount(Tid cls_id)
 
{
 
	assert(cls_id < Tmax);
 
	return classes[cls_id].count;
 
}
 

	
 
/**
 
 * Get a spec from a particular class at a given index.
 
 * @param cls_id The class to get the spec from.
 
 * Get a spec from the class at a given index.
 
 * @param index  The index where to find the spec.
 
 * @pre index < GetCount(cls_id)
 
 * @return The spec at given location.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::Get(Tid cls_id, uint index)
 
DEFINE_NEWGRF_CLASS_METHOD(const Tspec *)::GetSpec(uint index) const
 
{
 
	assert(cls_id < Tmax);
 
	if (index < classes[cls_id].count) return classes[cls_id].spec[index];
 

	
 
	/* If the custom spec isn't defined any more, then the GRF file probably was not loaded. */
 
	return NULL;
 
	return index < this->GetSpecCount() ? this->spec[index] : NULL;
 
}
 

	
 
/**
 
 * Retrieve a spec by GRF location.
 
 * @param grfid    GRF ID of spec.
 
 * @param local_id Index within GRF file of spec.
 
@@ -177,9 +160,8 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *
 
	template void name::Reset(); \
 
	template Tid name::Allocate(uint32 global_id); \
 
	template void name::Insert(Tspec *spec); \
 
	template void name::Assign(Tspec *spec); \
 
	template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
 
	template uint name::GetCount(); \
 
	template uint name::GetCount(Tid cls_id); \
 
	template const Tspec *name::Get(Tid cls_id, uint index); \
 
	template const Tspec *name::GetSpec(uint index) const; \
 
	template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);
src/newgrf_station.cpp
Show inline comments
 
@@ -802,19 +802,18 @@ void DeallocateSpecFromStation(BaseStati
 
 * @param sclass, station Type of station.
 
 * @param station station ID
 
 * @return True if the tile was drawn (allows for fallback to default graphic)
 
 */
 
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
 
{
 
	const StationSpec *statspec;
 
	const DrawTileSprites *sprites = NULL;
 
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
 
	PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company);
 
	uint tile = 2;
 

	
 
	statspec = StationClass::Get(sclass, station);
 
	const StationSpec *statspec = StationClass::Get(sclass)->GetSpec(station);
 
	if (statspec == NULL) return false;
 

	
 
	if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) {
 
		uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE);
 
		if (callback != CALLBACK_FAILED) tile = callback;
 
	}
src/object_gui.cpp
Show inline comments
 
@@ -48,24 +48,24 @@ public:
 

	
 
		this->SelectFirstAvailableObject(true);
 
		this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetCount(4);
 

	
 
		NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX);
 
		matrix->SetScrollbar(this->GetScrollbar(WID_BO_SELECT_SCROLL));
 
		matrix->SetCount(ObjectClass::GetCount(_selected_object_class));
 
		matrix->SetCount(ObjectClass::Get(_selected_object_class)->GetSpecCount());
 
	}
 

	
 
	virtual ~BuildObjectWindow()
 
	{
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		switch (widget) {
 
			case WID_BO_OBJECT_SIZE: {
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
 
				int size = spec == NULL ? 0 : spec->size;
 
				SetDParam(0, GB(size, HasBit(_selected_object_view, 0) ? 4 : 0, 4));
 
				SetDParam(1, GB(size, HasBit(_selected_object_view, 0) ? 0 : 4, 4));
 
				break;
 
			}
 

	
 
@@ -86,13 +86,13 @@ public:
 
				size->height = this->vscroll->GetCapacity() * this->line_height;
 
				break;
 
			}
 

	
 
			case WID_BO_OBJECT_MATRIX: {
 
				/* Get the right amount of buttons based on the current spec. */
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
 
				if (spec != NULL) {
 
					if (spec->views >= 2) size->width  += resize->width;
 
					if (spec->views >= 4) size->height += resize->height;
 
				}
 
				resize->width = 0;
 
				resize->height = 0;
 
@@ -126,13 +126,13 @@ public:
 
					size->width  = (3 * TILE_PIXELS + 2 * OBJECT_MARGIN) * 2 + 2;
 
				} else {
 
					size->width  = 4 * TILE_PIXELS + 2 * OBJECT_MARGIN;
 
				}
 

	
 
				/* Get the right size for the single widget based on the current spec. */
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
 
				if (spec != NULL) {
 
					if (spec->views >= 2) size->width  = size->width  / 2 - 1;
 
					if (spec->views >= 4) size->height = size->height / 2 - 1;
 
				}
 
				break;
 
			}
 
@@ -162,13 +162,13 @@ public:
 
					y += this->line_height;
 
				}
 
				break;
 
			}
 

	
 
			case WID_BO_OBJECT_SPRITE: {
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
 
				if (spec == NULL) break;
 

	
 
				DrawPixelInfo tmp_dpi;
 
				/* Set up a clipping area for the preview. */
 
				if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
 
					DrawPixelInfo *old_dpi = _cur_dpi;
 
@@ -186,13 +186,13 @@ public:
 
			}
 

	
 
			case WID_BO_SELECT_IMAGE: {
 
				if (_selected_object_index < 0) break;
 

	
 
				int obj_index = GB(widget, 16, 16);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, obj_index);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(obj_index);
 
				if (spec == NULL) break;
 

	
 
				if (!spec->IsAvailable()) {
 
					GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
 
				}
 
				DrawPixelInfo tmp_dpi;
 
@@ -211,13 +211,13 @@ public:
 
					_cur_dpi = old_dpi;
 
				}
 
				break;
 
			}
 

	
 
			case WID_BO_INFO: {
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
 
				if (spec == NULL) break;
 

	
 
				/* Get the extra message for the GUI */
 
				if (HasBit(spec->callback_mask, CBM_OBJ_FUND_MORE_TEXT)) {
 
					uint16 callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, NULL, INVALID_TILE, _selected_object_view);
 
					if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
 
@@ -250,13 +250,13 @@ public:
 
	 * @param object_index Object index to select, \c -1 means select nothing.
 
	 */
 
	void SelectOtherObject(int object_index)
 
	{
 
		_selected_object_index = object_index;
 
		if (_selected_object_index != -1) {
 
			const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
 
			const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
 
			_selected_object_view = min(_selected_object_view, spec->views - 1);
 
			this->ReInit();
 
		} else {
 
			_selected_object_view = 0;
 
		}
 

	
 
@@ -268,13 +268,13 @@ public:
 

	
 
	void UpdateSelectSize()
 
	{
 
		if (_selected_object_index == -1) {
 
			SetTileSelectSize(1, 1);
 
		} else {
 
			const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, _selected_object_index);
 
			const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
 
			int w = GB(spec->size, HasBit(_selected_object_view, 0) ? 4 : 0, 4);
 
			int h = GB(spec->size, HasBit(_selected_object_view, 0) ? 0 : 4, 4);
 
			SetTileSelectSize(w, h);
 
		}
 
	}
 

	
 
@@ -289,20 +289,20 @@ public:
 
		switch (GB(widget, 0, 16)) {
 
			case WID_BO_CLASS_LIST: {
 
				int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
 
				if (num_clicked >= (int)ObjectClass::GetCount()) break;
 

	
 
				_selected_object_class = (ObjectClassID)num_clicked;
 
				this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::GetCount(_selected_object_class));
 
				this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetSpecCount());
 
				this->SelectFirstAvailableObject(false);
 
				break;
 
			}
 

	
 
			case WID_BO_SELECT_IMAGE: {
 
				int num_clicked = GB(widget, 16, 16);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, num_clicked);
 
				const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(num_clicked);
 
				if (spec->IsAvailable()) this->SelectOtherObject(num_clicked);
 
				break;
 
			}
 

	
 
			case WID_BO_OBJECT_SPRITE:
 
				if (_selected_object_index != -1) {
 
@@ -320,25 +320,27 @@ public:
 
	 * @param change_class If true, change the class if no object in the current
 
	 *   class is available.
 
	 */
 
	void SelectFirstAvailableObject(bool change_class)
 
	{
 
		/* First try to select an object in the selected class. */
 
		for (uint i = 0; i < ObjectClass::GetCount(_selected_object_class); i++) {
 
			const ObjectSpec *spec = ObjectClass::Get(_selected_object_class, i);
 
		ObjectClass *sel_objclass = ObjectClass::Get(_selected_object_class);
 
		for (uint i = 0; i < sel_objclass->GetSpecCount(); i++) {
 
			const ObjectSpec *spec = sel_objclass->GetSpec(i);
 
			if (spec->IsAvailable()) {
 
				this->SelectOtherObject(i);
 
				return;
 
			}
 
		}
 
		if (change_class) {
 
			/* If that fails, select the first available object
 
			 * from a random class. */
 
			for (ObjectClassID j = OBJECT_CLASS_BEGIN; j < OBJECT_CLASS_MAX; j++) {
 
				for (uint i = 0; i < ObjectClass::GetCount(j); i++) {
 
					const ObjectSpec *spec = ObjectClass::Get(j, i);
 
				ObjectClass *objclass = ObjectClass::Get(j);
 
				for (uint i = 0; i < objclass->GetSpecCount(); i++) {
 
					const ObjectSpec *spec = objclass->GetSpec(i);
 
					if (spec->IsAvailable()) {
 
						_selected_object_class = j;
 
						this->SelectOtherObject(i);
 
						return;
 
					}
 
				}
 
@@ -415,8 +417,8 @@ void InitializeObjectGui()
 
 * PlaceProc function, called when someone pressed the button if the
 
 *  object-tool is selected
 
 * @param tile on which to place the object
 
 */
 
void PlaceProc_Object(TileIndex tile)
 
{
 
	DoCommandP(tile, ObjectClass::Get(_selected_object_class, _selected_object_index)->Index(), _selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
 
	DoCommandP(tile, ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index)->Index(), _selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
 
}
src/rail_gui.cpp
Show inline comments
 
@@ -546,13 +546,13 @@ struct BuildRailToolbarWindow : Window {
 
					this->last_user_action = widget;
 
				}
 
				break;
 

	
 
			case WID_RAT_BUILD_WAYPOINT:
 
				this->last_user_action = widget;
 
				_waypoint_count = StationClass::GetCount(STAT_CLASS_WAYP);
 
				_waypoint_count = StationClass::Get(STAT_CLASS_WAYP)->GetSpecCount();
 
				if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT) && _waypoint_count > 1) {
 
					ShowBuildWaypointPicker(this);
 
				}
 
				break;
 

	
 
			case WID_RAT_BUILD_STATION:
 
@@ -942,13 +942,13 @@ public:
 
			 * type is 'selected'. */
 
			_railstation.station_class = STAT_CLASS_DFLT;
 
			_railstation.station_type = 0;
 
			this->vscroll2 = NULL;
 
		}
 
		if (newstation) {
 
			_railstation.station_count = StationClass::GetCount(_railstation.station_class);
 
			_railstation.station_count = StationClass::Get(_railstation.station_class)->GetSpecCount();
 
			_railstation.station_type = min(_railstation.station_type, _railstation.station_count - 1);
 

	
 
			int count = 0;
 
			for (uint i = 0; i < StationClass::GetCount(); i++) {
 
				if (i == STAT_CLASS_WAYP) continue;
 
				count++;
 
@@ -971,13 +971,13 @@ public:
 
		DeleteWindowById(WC_SELECT_STATION, 0);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		bool newstations = _railstation.newstations;
 
		const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
 
		const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
 

	
 
		if (_settings_client.gui.station_dragdrop) {
 
			SetTileSelectSize(1, 1);
 
		} else {
 
			int x = _settings_client.gui.station_numtracks;
 
			int y = _settings_client.gui.station_platlength;
 
@@ -1045,14 +1045,15 @@ public:
 

	
 
				/* If newstations exist, compute the non-zero minimal size. */
 
				Dimension d = {0, 0};
 
				StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
 
				for (StationClassID statclass = STAT_CLASS_BEGIN; statclass < (StationClassID)StationClass::GetCount(); statclass++) {
 
					if (statclass == STAT_CLASS_WAYP) continue;
 
					for (uint16 j = 0; j < StationClass::GetCount(statclass); j++) {
 
						const StationSpec *statspec = StationClass::Get(statclass, j);
 
					StationClass *stclass = StationClass::Get(statclass);
 
					for (uint16 j = 0; j < stclass->GetSpecCount(); j++) {
 
						const StationSpec *statspec = stclass->GetSpec(j);
 
						SetDParam(0, (statspec != NULL && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
 
						d = maxdim(d, GetStringBoundingBox(str));
 
					}
 
				}
 
				size->width = max(size->width, d.width + padding.width);
 
				break;
 
@@ -1115,13 +1116,13 @@ public:
 
			}
 

	
 
			case WID_BRAS_IMAGE: {
 
				byte type = GB(widget, 16, 16);
 
				assert(type < _railstation.station_count);
 
				/* Check station availability callback */
 
				const StationSpec *statspec = StationClass::Get(_railstation.station_class, type);
 
				const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type);
 
				if (!IsStationAvailable(statspec)) {
 
					GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
 
				}
 

	
 
				/* Set up a clipping area for the station preview. */
 
				if (FillDrawPixelInfo(&tmp_dpi, r.left + 1, r.top + 1, r.right - (r.left + 1) + 1, r.bottom - 1 - (r.top + 1) + 1)) {
 
@@ -1145,13 +1146,13 @@ public:
 
		}
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget == WID_BRAS_SHOW_NEWST_TYPE) {
 
			const StationSpec *statspec = StationClass::Get(_railstation.station_class, _railstation.station_type);
 
			const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type);
 
			SetDParam(0, (statspec != NULL && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
@@ -1178,13 +1179,13 @@ public:
 

	
 
				_settings_client.gui.station_numtracks = widget - WID_BRAS_PLATFORM_NUM_BEGIN;
 
				_settings_client.gui.station_dragdrop = false;
 

	
 
				_settings_client.gui.station_dragdrop = false;
 

	
 
				const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
 
				const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
 
				if (statspec != NULL && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
 
					/* The previously selected number of platforms in invalid */
 
					for (uint i = 0; i < 7; i++) {
 
						if (!HasBit(statspec->disallowed_lengths, i)) {
 
							this->RaiseWidget(_settings_client.gui.station_platlength + WID_BRAS_PLATFORM_LEN_BEGIN);
 
							_settings_client.gui.station_platlength = i + 1;
 
@@ -1213,13 +1214,13 @@ public:
 

	
 
				_settings_client.gui.station_platlength = widget - WID_BRAS_PLATFORM_LEN_BEGIN;
 
				_settings_client.gui.station_dragdrop = false;
 

	
 
				_settings_client.gui.station_dragdrop = false;
 

	
 
				const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
 
				const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
 
				if (statspec != NULL && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
 
					/* The previously selected number of tracks in invalid */
 
					for (uint i = 0; i < 7; i++) {
 
						if (!HasBit(statspec->disallowed_platforms, i)) {
 
							this->RaiseWidget(_settings_client.gui.station_numtracks + WID_BRAS_PLATFORM_NUM_BEGIN);
 
							_settings_client.gui.station_numtracks = i + 1;
 
@@ -1239,13 +1240,13 @@ public:
 
			case WID_BRAS_PLATFORM_DRAG_N_DROP: {
 
				_settings_client.gui.station_dragdrop ^= true;
 

	
 
				this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP);
 

	
 
				/* get the first allowed length/number of platforms */
 
				const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class, _railstation.station_type) : NULL;
 
				const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : NULL;
 
				if (statspec != NULL && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
 
					for (uint i = 0; i < 7; i++) {
 
						if (!HasBit(statspec->disallowed_lengths, i)) {
 
							this->RaiseWidget(_settings_client.gui.station_platlength + WID_BRAS_PLATFORM_LEN_BEGIN);
 
							_settings_client.gui.station_platlength = i + 1;
 
							break;
 
@@ -1285,16 +1286,17 @@ public:
 
				if (y >= (int)StationClass::GetCount()) return;
 
				for (uint i = 0; i < StationClass::GetCount(); i++) {
 
					if (i == STAT_CLASS_WAYP) continue;
 
					if (y == 0) {
 
						if (_railstation.station_class != (StationClassID)i) {
 
							_railstation.station_class = (StationClassID)i;
 
							_railstation.station_count = StationClass::GetCount(_railstation.station_class);
 
							StationClass *stclass = StationClass::Get(_railstation.station_class);
 
							_railstation.station_count = stclass->GetSpecCount();
 
							_railstation.station_type  = min((int)_railstation.station_type, max(0, (int)_railstation.station_count - 1));
 

	
 
							this->CheckSelectedSize(StationClass::Get(_railstation.station_class, _railstation.station_type));
 
							this->CheckSelectedSize(stclass->GetSpec(_railstation.station_type));
 

	
 
							NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX);
 
							matrix->SetCount(_railstation.station_count);
 
							matrix->SetClicked(_railstation.station_type);
 
						}
 
						SndPlayFx(SND_15_BEEP);
 
@@ -1309,13 +1311,13 @@ public:
 

	
 
			case WID_BRAS_IMAGE: {
 
				int y = GB(widget, 16, 16);
 
				if (y >= _railstation.station_count) return;
 

	
 
				/* Check station availability callback */
 
				const StationSpec *statspec = StationClass::Get(_railstation.station_class, y);
 
				const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(y);
 
				if (!IsStationAvailable(statspec)) return;
 

	
 
				_railstation.station_type = y;
 

	
 
				this->CheckSelectedSize(statspec);
 
				this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX)->SetClicked(_railstation.station_type);
 
@@ -1432,13 +1434,13 @@ static const WindowDesc _station_builder
 
	_nested_station_builder_widgets, lengthof(_nested_station_builder_widgets)
 
);
 

	
 
/** Open station build window */
 
static void ShowStationBuilder(Window *parent)
 
{
 
	bool newstations = StationClass::GetCount() > 2 || StationClass::GetCount(STAT_CLASS_DFLT) != 1;
 
	bool newstations = StationClass::GetCount() > 2 || StationClass::Get(STAT_CLASS_DFLT)->GetSpecCount() != 1;
 
	new BuildRailStationWindow(&_station_builder_desc, parent, newstations);
 
}
 

	
 
struct BuildSignalWindow : public PickerWindowBase {
 
private:
 
	/**
 
@@ -1738,13 +1740,13 @@ struct BuildRailWaypointWindow : PickerW
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (GB(widget, 0, 16)) {
 
			case WID_BRW_WAYPOINT: {
 
				byte type = GB(widget, 16, 16);
 
				const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, type);
 
				const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
 
				DrawWaypointSprite(r.left + TILE_PIXELS, r.bottom - TILE_PIXELS, type, _cur_railtype);
 

	
 
				if (!IsStationAvailable(statspec)) {
 
					GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
 
				}
 
			}
 
@@ -1756,13 +1758,13 @@ struct BuildRailWaypointWindow : PickerW
 
		switch (GB(widget, 0, 16)) {
 
			case WID_BRW_WAYPOINT: {
 
				byte type = GB(widget, 16, 16);
 
				this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
 

	
 
				/* Check station availability callback */
 
				const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, type);
 
				const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
 
				if (!IsStationAvailable(statspec)) return;
 

	
 
				_cur_waypoint_type = type;
 
				this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
 
				SndPlayFx(SND_15_BEEP);
 
				this->SetDirty();
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -73,21 +73,22 @@ void MoveWaypointsToBaseStations()
 
			if (wp->delete_ctr != 0) continue; // The waypoint was deleted
 

	
 
			/* Waypoint indices were not added to the map prior to this. */
 
			_m[wp->xy].m2 = (StationID)wp->index;
 

	
 
			if (HasBit(_m[wp->xy].m3, 4)) {
 
				wp->spec = StationClass::Get(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1);
 
				wp->spec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(_m[wp->xy].m4 + 1);
 
			}
 
		}
 
	} else {
 
		/* As of version 17, we recalculate the custom graphic ID of waypoints
 
		 * from the GRF ID / station index. */
 
		for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
 
			for (uint i = 0; i < StationClass::GetCount(STAT_CLASS_WAYP); i++) {
 
				const StationSpec *statspec =  StationClass::Get(STAT_CLASS_WAYP, i);
 
			StationClass* stclass = StationClass::Get(STAT_CLASS_WAYP);
 
			for (uint i = 0; i < stclass->GetSpecCount(); i++) {
 
				const StationSpec *statspec = stclass->GetSpec(i);
 
				if (statspec != NULL && statspec->grf_prop.grffile->grfid == wp->grfid && statspec->grf_prop.local_id == wp->localidx) {
 
					wp->spec = statspec;
 
					break;
 
				}
 
			}
 
		}
src/station_cmd.cpp
Show inline comments
 
@@ -741,13 +741,13 @@ CommandCost CheckFlatLand(TileArea tile_
 
static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, Axis axis, StationID *station, RailType rt, SmallVector<Train *, 4> &affected_vehicles, StationClassID spec_class, byte spec_index, byte plat_len, byte numtracks)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	int allowed_z = -1;
 
	uint invalid_dirs = 5 << axis;
 

	
 
	const StationSpec *statspec = StationClass::Get(spec_class, spec_index);
 
	const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
 
	bool slope_cb = statspec != NULL && HasBit(statspec->callback_mask, CBM_STATION_SLOPE_CHECK);
 

	
 
	TILE_AREA_LOOP(tile_cur, tile_area) {
 
		CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 
@@ -1103,13 +1103,13 @@ CommandCost CmdBuildRailStation(TileInde
 
	if (ret.Failed()) return ret;
 

	
 
	if (!ValParamRailtype(rt)) return CMD_ERROR;
 

	
 
	/* Check if the given station class is valid */
 
	if ((uint)spec_class >= StationClass::GetCount() || spec_class == STAT_CLASS_WAYP) return CMD_ERROR;
 
	if (spec_index >= StationClass::GetCount(spec_class)) return CMD_ERROR;
 
	if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
 
	if (plat_len == 0 || numtracks == 0) return CMD_ERROR;
 

	
 
	int w_org, h_org;
 
	if (axis == AXIS_X) {
 
		w_org = plat_len;
 
		h_org = numtracks;
 
@@ -1172,13 +1172,13 @@ CommandCost CmdBuildRailStation(TileInde
 
				SetBit(st->town->have_ratings, _current_company);
 
			}
 
		}
 
	}
 

	
 
	/* Check if we can allocate a custom stationspec to this station */
 
	const StationSpec *statspec = StationClass::Get(spec_class, spec_index);
 
	const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
 
	int specindex = AllocateSpecToStation(statspec, st, (flags & DC_EXEC) != 0);
 
	if (specindex == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
 

	
 
	if (statspec != NULL) {
 
		/* Perform NewStation checks */
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -167,13 +167,13 @@ CommandCost CmdBuildRailWaypoint(TileInd
 
	StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
 
	byte spec_index           = GB(p2, 8, 8);
 
	StationID station_to_join = GB(p2, 16, 16);
 

	
 
	/* Check if the given station class is valid */
 
	if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
 
	if (spec_index >= StationClass::GetCount(spec_class)) return CMD_ERROR;
 
	if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
 

	
 
	/* The number of parts to build */
 
	byte count = axis == AXIS_X ? height : width;
 

	
 
	if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR;
 
	if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR;
 
@@ -239,13 +239,13 @@ CommandCost CmdBuildRailWaypoint(TileInd
 
		wp->train_station = new_location;
 

	
 
		if (wp->town == NULL) MakeDefaultName(wp);
 

	
 
		wp->UpdateVirtCoord();
 

	
 
		const StationSpec *spec = StationClass::Get(spec_class, spec_index);
 
		const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index);
 
		byte *layout_ptr = AllocaM(byte, count);
 
		if (spec == NULL) {
 
			/* The layout must be 0 for the 'normal' waypoints by design. */
 
			memset(layout_ptr, 0, count);
 
		} else {
 
			/* But for NewGRF waypoints we like to have their style. */
0 comments (0 inline, 0 general)