Changeset - r12234:fd1a494e7620
[Not reviewed]
master
0 14 0
smatz - 15 years ago 2009-06-25 19:23:09
smatz@openttd.org
(svn r16659) -Codechange: rename GetAcceptedCargo() to AddAcceptedCargo() and change its behaviour accordingly
-Codechange: remove dummy GetAcceptedCargo_*() handlers
14 files changed with 36 insertions and 82 deletions:
0 comments (0 inline, 0 general)
src/clear_cmd.cpp
Show inline comments
 
@@ -109,29 +109,24 @@ static uint GetSlopeZ_Clear(TileIndex ti
 
{
 
	uint z;
 
	Slope tileh = GetTileSlope(tile, &z);
 

	
 
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
 
}
 

	
 
static Foundation GetFoundation_Clear(TileIndex tile, Slope tileh)
 
{
 
	return FOUNDATION_NONE;
 
}
 

	
 
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* unused */
 
}
 

	
 
static void AnimateTile_Clear(TileIndex tile)
 
{
 
	/* unused */
 
}
 

	
 
void TileLoopClearHelper(TileIndex tile)
 
{
 
	bool self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS));
 
	bool dirty = false;
 

	
 
	bool neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS));
 
	if (GetFenceSW(tile) == 0) {
 
@@ -354,24 +349,24 @@ void InitializeClearLand()
 
	_settings_game.game_creation.snow_line = _settings_game.game_creation.snow_line_height * TILE_HEIGHT;
 
}
 

	
 
static CommandCost TerraformTile_Clear(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 
extern const TileTypeProcs _tile_type_clear_procs = {
 
	DrawTile_Clear,           ///< draw_tile_proc
 
	GetSlopeZ_Clear,          ///< get_slope_z_proc
 
	ClearTile_Clear,          ///< clear_tile_proc
 
	GetAcceptedCargo_Clear,   ///< get_accepted_cargo_proc
 
	NULL,                     ///< get_accepted_cargo_proc
 
	GetTileDesc_Clear,        ///< get_tile_desc_proc
 
	GetTileTrackStatus_Clear, ///< get_tile_track_status_proc
 
	ClickTile_Clear,          ///< click_tile_proc
 
	AnimateTile_Clear,        ///< animate_tile_proc
 
	TileLoop_Clear,           ///< tile_loop_clear
 
	ChangeTileOwner_Clear,    ///< change_tile_owner_clear
 
	NULL,                     ///< get_produced_cargo_proc
 
	NULL,                     ///< vehicle_enter_tile_proc
 
	GetFoundation_Clear,      ///< get_foundation_proc
 
	TerraformTile_Clear,      ///< terraform_tile_proc
 
};
src/dummy_land.cpp
Show inline comments
 
@@ -24,29 +24,24 @@ static uint GetSlopeZ_Dummy(TileIndex ti
 

	
 
static Foundation GetFoundation_Dummy(TileIndex tile, Slope tileh)
 
{
 
	return FOUNDATION_NONE;
 
}
 

	
 
static CommandCost ClearTile_Dummy(TileIndex tile, DoCommandFlag flags)
 
{
 
	return_cmd_error(STR_ERROR_OFF_EDGE_OF_MAP);
 
}
 

	
 

	
 
static void GetAcceptedCargo_Dummy(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void GetTileDesc_Dummy(TileIndex tile, TileDesc *td)
 
{
 
	td->str = STR_EMPTY;
 
	td->owner[0] = OWNER_NONE;
 
}
 

	
 
static void AnimateTile_Dummy(TileIndex tile)
 
{
 
	/* not used */
 
}
 

	
 
static void TileLoop_Dummy(TileIndex tile)
 
@@ -70,24 +65,24 @@ static TrackStatus GetTileTrackStatus_Du
 
	return 0;
 
}
 

	
 
static CommandCost TerraformTile_Dummy(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	return_cmd_error(STR_ERROR_OFF_EDGE_OF_MAP);
 
}
 

	
 
extern const TileTypeProcs _tile_type_dummy_procs = {
 
	DrawTile_Dummy,           // draw_tile_proc
 
	GetSlopeZ_Dummy,          // get_slope_z_proc
 
	ClearTile_Dummy,          // clear_tile_proc
 
	GetAcceptedCargo_Dummy,   // get_accepted_cargo_proc
 
	NULL,                     // get_accepted_cargo_proc
 
	GetTileDesc_Dummy,        // get_tile_desc_proc
 
	GetTileTrackStatus_Dummy, // get_tile_track_status_proc
 
	ClickTile_Dummy,          // click_tile_proc
 
	AnimateTile_Dummy,        // animate_tile_proc
 
	TileLoop_Dummy,           // tile_loop_clear
 
	ChangeTileOwner_Dummy,    // change_tile_owner_clear
 
	NULL,                     // get_produced_cargo_proc
 
	NULL,                     // vehicle_enter_tile_proc
 
	GetFoundation_Dummy,      // get_foundation_proc
 
	TerraformTile_Dummy,      // terraform_tile_proc
 
};
src/industry_cmd.cpp
Show inline comments
 
@@ -345,25 +345,25 @@ static Foundation GetFoundation_Industry
 
	 * draw the wall of the foundation in this case.
 
	 */
 
	if (gfx >= NEW_INDUSTRYTILEOFFSET) {
 
		const IndustryTileSpec *indts = GetIndustryTileSpec(gfx);
 
		if (indts->grf_prop.spritegroup != NULL && HasBit(indts->callback_flags, CBM_INDT_DRAW_FOUNDATIONS)) {
 
			uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, GetIndustryByTile(tile), tile);
 
			if (callback_res == 0) return FOUNDATION_NONE;
 
		}
 
	}
 
	return FlatteningFoundation(tileh);
 
}
 

	
 
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
 
