Changeset - r3877:c0e9cf5b0329
[Not reviewed]
master
0 3 0
tron - 18 years ago 2006-05-20 16:46:37
tron@openttd.org
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
At least in the case of checking for oil industry restrictions this makes the check conditions more clear.
3 files changed with 49 insertions and 35 deletions:
0 comments (0 inline, 0 general)
industry_cmd.c
Show inline comments
 
@@ -1003,97 +1003,105 @@ void OnTick_Industry(void)
 
	FOR_ALL_INDUSTRIES(i) {
 
		if (i->xy != 0) ProduceIndustryGoods(i);
 
	}
 
}
 

	
 

	
 
static bool CheckNewIndustry_NULL(TileIndex tile, IndustryType type)
 
static bool CheckNewIndustry_NULL(TileIndex tile)
 
{
 
	return true;
 
}
 

	
 
static bool CheckNewIndustry_Forest(TileIndex tile, IndustryType type)
 
static bool CheckNewIndustry_Forest(TileIndex tile)
 
{
 
	if (_opt.landscape == LT_HILLY) {
 
		if (GetTileZ(tile) < _opt.snow_line + TILE_HEIGHT * 2U) {
 
			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
 
			return false;
 
		}
 
	}
 
	return true;
 
}
 

	
 
static bool CheckNewIndustry_OilRefinery(TileIndex tile)
 
{
 
	if (_game_mode == GM_EDITOR) return true;
 
	if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < 16) return true;
 

	
 
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
 
	return false;
 
}
 

	
 
extern bool _ignore_restrictions;
 

	
 
/* Oil Rig and Oil Refinery */
 
static bool CheckNewIndustry_Oil(TileIndex tile, IndustryType type)
 
static bool CheckNewIndustry_OilRig(TileIndex tile)
 
{
 
	if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
 
	if (_game_mode == GM_EDITOR && type != IT_OIL_RIG)   return true;
 
	if ((type != IT_OIL_RIG || TileHeight(tile) == 0) &&
 
	if (TileHeight(tile) == 0 &&
 
			DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < 16)   return true;
 

	
 
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
 
	return false;
 
}
 

	
 
static bool CheckNewIndustry_Farm(TileIndex tile, IndustryType type)
 
static bool CheckNewIndustry_Farm(TileIndex tile)
 
{
 
	if (_opt.landscape == LT_HILLY) {
 
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line) {
 
			_error_message = STR_0239_SITE_UNSUITABLE;
 
			return false;
 
		}
 
	}
 
	return true;
 
}
 

	
 
static bool CheckNewIndustry_Plantation(TileIndex tile, IndustryType type)
 
static bool CheckNewIndustry_Plantation(TileIndex tile)
 
