summaryrefslogtreecommitdiff
path: root/town_cmd.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-06-10 08:37:41 +0000
committertron <tron@openttd.org>2006-06-10 08:37:41 +0000
commit0a72639c2d7254c37cd6f8ab0a9fa0f4d63fd2ea (patch)
treeddcc7798b94be03152e4b31cee4bf48bc73774e4 /town_cmd.c
parent15c945c9263ffd64f01fd3da92fcb4efb17fe691 (diff)
downloadopenttd-0a72639c2d7254c37cd6f8ab0a9fa0f4d63fd2ea.tar.xz
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
Diffstat (limited to 'town_cmd.c')
-rw-r--r--town_cmd.c53
1 files changed, 23 insertions, 30 deletions
diff --git a/town_cmd.c b/town_cmd.c
index 753be77b4..825f17509 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1063,17 +1063,20 @@ bool GenerateTowns(void)
uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
do {
- if (CreateRandomTown(20, 0) != NULL) //try 20 times to create a random-sized town for the first loop.
- num++;
+ // try 20 times to create a random-sized town for the first loop.
+ if (CreateRandomTown(20, 0) != NULL) num++;
} while (--n);
// give it a last try, but now more aggressive
if (num == 0 && CreateRandomTown(10000, 0) == NULL) {
- Town *t;
- FOR_ALL_TOWNS(t) { if (IsValidTown(t)) {num = 1; break;}}
+ const Town* t;
+
+ FOR_ALL_TOWNS(t) if (IsValidTown(t)) return true;
//XXX can we handle that more gracefully?
- if (num == 0 && _game_mode != GM_EDITOR) error("Could not generate any town");
+ if (num == 0 && _game_mode != GM_EDITOR) {
+ error("Could not generate any town");
+ }
return false;
}
@@ -1102,19 +1105,18 @@ static bool CheckBuildHouseMode(TileIndex tile, Slope tileh, int mode)
return !CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR));
}
-int GetTownRadiusGroup(const Town *t, TileIndex tile)
+
+uint GetTownRadiusGroup(const Town* t, TileIndex tile)
{
- uint dist;
- int i,smallest;
+ uint dist = DistanceSquare(tile, t->xy);
+ uint smallest;
+ uint i;
- dist = DistanceSquare(tile, t->xy);
- if (t->fund_buildings_months && dist <= 25)
- return 4;
+ if (t->fund_buildings_months && dist <= 25) return 4;
smallest = 0;
for (i = 0; i != lengthof(t->radius); i++) {
- if (dist < t->radius[i])
- smallest = i;
+ if (dist < t->radius[i]) smallest = i;
}
return smallest;
@@ -1160,8 +1162,7 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
uint rad = GetTownRadiusGroup(t, tile);
int land = _opt.landscape;
- if (land == LT_HILLY && z >= _opt.snow_line)
- land = -1;
+ if (land == LT_HILLY && z >= _opt.snow_line) land = -1;
bitmask = (1 << rad) + (1 << (land + 12));
}
@@ -1259,8 +1260,6 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
size_flags = GB(_housetype_extra_flags[house], 2, 3);
MakeTownHouse(tile, t->index, construction_counter, construction_stage, size_flags, house);
}
-
- // ENDING
}
static bool BuildTownHouse(Town *t, TileIndex tile)
@@ -1710,11 +1709,10 @@ static void UpdateTownAmounts(Town *t)
static void UpdateTownUnwanted(Town *t)
{
- Player *p;
+ const Player* p;
FOR_ALL_PLAYERS(p) {
- if (t->unwanted[p->index] > 0)
- t->unwanted[p->index]--;
+ if (t->unwanted[p->index] > 0) t->unwanted[p->index]--;
}
}
@@ -1722,15 +1720,12 @@ bool CheckIfAuthorityAllows(TileIndex tile)
{
Town *t;
- if (_current_player >= MAX_PLAYERS)
- return true;
+ if (_current_player >= MAX_PLAYERS) return true;
t = ClosestTownFromTile(tile, _patches.dist_local_authority);
- if (t == NULL)
- return true;
+ if (t == NULL) return true;
- if (t->ratings[_current_player] > -200)
- return true;
+ if (t->ratings[_current_player] > -200) return true;
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
SetDParam(0, t->index);
@@ -1837,12 +1832,10 @@ void TownsMonthlyLoop(void)
Town *t;
FOR_ALL_TOWNS(t) if (t->xy != 0) {
- if (t->road_build_months != 0)
- t->road_build_months--;
+ if (t->road_build_months != 0) t->road_build_months--;
if (t->exclusive_counter != 0)
- if (--t->exclusive_counter == 0)
- t->exclusivity = (byte)-1;
+ if (--t->exclusive_counter == 0) t->exclusivity = (byte)-1;
UpdateTownGrowRate(t);
UpdateTownAmounts(t);