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
 
@@ -1006,12 +1006,12 @@ void OnTick_Industry(void)
 
}
 

	
 

	
 
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) {
 
@@ -1022,21 +1022,28 @@ static bool CheckNewIndustry_Forest(Tile
 
	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) {
 
@@ -1047,7 +1054,7 @@ static bool CheckNewIndustry_Farm(TileIn
 
	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;
 
@@ -1057,7 +1064,7 @@ static bool CheckNewIndustry_Plantation(
 
	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;
 
@@ -1067,7 +1074,7 @@ static bool CheckNewIndustry_Water(TileI
 
	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;
 
@@ -1076,21 +1083,22 @@ static bool CheckNewIndustry_Lumbermill(
 
	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)
 
@@ -1409,7 +1417,7 @@ int32 CmdBuildIndustry(TileIndex tile, u
 
		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;
 
@@ -1445,7 +1453,7 @@ Industry *CreateNewIndustry(TileIndex ti
 

	
 
	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;
table/build_industry.h
Show inline comments
 
@@ -1070,12 +1070,13 @@ static const IndustryTileTable * const _
 
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;
 

	
 
@@ -1115,13 +1116,13 @@ static const IndustrySpec _industry_spec
 
	   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),
town_cmd.c
Show inline comments
 
@@ -1442,18 +1442,22 @@ 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;
 

	
 
@@ -1495,7 +1499,7 @@ static bool DoBuildStatueOfCompany(TileI
 
	return true;
 
}
 

	
 
static void TownActionBuildStatue(Town *t, int action)
 
static void TownActionBuildStatue(Town* t)
 
{
 
	// Layouted as an outward spiral
 
	static const TileIndexDiffC _statue_tiles[] = {
 
@@ -1529,7 +1533,7 @@ static void TownActionBuildStatue(Town *
 
	}
 
}
 

	
 
static void TownActionFundBuildings(Town *t, int action)
 
static void TownActionFundBuildings(Town* t)
 
{
 
	// Build next tick
 
	t->grow_counter = 1;
 
@@ -1539,7 +1543,7 @@ static void TownActionFundBuildings(Town
 
	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;
 
@@ -1547,7 +1551,7 @@ static void TownActionBuyRights(Town *t,
 
	ModifyStationRatingAround(t->xy, _current_player, 130, 17);
 
}
 

	
 
static void TownActionBribe(Town *t, int action)
 
static void TownActionBribe(Town* t)
 
{
 
	if (!RandomRange(15)) {
 
		Station *st;
 
@@ -1580,10 +1584,11 @@ static void TownActionBribe(Town *t, int
 
	}
 
}
 

	
 
typedef void TownActionProc(Town* t);
 
static TownActionProc * const _town_action_proc[] = {
 
	TownActionAdvertise,
 
	TownActionAdvertise,
 
	TownActionAdvertise,
 
	TownActionAdvertiseSmall,
 
	TownActionAdvertiseMedium,
 
	TownActionAdvertiseLarge,
 
	TownActionRoadRebuild,
 
	TownActionBuildStatue,
 
	TownActionFundBuildings,
 
@@ -1616,7 +1621,7 @@ int32 CmdDoTownAction(TileIndex tile, ui
 
	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);
 
	}
 

	
0 comments (0 inline, 0 general)