static void AddAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
 
{
 
	IndustryGfx gfx = GetIndustryGfx(tile);
 
	const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
 

	
 
	/* When we have to use a callback, we put our data in the next two variables */
 
	CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)];
 
	uint8 raw_acceptance[lengthof(itspec->acceptance)];
 

	
 
	/* And then these will always point to a same sized array with the required data */
 
	const CargoID *accepts_cargo = itspec->accepts_cargo;
 
	const uint8 *acceptance = itspec->acceptance;
 

	
 
@@ -376,26 +376,25 @@ static void GetAcceptedCargo_Industry(Ti
 
	}
 

	
 
	if (HasBit(itspec->callback_flags, CBM_INDT_CARGO_ACCEPTANCE)) {
 
		uint16 res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, GetIndustryByTile(tile), tile);
 
		if (res != CALLBACK_FAILED) {
 
			acceptance = raw_acceptance;
 
			for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_acceptance[i] = GB(res, i * 4, 4);
 
		}
 
	}
 

	
 
	for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) {
 
		CargoID a = accepts_cargo[i];
 
		/* Only set the value once. */
 
		if (a != CT_INVALID && ac[a] == 0) ac[a] = acceptance[i];
 
		if (a != CT_INVALID) ac[a] += acceptance[i];
 
	}
 
}
 

	
 
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
 
{
 
	const Industry *i = GetIndustryByTile(tile);
 
	const IndustrySpec *is = GetIndustrySpec(i->type);
 

	
 
	td->owner[0] = i->owner;
 
	td->str = is->name;
 
	if (!IsIndustryCompleted(tile)) {
 
		SetDParamX(td->dparam, 0, td->str);
 
@@ -2376,24 +2375,24 @@ static CommandCost TerraformTile_Industr
 
				/* allow autoslope */
 
				return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
			}
 
		}
 
	}
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 
extern const TileTypeProcs _tile_type_industry_procs = {
 
	DrawTile_Industry,           // draw_tile_proc
 
	GetSlopeZ_Industry,          // get_slope_z_proc
 
	ClearTile_Industry,          // clear_tile_proc
 
	GetAcceptedCargo_Industry,   // get_accepted_cargo_proc
 
	AddAcceptedCargo_Industry,   // add_accepted_cargo_proc
 
	GetTileDesc_Industry,        // get_tile_desc_proc
 
	GetTileTrackStatus_Industry, // get_tile_track_status_proc
 
	ClickTile_Industry,          // click_tile_proc
 
	AnimateTile_Industry,        // animate_tile_proc
 
	TileLoop_Industry,           // tile_loop_proc
 
	ChangeTileOwner_Industry,    // change_tile_owner_proc
 
	GetProducedCargo_Industry,   // get_produced_cargo_proc
 
	NULL,                        // vehicle_enter_tile_proc
 
	GetFoundation_Industry,      // get_foundation_proc
 
	TerraformTile_Industry,      // terraform_tile_proc
 
};
src/landscape.cpp
Show inline comments
 
@@ -491,30 +491,24 @@ TrackStatus GetTileTrackStatus(TileIndex
 

	
 
/**
 
 * Change the owner of a tile
 
 * @param tile      Tile to change
 
 * @param old_owner Current owner of the tile
 
 * @param new_owner New owner of the tile
 
 */
 
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
 
{
 
	_tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
 
}
 

	
 
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac)
 
{
 
	memset(ac, 0, sizeof(AcceptedCargo));
 
	_tile_type_procs[GetTileType(tile)]->get_accepted_cargo_proc(tile, ac);
 
}
 

	
 
void AnimateTile(TileIndex tile)
 
{
 
	_tile_type_procs[GetTileType(tile)]->animate_tile_proc(tile);
 
}
 

	
 
bool ClickTile(TileIndex tile)
 
{
 
	return _tile_type_procs[GetTileType(tile)]->click_tile_proc(tile);
 
}
 

	
 
void GetTileDesc(TileIndex tile, TileDesc *td)
 