{
 
	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
 
		_error_message = STR_0239_SITE_UNSUITABLE;
 
		return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
static bool CheckNewIndustry_Water(TileIndex tile, IndustryType type)
 
static bool CheckNewIndustry_Water(TileIndex tile)
 
{
 
	if (GetTropicZone(tile) != TROPICZONE_DESERT) {
 
		_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT;
 
		return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
static bool CheckNewIndustry_Lumbermill(TileIndex tile, IndustryType type)
 
static bool CheckNewIndustry_Lumbermill(TileIndex tile)
 
{
 
	if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
 
		_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST;
 
		return false;
 
	}
 
	return true;
 
}
 

	
 
static bool CheckNewIndustry_BubbleGen(TileIndex tile, IndustryType type)
 
static bool CheckNewIndustry_BubbleGen(TileIndex tile)
 
{
 
	return GetTileZ(tile) <= TILE_HEIGHT * 4;
 
}
 

	
 
typedef bool CheckNewIndustryProc(TileIndex tile, IndustryType type);
 
typedef bool CheckNewIndustryProc(TileIndex tile);
 
static CheckNewIndustryProc * const _check_new_industry_procs[CHECK_END] = {
 
	CheckNewIndustry_NULL,
 
	CheckNewIndustry_Forest,
 
	CheckNewIndustry_Oil,
 
	CheckNewIndustry_OilRefinery,
 
	CheckNewIndustry_Farm,
 
	CheckNewIndustry_Plantation,
 
	CheckNewIndustry_Water,
 
	CheckNewIndustry_Lumbermill,
 
	CheckNewIndustry_BubbleGen,
 
	CheckNewIndustry_OilRig
 
};
 

	
 
static bool CheckSuitableIndustryPos(TileIndex tile)
 
{
 
	uint x = TileX(tile);
 
	uint y = TileY(tile);
 
@@ -1406,13 +1414,13 @@ int32 CmdBuildIndustry(TileIndex tile, u
 
			indspec->accepts_cargo[1] == CT_INVALID &&
 
			indspec->accepts_cargo[2] == CT_INVALID &&
 
			p1 != IT_LUMBER_MILL) {
 
		return CMD_ERROR;
 
	}
 

	
 
	if (!_check_new_industry_procs[indspec->check_proc](tile, p1)) return CMD_ERROR;
 
	if (!_check_new_industry_procs[indspec->check_proc](tile)) return CMD_ERROR;
 

	
 
	t = CheckMultipleIndustryInTown(tile, p1);
 
	if (t == NULL) return CMD_ERROR;
 

	
 
	num = indspec->num_table;
 
	itt = indspec->table;
 
@@ -1442,13 +1450,13 @@ Industry *CreateNewIndustry(TileIndex ti
 
	const IndustrySpec *indspec;
 

	
 
	if (!CheckSuitableIndustryPos(tile)) return NULL;
 

	
 
	indspec =  GetIndustrySpec(type);
 

	
 
	if (!_check_new_industry_procs[indspec->check_proc](tile, type)) return NULL;
 
	if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
 

	
 
	t = CheckMultipleIndustryInTown(tile, type);
 
	if (t == NULL) return NULL;
 

	
 
	/* pick a random layout */
 
	it = indspec->table[RandomRange(indspec->num_table)];
table/build_industry.h
Show inline comments
 
@@ -1067,18 +1067,19 @@ static const IndustryTileTable * const _
 

	
 
/* Procedures that can be run to check whether an industry may
 
 * build at location the given to the procedure */
 
typedef enum CheckProcs {
 
	CHECK_NOTHING    = 0,
 
	CHECK_FOREST     = 1,
 
	CHECK_OIL        = 2,
 
	CHECK_REFINERY   = 2,
 
	CHECK_FARM       = 3,
 
	CHECK_PLANTATION = 4,
 
	CHECK_WATER      = 5,
 
	CHECK_LUMBERMILL = 6,
 
	CHECK_BUBBLEGEN  = 7,
 
	CHECK_OIL_RIG    = 8,
 
	CHECK_END,
 
} CheckProc;
 

	
 
#define MK(tbl, d, c1, c2, c3, proc, p1, r1, p2, r2, m, a1, a2, a3, s1, s2, s3) \
 
	{tbl, lengthof(tbl), d, {c1, c2, c3}, proc, {p1, p2}, {r1, r2}, m,            \
 
	 {a1, a2, a3},  s1, s2, s3}
 
@@ -1112,19 +1113,19 @@ static const IndustrySpec _industry_spec
 
	   IT_SAWMILL,        IT_PAPER_MILL,       IT_INVALID,       CHECK_FOREST,
 
	   CT_WOOD,       13, CT_INVALID,       0, 30,
 
	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 
	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4835_INCREASES_PRODUCTION,     STR_483A_INSECT_INFESTATION_CAUSES),
 

	
 
	MK(_tile_table_oil_refinery,               31,
 
	   IT_OIL_RIG,        IT_INVALID,          IT_INVALID,       CHECK_OIL,
 
	   IT_OIL_RIG,        IT_INVALID,          IT_INVALID,       CHECK_REFINERY,
 
	   CT_GOODS,       0, CT_INVALID,       0, 5,
 
	   CT_OIL,            CT_INVALID,          CT_INVALID,
 
	   STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,      STR_4835_INCREASES_PRODUCTION,     STR_4839_PRODUCTION_DOWN_BY_50),
 

	
 
	MK(_tile_table_oil_rig,                    240,
 
	   IT_OIL_REFINERY,   IT_INVALID,          IT_INVALID,       CHECK_OIL,
 
	   IT_OIL_REFINERY,   IT_INVALID,          IT_INVALID,       CHECK_OIL_RIG,
 
	   CT_OIL,        15, CT_PASSENGERS,    2, 5,
 
	   CT_INVALID,        CT_INVALID,          CT_INVALID,
 
	   STR_4832_ANNOUNCES_IMMINENT_CLOSURE,    STR_4837_NEW_OIL_RESERVES_FOUND,   STR_4839_PRODUCTION_DOWN_BY_50),
 

	
 
	MK(_tile_table_factory,                    26,
 
	   IT_FARM,           IT_STEEL_MILL,       IT_INVALID,       CHECK_NOTHING,
town_cmd.c
Show inline comments
 
@@ -1439,24 +1439,28 @@ void ExpandTown(Town *t)
 
}
 

	
 
const byte _town_action_costs[8] = {
 
	2, 4, 9, 35, 48, 53, 117, 175
 
};
 

	
 
typedef void TownActionProc(Town *t, int action);
 

	
 
static void TownActionAdvertise(Town *t, int action)
 
static void TownActionAdvertiseSmall(Town* t)
 
{
 
	static const byte _advertising_amount[3] = {0x40, 0x70, 0xA0};
 
	static const byte _advertising_radius[3] = {10, 15, 20};
 
	ModifyStationRatingAround(t->xy, _current_player,
 
		_advertising_amount[action],
 
		_advertising_radius[action]);
 
	ModifyStationRatingAround(t->xy, _current_player, 0x40, 10);
 
}
 

	
 
static void TownActionRoadRebuild(Town *t, int action)
 
static void TownActionAdvertiseMedium(Town* t)
 
{
 
	ModifyStationRatingAround(t->xy, _current_player, 0x70, 15);
 
}
 

	
 
static void TownActionAdvertiseLarge(Town* t)
 
{
 
	ModifyStationRatingAround(t->xy, _current_player, 0xA0, 20);
 
}
 

	
 
static void TownActionRoadRebuild(Town* t)
 
{
 
	const Player* p;
 

	
 
	t->road_build_months = 6;
 

	
 
	SetDParam(0, t->index);
 
@@ -1492,13 +1496,13 @@ static bool DoBuildStatueOfCompany(TileI
 
	MakeStatue(tile, _current_player);
 
	MarkTileDirtyByTile(tile);
 

	
 
	return true;
 
}
 

	
 
static void TownActionBuildStatue(Town *t, int action)
 
static void TownActionBuildStatue(Town* t)
 
{
 
	// Layouted as an outward spiral
 
	static const TileIndexDiffC _statue_tiles[] = {
 
		{-1, 0},
 
		{ 0, 1},
 
		{ 1, 0}, { 1, 0},
 
@@ -1526,31 +1530,31 @@ static void TownActionBuildStatue(Town *
 
	for (p = _statue_tiles; p != endof(_statue_tiles); ++p) {
 
		if (DoBuildStatueOfCompany(tile)) return;
 
		tile = TILE_ADD(tile, ToTileIndexDiff(*p));
 
	}
 
}
 

	
 
static void TownActionFundBuildings(Town *t, int action)
 
static void TownActionFundBuildings(Town* t)
 
{
 
	// Build next tick
 
	t->grow_counter = 1;
 
	// If we were not already growing
 
	SETBIT(t->flags12, TOWN_IS_FUNDED);
 
	// And grow for 3 months
 
	t->fund_buildings_months = 3;
 
}
 

	
 
static void TownActionBuyRights(Town *t, int action)
 
static void TownActionBuyRights(Town* t)
 
{
 
	t->exclusive_counter = 12;
 
	t->exclusivity = _current_player;
 

	
 
	ModifyStationRatingAround(t->xy, _current_player, 130, 17);
 
}
 

	
 
static void TownActionBribe(Town *t, int action)
 
static void TownActionBribe(Town* t)
 
{
 
	if (!RandomRange(15)) {
 
		Station *st;
 

	
 
		// set as unwanted for 6 months
 
		t->unwanted[_current_player] = 6;
 
@@ -1577,16 +1581,17 @@ static void TownActionBribe(Town *t, int
 
		}
 
	} else {
 
		ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM);
 
	}
 
}
 

	
 
typedef void TownActionProc(Town* t);
 
static TownActionProc * const _town_action_proc[] = {
 
	TownActionAdvertise,
 
	TownActionAdvertise,
 
	TownActionAdvertise,
 
	TownActionAdvertiseSmall,
 
	TownActionAdvertiseMedium,
 
	TownActionAdvertiseLarge,
 
	TownActionRoadRebuild,
 
	TownActionBuildStatue,
 
	TownActionFundBuildings,
 
	TownActionBuyRights,
 
	TownActionBribe
 
};
 
@@ -1613,13 +1618,13 @@ int32 CmdDoTownAction(TileIndex tile, ui
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 

	
 
	cost = (_price.build_industry >> 8) * _town_action_costs[p2];
 

	
 
	if (flags & DC_EXEC) {
 
		_town_action_proc[p2](t, p2);
 
		_town_action_proc[p2](t);
 
		InvalidateWindow(WC_TOWN_AUTHORITY, p1);
 
	}
 

	
 
	return cost;
 
}
 

	
0 comments (0 inline, 0 general)