# HG changeset patch # User tron # Date 1148143597 0 # Node ID 0a298def02020902d995a25df87af42c58025508 # Parent 468642825a109f57fbcf6406f91e2afde4a4a9cc (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. diff -r 468642825a10 -r 0a298def0202 industry_cmd.c --- a/industry_cmd.c Sat May 20 15:13:27 2006 +0000 +++ b/industry_cmd.c Sat May 20 16:46:37 2006 +0000 @@ -1006,12 +1006,12 @@ } -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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; diff -r 468642825a10 -r 0a298def0202 table/build_industry.h --- a/table/build_industry.h Sat May 20 15:13:27 2006 +0000 +++ b/table/build_industry.h Sat May 20 16:46:37 2006 +0000 @@ -1070,12 +1070,13 @@ 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 @@ 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), diff -r 468642825a10 -r 0a298def0202 town_cmd.c --- a/town_cmd.c Sat May 20 15:13:27 2006 +0000 +++ b/town_cmd.c Sat May 20 16:46:37 2006 +0000 @@ -1442,18 +1442,22 @@ 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 @@ 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 TownActionFundBuildings(Town *t, int action) +static void TownActionFundBuildings(Town* t) { // Build next tick t->grow_counter = 1; @@ -1539,7 +1543,7 @@ 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 @@ 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 @@ } } +typedef void TownActionProc(Town* t); static TownActionProc * const _town_action_proc[] = { - TownActionAdvertise, - TownActionAdvertise, - TownActionAdvertise, + TownActionAdvertiseSmall, + TownActionAdvertiseMedium, + TownActionAdvertiseLarge, TownActionRoadRebuild, TownActionBuildStatue, TownActionFundBuildings, @@ -1616,7 +1621,7 @@ 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); }