{
src/misc_gui.cpp
Show inline comments
 
@@ -99,47 +99,48 @@ public:
 

	
 
		if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
 
			SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
 
			DrawStringMultiLine(this->widget[LIW_BACKGROUND].left + 2, this->widget[LIW_BACKGROUND].right - 2, y, y + 22, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
 
		}
 
	}
 

	
 
	LandInfoWindow(TileIndex tile) : Window(&_land_info_desc) {
 
		Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
 

	
 
		/* Because build_date is not set yet in every TileDesc, we make sure it is empty */
 
		TileDesc td;
 
		AcceptedCargo ac;
 

	
 
		td.build_date = INVALID_DATE;
 

	
 
		/* Most tiles have only one owner, but
 
		 *  - drivethrough roadstops can be build on town owned roads (up to 2 owners) and
 
		 *  - roads can have up to four owners (railroad, road, tram, 3rd-roadtype "highway").
 
		 */
 
		td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A".
 
		td.owner_type[1] = STR_NULL;       // STR_NULL results in skipping the owner
 
		td.owner_type[2] = STR_NULL;
 
		td.owner_type[3] = STR_NULL;
 
		td.owner[0] = OWNER_NONE;
 
		td.owner[1] = OWNER_NONE;
 
		td.owner[2] = OWNER_NONE;
 
		td.owner[3] = OWNER_NONE;
 

	
 
		td.station_class = STR_NULL;
 
		td.station_name = STR_NULL;
 

	
 
		td.grf = NULL;
 

	
 
		GetAcceptedCargo(tile, ac);
 
		AcceptedCargo ac;
 
		memset(ac, 0, sizeof(AcceptedCargo));
 
		AddAcceptedCargo(tile, ac);
 
		GetTileDesc(tile, &td);
 

	
 
		uint line_nr = 0;
 

	
 
		/* Tiletype */
 
		SetDParam(0, td.dparam[0]);
 
		GetString(this->landinfo_data[line_nr], td.str, lastof(this->landinfo_data[line_nr]));
 
		line_nr++;
 

	
 
		/* Up to four owners */
 
		for (uint i = 0; i < 4; i++) {
 
			if (td.owner_type[i] == STR_NULL) continue;
src/rail_cmd.cpp
Show inline comments
 
@@ -2065,29 +2065,24 @@ static uint GetSlopeZ_Track(TileIndex ti
 
		z += ApplyFoundationToSlope(GetRailFoundation(tileh, GetTrackBits(tile)), &tileh);
 
		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
 
	} else {
 
		return z + TILE_HEIGHT;
 
	}
 
}
 

	
 
static Foundation GetFoundation_Track(TileIndex tile, Slope tileh)
 
{
 
	return IsPlainRail(tile) ? GetRailFoundation(tileh, GetTrackBits(tile)) : FlatteningFoundation(tileh);
 
}
 

	
 
static void GetAcceptedCargo_Track(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void AnimateTile_Track(TileIndex tile)
 
{
 
	/* not used */
 
}
 

	
 
static void TileLoop_Track(TileIndex tile)
 
{
 
	RailGroundType old_ground = GetRailGroundType(tile);
 
	RailGroundType new_ground;
 

	
 
	if (old_ground == RAIL_GROUND_WATER) {
 
		TileLoop_Water(tile);
 
@@ -2611,24 +2606,24 @@ static CommandCost TerraformTile_Track(T
 
				default: NOT_REACHED();
 
			}
 
		}
 
	}
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 

	
 
extern const TileTypeProcs _tile_type_rail_procs = {
 
	DrawTile_Track,           // draw_tile_proc
 
	GetSlopeZ_Track,          // get_slope_z_proc
 
	ClearTile_Track,          // clear_tile_proc
 
	GetAcceptedCargo_Track,   // get_accepted_cargo_proc
 
	NULL,                     // get_accepted_cargo_proc
 
	GetTileDesc_Track,        // get_tile_desc_proc
 
	GetTileTrackStatus_Track, // get_tile_track_status_proc
 
	ClickTile_Track,          // click_tile_proc
 
	AnimateTile_Track,        // animate_tile_proc
 
	TileLoop_Track,           // tile_loop_clear
 
	ChangeTileOwner_Track,    // change_tile_owner_clear
 
	NULL,                     // get_produced_cargo_proc
 
	VehicleEnter_Track,       // vehicle_enter_tile_proc
 
	GetFoundation_Track,      // get_foundation_proc
 
	TerraformTile_Track,      // terraform_tile_proc
 
};
src/road_cmd.cpp
Show inline comments
 
@@ -1278,29 +1278,24 @@ static uint GetSlopeZ_Road(TileIndex til
 
	}
 
}
 

	
 
static Foundation GetFoundation_Road(TileIndex tile, Slope tileh)
 
{
 
	if (IsNormalRoad(tile)) {
 
		return GetRoadFoundation(tileh, GetAllRoadBits(tile));
 
	} else {
 
		return FlatteningFoundation(tileh);
 
	}
 
}
 

	
 
static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void AnimateTile_Road(TileIndex tile)
 
{
 
	if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile);
 
}
 

	
 

	
 
static const Roadside _town_road_types[][2] = {
 
	{ ROADSIDE_GRASS,         ROADSIDE_GRASS },
 
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
 
	{ ROADSIDE_PAVED,         ROADSIDE_PAVED },
 
	{ ROADSIDE_TREES,         ROADSIDE_TREES },
 
	{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
 
@@ -1628,24 +1623,24 @@ static CommandCost TerraformTile_Road(Ti
 
			default: NOT_REACHED();
 
		}
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 
/** Tile callback functions for road tiles */
 
extern const TileTypeProcs _tile_type_road_procs = {
 
	DrawTile_Road,           // draw_tile_proc
 
	GetSlopeZ_Road,          // get_slope_z_proc
 
	ClearTile_Road,          // clear_tile_proc
 
	GetAcceptedCargo_Road,   // get_accepted_cargo_proc
 
	NULL,                    // get_accepted_cargo_proc
 
	GetTileDesc_Road,        // get_tile_desc_proc
 
	GetTileTrackStatus_Road, // get_tile_track_status_proc
 
	ClickTile_Road,          // click_tile_proc
 
	AnimateTile_Road,        // animate_tile_proc
 
	TileLoop_Road,           // tile_loop_clear
 
	ChangeTileOwner_Road,    // change_tile_owner_clear
 
	NULL,                    // get_produced_cargo_proc
 
	VehicleEnter_Road,       // vehicle_enter_tile_proc
 
	GetFoundation_Road,      // get_foundation_proc
 
	TerraformTile_Road,      // terraform_tile_proc
 
};
src/station_cmd.cpp
Show inline comments
 
@@ -515,31 +515,25 @@ void GetAcceptanceAroundTiles(AcceptedCa
 
	int y2 = min(y + h + rad, MapSizeY());
 
	int x1 = max(x - rad, 0);
 
	int y1 = max(y - rad, 0);
 

	
 
	assert(x1 < x2);
 
	assert(y1 < y2);
 
	assert(w > 0);
 
	assert(h > 0);
 

	
 
	for (int yc = y1; yc != y2; yc++) {
 
		for (int xc = x1; xc != x2; xc++) {
 
			TileIndex tile = TileXY(xc, yc);
 

	
 
			if (!IsTileType(tile, MP_STATION)) {
 
				AcceptedCargo ac;
 

	
 
				GetAcceptedCargo(tile, ac);
 
				for (uint i = 0; i < lengthof(ac); ++i) accepts[i] += ac[i];
 
			}
 
			AddAcceptedCargo(tile, accepts);
 
		}
 
	}
 
}
 

	
 
/** Update the acceptance for a station.
 
 * @param st Station to update
 
 * @param show_msg controls whether to display a message that acceptance was changed.
 
 */
 
static void UpdateStationAcceptance(Station *st, bool show_msg)
 
{
 
	/* Don't update acceptance for a buoy */
 
	if (st->IsBuoy()) return;
 
@@ -2339,29 +2333,24 @@ void StationPickerDrawSprite(int x, int 
 
}
 

	
 
static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y)
 
{
 
	return GetTileMaxZ(tile);
 
}
 

	
 
static Foundation GetFoundation_Station(TileIndex tile, Slope tileh)
 
{
 
	return FlatteningFoundation(tileh);
 
}
 

	
 
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
 
{
 
	td->owner[0] = GetTileOwner(tile);
 
	if (IsDriveThroughStopTile(tile)) {
 
		Owner road_owner = INVALID_OWNER;
 
		Owner tram_owner = INVALID_OWNER;
 
		RoadTypes rts = GetRoadTypes(tile);
 
		if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
 
		if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
 

	
 
		/* Is there a mix of owners? */
 
		if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
 
@@ -3154,24 +3143,24 @@ static CommandCost TerraformTile_Station
 
				default: break;
 
			}
 
		}
 
	}
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 

	
 
extern const TileTypeProcs _tile_type_station_procs = {
 
	DrawTile_Station,           // draw_tile_proc
 
	GetSlopeZ_Station,          // get_slope_z_proc
 
	ClearTile_Station,          // clear_tile_proc
 
	GetAcceptedCargo_Station,   // get_accepted_cargo_proc
 
	NULL,                       // get_accepted_cargo_proc
 
	GetTileDesc_Station,        // get_tile_desc_proc
 
	GetTileTrackStatus_Station, // get_tile_track_status_proc
 
	ClickTile_Station,          // click_tile_proc
 
	AnimateTile_Station,        // animate_tile_proc
 
	TileLoop_Station,           // tile_loop_clear
 
	ChangeTileOwner_Station,    // change_tile_owner_clear
 
	NULL,                       // get_produced_cargo_proc
 
	VehicleEnter_Station,       // vehicle_enter_tile_proc
 
	GetFoundation_Station,      // get_foundation_proc
 
	TerraformTile_Station,      // terraform_tile_proc
 
};
src/tile_cmd.h
Show inline comments
 
@@ -7,24 +7,25 @@
 

	
 
#include "slope_type.h"
 
#include "tile_type.h"
 
#include "command_type.h"
 
#include "vehicle_type.h"
 
#include "cargo_type.h"
 
#include "strings_type.h"
 
#include "date_type.h"
 
#include "company_type.h"
 
#include "direction_type.h"
 
#include "track_type.h"
 
#include "transport_type.h"
 
#include "tile_map.h"
 

	
 
/** The returned bits of VehicleEnterTile. */
 
enum VehicleEnterTileStatus {
 
	VETS_ENTERED_STATION  = 1, ///< The vehicle entered a station
 
	VETS_ENTERED_WORMHOLE = 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel)
 
	VETS_CANNOT_ENTER     = 3, ///< The vehicle cannot enter the tile
 

	
 
	/**
 
	 * Shift the VehicleEnterTileStatus this many bits
 
	 * to the right to get the station ID when
 
	 * VETS_ENTERED_STATION is set
 
	 */
 
@@ -64,25 +65,25 @@ struct TileDesc {
 
 * Tile callback function signature for drawing a tile and its contents to the screen
 
 * @param ti Information about the tile to draw
 
 */
 
typedef void DrawTileProc(TileInfo *ti);
 
typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y);
 
typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
 

	
 
/**
 
 * Tile callback function signature for obtaining accepted cargo of a tile
 
 * @param tile Tile queried for its accepted cargo
 
 * @param res  Storage destination of the cargo accepted
 
 */
 
typedef void GetAcceptedCargoProc(TileIndex tile, AcceptedCargo res);
 
typedef void AddAcceptedCargoProc(TileIndex tile, AcceptedCargo res);
 

	
 
/**
 
 * Tile callback function signature for obtaining a tile description
 
 * @param tile Tile being queried
 
 * @param td   Storage pointer for returned tile description
 
 */
 
typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
 

	
 
/**
 
 * Tile callback function signature for getting the possible tracks
 
 * that can be taken on a given tile by a given transport.
 
 *
 
@@ -127,36 +128,42 @@ typedef Foundation GetFoundationProc(Til
 
 * @param tileh_new Slope after terraforming.
 
 * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
 
 */
 
typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new);
 

	
 
/**
 
 * Set of callback functions for performing tile operations of a given tile type.
 
 * @see TileType */
 
struct TileTypeProcs {
 
	DrawTileProc *draw_tile_proc;                  ///< Called to render the tile and its contents to the screen
 
	GetSlopeZProc *get_slope_z_proc;
 
	ClearTileProc *clear_tile_proc;
 
	GetAcceptedCargoProc *get_accepted_cargo_proc; ///< Return accepted cargo of the tile
 
	AddAcceptedCargoProc *add_accepted_cargo_proc; ///< Adds accepted cargo of the tile to cargo array supplied as parameter
 
	GetTileDescProc *get_tile_desc_proc;           ///< Get a description of a tile (for the 'land area information' tool)
 
	GetTileTrackStatusProc *get_tile_track_status_proc; ///< Get available tracks and status of a tile
 
	ClickTileProc *click_tile_proc;                ///< Called when tile is clicked
 
	AnimateTileProc *animate_tile_proc;
 
	TileLoopProc *tile_loop_proc;
 
	ChangeTileOwnerProc *change_tile_owner_proc;
 
	GetProducedCargoProc *get_produced_cargo_proc; ///< Return produced cargo of the tile
 
	VehicleEnterTileProc *vehicle_enter_tile_proc; ///< Called when a vehicle enters a tile
 
	GetFoundationProc *get_foundation_proc;
 
	TerraformTileProc *terraform_tile_proc;        ///< Called when a terraforming operation is about to take place
 
};
 

	
 
extern const TileTypeProcs * const _tile_type_procs[16];
 

	
 
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
 
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
 
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac);
 
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
 
void AnimateTile(TileIndex tile);
 
bool ClickTile(TileIndex tile);
 
void GetTileDesc(TileIndex tile, TileDesc *td);
 

	
 
static inline void AddAcceptedCargo(TileIndex tile, AcceptedCargo ac)
 
{
 
	AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
 
	if (proc == NULL) return;
 
	proc(tile, ac);
 
}
 

	
 
#endif /* TILE_CMD_H */
src/town_cmd.cpp
Show inline comments
 
@@ -560,64 +560,64 @@ static void GetProducedCargo_Town(TileIn
 
			*(b++) = cargo;
 
		}
 
	} else {
 
		if (hs->population > 0) {
 
			*(b++) = CT_PASSENGERS;
 
		}
 
		if (hs->mail_generation > 0) {
 
			*(b++) = CT_MAIL;
 
		}
 
	}
 
}
 

	
 
static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac)
 
static void AddAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac)
 
{
 
	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
 
	CargoID accepts[3];
 

	
 
	/* Set the initial accepted cargo types */
 
	for (uint8 i = 0; i < lengthof(accepts); i++) {
 
		accepts[i] = hs->accepts_cargo[i];
 
	}
 

	
 
	/* Check for custom accepted cargo types */
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) {
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		if (callback != CALLBACK_FAILED) {
 
			/* Replace accepted cargo types with translated values from callback */
 
			accepts[0] = GetCargoTranslation(GB(callback,  0, 5), hs->grffile);
 
			accepts[1] = GetCargoTranslation(GB(callback,  5, 5), hs->grffile);
 
			accepts[2] = GetCargoTranslation(GB(callback, 10, 5), hs->grffile);
 
		}
 
	}
 

	
 
	/* Check for custom cargo acceptance */
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) {
 
		uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
 
		if (callback != CALLBACK_FAILED) {
 
			if (accepts[0] != CT_INVALID) ac[accepts[0]] = GB(callback, 0, 4);
 
			if (accepts[1] != CT_INVALID) ac[accepts[1]] = GB(callback, 4, 4);
 
			if (accepts[0] != CT_INVALID) ac[accepts[0]] += GB(callback, 0, 4);
 
			if (accepts[1] != CT_INVALID) ac[accepts[1]] += GB(callback, 4, 4);
 
			if (_settings_game.game_creation.landscape != LT_TEMPERATE && HasBit(callback, 12)) {
 
				/* The 'S' bit indicates food instead of goods */
 
				ac[CT_FOOD] = GB(callback, 8, 4);
 
				ac[CT_FOOD] += GB(callback, 8, 4);
 
			} else {
 
				if (accepts[2] != CT_INVALID) ac[accepts[2]] = GB(callback, 8, 4);
 
				if (accepts[2] != CT_INVALID) ac[accepts[2]] += GB(callback, 8, 4);
 
			}
 
			return;
 
		}
 
	}
 

	
 
	/* No custom acceptance, so fill in with the default values */
 
	for (uint8 i = 0; i < lengthof(accepts); i++) {
 
		if (accepts[i] != CT_INVALID) ac[accepts[i]] = hs->cargo_acceptance[i];
 
		if (accepts[i] != CT_INVALID) ac[accepts[i]] += hs->cargo_acceptance[i];
 
	}
 
}
 

	
 
static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
 
{
 
	const HouseID house = GetHouseType(tile);
 
	const HouseSpec *hs = GetHouseSpecs(house);
 
	bool house_completed = IsHouseCompleted(tile);
 

	
 
	td->str = hs->building_name;
 

	
 
	uint16 callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, GetTownByTile(tile), tile);
 
@@ -2874,25 +2874,25 @@ static CommandCost TerraformTile_Town(Ti
 
		if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
 
			(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 
/** Tile callback functions for a town */
 
extern const TileTypeProcs _tile_type_town_procs = {
 
	DrawTile_Town,           // draw_tile_proc
 
	GetSlopeZ_Town,          // get_slope_z_proc
 
	ClearTile_Town,          // clear_tile_proc
 
	GetAcceptedCargo_Town,   // get_accepted_cargo_proc
 
	AddAcceptedCargo_Town,   // add_accepted_cargo_proc
 
	GetTileDesc_Town,        // get_tile_desc_proc
 
	GetTileTrackStatus_Town, // get_tile_track_status_proc
 
	ClickTile_Town,          // click_tile_proc
 
	AnimateTile_Town,        // animate_tile_proc
 
	TileLoop_Town,           // tile_loop_clear
 
	ChangeTileOwner_Town,    // change_tile_owner_clear
 
	GetProducedCargo_Town,   // get_produced_cargo_proc
 
	NULL,                    // vehicle_enter_tile_proc
 
	GetFoundation_Town,      // get_foundation_proc
 
	TerraformTile_Town,      // terraform_tile_proc
 
};
 

	
src/tree_cmd.cpp
Show inline comments
 
@@ -535,29 +535,24 @@ static CommandCost ClearTile_Trees(TileI
 
		Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
 
		if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
 
	}
 

	
 
	num = GetTreeCount(tile);
 
	if (IsInsideMM(GetTreeType(tile), TREE_RAINFOREST, TREE_CACTUS)) num *= 4;
 

	
 
	if (flags & DC_EXEC) DoClearSquare(tile);
 

	
 
	return CommandCost(EXPENSES_CONSTRUCTION, num * _price.remove_trees);
 
}
 

	
 
static void GetAcceptedCargo_Trees(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void GetTileDesc_Trees(TileIndex tile, TileDesc *td)
 
{
 
	TreeType tt = GetTreeType(tile);
 

	
 
	if (IsInsideMM(tt, TREE_RAINFOREST, TREE_CACTUS)) {
 
		td->str = STR_TREE_NAME_RAINFOREST;
 
	} else {
 
		td->str = tt == TREE_CACTUS ? STR_TREE_NAME_CACTUS_PLANTS : STR_TREE_NAME_TREES;
 
	}
 

	
 
	td->owner[0] = GetTileOwner(tile);
 
}
 
@@ -764,24 +759,24 @@ void InitializeTrees()
 
}
 

	
 
static CommandCost TerraformTile_Trees(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 

	
 
extern const TileTypeProcs _tile_type_trees_procs = {
 
	DrawTile_Trees,           // draw_tile_proc
 
	GetSlopeZ_Trees,          // get_slope_z_proc
 
	ClearTile_Trees,          // clear_tile_proc
 
	GetAcceptedCargo_Trees,   // get_accepted_cargo_proc
 
	NULL,                     // get_accepted_cargo_proc
 
	GetTileDesc_Trees,        // get_tile_desc_proc
 
	GetTileTrackStatus_Trees, // get_tile_track_status_proc
 
	ClickTile_Trees,          // click_tile_proc
 
	AnimateTile_Trees,        // animate_tile_proc
 
	TileLoop_Trees,           // tile_loop_clear
 
	ChangeTileOwner_Trees,    // change_tile_owner_clear
 
	NULL,                     // get_produced_cargo_proc
 
	NULL,                     // vehicle_enter_tile_proc
 
	GetFoundation_Trees,      // get_foundation_proc
 
	TerraformTile_Trees,      // terraform_tile_proc
 
};
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -1238,30 +1238,24 @@ static uint GetSlopeZ_TunnelBridge(TileI
 
			return z + 1 + delta;
 
		}
 
	}
 

	
 
	return z + GetPartialZ(x, y, tileh);
 
}
 

	
 
static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh)
 
{
 
	return IsTunnel(tile) ? FOUNDATION_NONE : GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(tile)));
 
}
 

	
 

	
 
static void GetAcceptedCargo_TunnelBridge(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
 
{
 
	TransportType tt = GetTunnelBridgeTransportType(tile);
 

	
 
	if (IsTunnel(tile)) {
 
		td->str = (tt == TRANSPORT_RAIL) ? STR_TUNNEL_DESCRIPTION_RAILROAD : STR_TUNNEL_DESCRIPTION_ROAD;
 
	} else { // IsBridge(tile)
 
		td->str = (tt == TRANSPORT_WATER) ? STR_BRIDGE_DESCRIPTION_AQUEDUCT : GetBridgeSpec(GetBridgeType(tile))->transport_name[tt];
 
	}
 
	td->owner[0] = GetTileOwner(tile);
 

	
 
	Owner road_owner = INVALID_OWNER;
 
@@ -1537,24 +1531,24 @@ static CommandCost TerraformTile_TunnelB
 

	
 
		/* Surface slope is valid and remains unchanged? */
 
		if (!CmdFailed(res) && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
 
	DrawTile_TunnelBridge,           // draw_tile_proc
 
	GetSlopeZ_TunnelBridge,          // get_slope_z_proc
 
	ClearTile_TunnelBridge,          // clear_tile_proc
 
	GetAcceptedCargo_TunnelBridge,   // get_accepted_cargo_proc
 
	NULL,                            // get_accepted_cargo_proc
 
	GetTileDesc_TunnelBridge,        // get_tile_desc_proc
 
	GetTileTrackStatus_TunnelBridge, // get_tile_track_status_proc
 
	ClickTile_TunnelBridge,          // click_tile_proc
 
	AnimateTile_TunnelBridge,        // animate_tile_proc
 
	TileLoop_TunnelBridge,           // tile_loop_clear
 
	ChangeTileOwner_TunnelBridge,    // change_tile_owner_clear
 
	NULL,                            // get_produced_cargo_proc
 
	VehicleEnter_TunnelBridge,       // vehicle_enter_tile_proc
 
	GetFoundation_TunnelBridge,      // get_foundation_proc
 
	TerraformTile_TunnelBridge,      // terraform_tile_proc
 
};
src/unmovable_cmd.cpp
Show inline comments
 
@@ -282,43 +282,43 @@ static CommandCost ClearTile_Unmovable(T
 
		TownID town = GetStatueTownID(tile);
 
		ClrBit(Town::Get(town)->statues, GetTileOwner(tile));
 
		InvalidateWindow(WC_TOWN_AUTHORITY, town);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
static void GetAcceptedCargo_Unmovable(TileIndex tile, AcceptedCargo ac)
 
static void AddAcceptedCargo_Unmovable(TileIndex tile, AcceptedCargo ac)
 
{
 
	if (!IsCompanyHQ(tile)) return;
 

	
 
	/* HQ accepts passenger and mail; but we have to divide the values
 
	 * between 4 tiles it occupies! */
 

	
 
	/* HQ level (depends on company performance) in the range 1..5. */
 
	uint level = GetCompanyHQSize(tile) + 1;
 

	
 
	/* Top town building generates 10, so to make HQ interesting, the top
 
	 * type makes 20. */
 
	ac[CT_PASSENGERS] = max(1U, level);
 
	ac[CT_PASSENGERS] += max(1U, level);
 

	
 
	/* Top town building generates 4, HQ can make up to 8. The
 
	 * proportion passengers:mail is different because such a huge
 
	 * commercial building generates unusually high amount of mail
 
	 * correspondence per physical visitor. */
 
	ac[CT_MAIL] = max(1U, level / 2);
 
	ac[CT_MAIL] += max(1U, level / 2);
 
}
 

	
 

	
 
static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td)
 
{
 
	td->str = GetUnmovableSpec(GetUnmovableType(tile))->name;
 
	td->owner[0] = GetTileOwner(tile);
 
}
 

	
 
static void AnimateTile_Unmovable(TileIndex tile)
 
{
 
	/* not used */
 
@@ -492,24 +492,24 @@ static CommandCost TerraformTile_Unmovab
 

	
 
	if (AutoslopeEnabled() && (IsStatue(tile) || IsCompanyHQ(tile))) {
 
		if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 
extern const TileTypeProcs _tile_type_unmovable_procs = {
 
	DrawTile_Unmovable,             // draw_tile_proc
 
	GetSlopeZ_Unmovable,            // get_slope_z_proc
 
	ClearTile_Unmovable,            // clear_tile_proc
 
	GetAcceptedCargo_Unmovable,     // get_accepted_cargo_proc
 
	AddAcceptedCargo_Unmovable,     // add_accepted_cargo_proc
 
	GetTileDesc_Unmovable,          // get_tile_desc_proc
 
	GetTileTrackStatus_Unmovable,   // get_tile_track_status_proc
 
	ClickTile_Unmovable,            // click_tile_proc
 
	AnimateTile_Unmovable,          // animate_tile_proc
 
	TileLoop_Unmovable,             // tile_loop_clear
 
	ChangeTileOwner_Unmovable,      // change_tile_owner_clear
 
	NULL,                           // get_produced_cargo_proc
 
	NULL,                           // vehicle_enter_tile_proc
 
	GetFoundation_Unmovable,        // get_foundation_proc
 
	TerraformTile_Unmovable,        // terraform_tile_proc
 
};
src/water_cmd.cpp
Show inline comments
 
@@ -673,29 +673,24 @@ static uint GetSlopeZ_Water(TileIndex ti
 
{
 
	uint z;
 
	Slope tileh = GetTileSlope(tile, &z);
 

	
 
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
 
}
 

	
 
static Foundation GetFoundation_Water(TileIndex tile, Slope tileh)
 
{
 
	return FOUNDATION_NONE;
 
}
 

	
 
static void GetAcceptedCargo_Water(TileIndex tile, AcceptedCargo ac)
 
{
 
	/* not used */
 
}
 

	
 
static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
 
{
 
	switch (GetWaterTileType(tile)) {
 
		case WATER_TILE_CLEAR:
 
			switch (GetWaterClass(tile)) {
 
				case WATER_CLASS_SEA:   td->str = STR_WATER_DESCRIPTION_WATER;     break;
 
				case WATER_CLASS_CANAL: td->str = STR_LANDINFO_CANAL; break;
 
				case WATER_CLASS_RIVER: td->str = STR_LANDINFO_RIVER; break;
 
				default: assert(0); break;
 
			}
 
			break;
 
		case WATER_TILE_COAST: td->str = STR_WATER_DESCRIPTION_COAST_OR_RIVERBANK; break;
 
@@ -1151,24 +1146,24 @@ static CommandCost TerraformTile_Water(T
 
{
 
	/* Canals can't be terraformed */
 
	if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_MUST_DEMOLISH_CANAL_FIRST);
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
 

	
 
extern const TileTypeProcs _tile_type_water_procs = {
 
	DrawTile_Water,           // draw_tile_proc
 
	GetSlopeZ_Water,          // get_slope_z_proc
 
	ClearTile_Water,          // clear_tile_proc
 
	GetAcceptedCargo_Water,   // get_accepted_cargo_proc
 
	NULL,                     // get_accepted_cargo_proc
 
	GetTileDesc_Water,        // get_tile_desc_proc
 
	GetTileTrackStatus_Water, // get_tile_track_status_proc
 
	ClickTile_Water,          // click_tile_proc
 
	AnimateTile_Water,        // animate_tile_proc
 
	TileLoop_Water,           // tile_loop_clear
 
	ChangeTileOwner_Water,    // change_tile_owner_clear
 
	NULL,                     // get_produced_cargo_proc
 
	VehicleEnter_Water,       // vehicle_enter_tile_proc
 
	GetFoundation_Water,      // get_foundation_proc
 
	TerraformTile_Water,      // terraform_tile_proc
 
};
0 comments (0 inline, 0 general)