author | glx |
Mon, 24 Sep 2007 03:08:47 +0000 | |
branch | 0.5 |
changeset 5545 | f42dc59a45f5 |
parent 5543 | 4d8dfa498905 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
4 |
#include "openttd.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
5 |
#include "functions.h" |
1309
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1304
diff
changeset
|
6 |
#include "strings.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3071
diff
changeset
|
7 |
#include "road_map.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
8 |
#include "table/strings.h" |
2148
47ba4a1b1c3b
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
9 |
#include "table/sprites.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
543
diff
changeset
|
10 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
11 |
#include "tile.h" |
3319
7d04847e4689
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3310
diff
changeset
|
12 |
#include "town_map.h" |
3154 | 13 |
#include "tunnel_map.h" |
0 | 14 |
#include "viewport.h" |
15 |
#include "town.h" |
|
16 |
#include "command.h" |
|
17 |
#include "gfx.h" |
|
18 |
#include "industry.h" |
|
19 |
#include "station.h" |
|
20 |
#include "player.h" |
|
21 |
#include "news.h" |
|
22 |
#include "saveload.h" |
|
23 |
#include "economy.h" |
|
24 |
#include "gui.h" |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3282
diff
changeset
|
25 |
#include "unmovable_map.h" |
3433
ca2b963c1671
(svn r4262) -Codechange: use IsClearWaterTile instead of some "home-brewn" marco. town_cmd is now map access free
celestar
parents:
3432
diff
changeset
|
26 |
#include "water_map.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
27 |
#include "variables.h" |
3359
d4316b1af327
(svn r4154) -Moved MAX_BRIDGES in bridge.h and made it an enum. This makes two drops ...
celestar
parents:
3319
diff
changeset
|
28 |
#include "bridge.h" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4231
diff
changeset
|
29 |
#include "date.h" |
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
30 |
#include "table/town_land.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
31 |
#include "genworld.h" |
0 | 32 |
|
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
33 |
/** |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
34 |
* Called if a new block is added to the town-pool |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
35 |
*/ |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
36 |
static void TownPoolNewBlock(uint start_item) |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
37 |
{ |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
38 |
Town *t; |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
39 |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
40 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
41 |
* TODO - This is just a temporary stage, this will be removed. */ |
4983 | 42 |
for (t = GetTown(start_item); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) t->index = start_item++; |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
43 |
} |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
44 |
|
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
45 |
/* Initialize the town-pool */ |
5216
d581e4db95b6
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
5118
diff
changeset
|
46 |
DEFINE_OLD_POOL(Town, Town, TownPoolNewBlock, NULL) |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
47 |
|
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
48 |
void DestroyTown(Town *t) |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
49 |
{ |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
50 |
Industry *i; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
51 |
TileIndex tile; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
52 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
53 |
/* Delete town authority window |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
54 |
* and remove from list of sorted towns */ |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
55 |
DeleteWindowById(WC_TOWN_VIEW, t->index); |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
56 |
_town_sort_dirty = true; |
5298
6d4c150bdd94
(svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents:
5247
diff
changeset
|
57 |
_total_towns--; |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
58 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
59 |
/* Delete all industries belonging to the town */ |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
60 |
FOR_ALL_INDUSTRIES(i) if (i->town == t) DeleteIndustry(i); |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
61 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
62 |
/* Go through all tiles and delete those belonging to the town */ |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
63 |
for (tile = 0; tile < MapSize(); ++tile) { |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
64 |
switch (GetTileType(tile)) { |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
65 |
case MP_HOUSE: |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
66 |
if (GetTownByTile(tile) == t) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
67 |
break; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
68 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
69 |
case MP_STREET: |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
70 |
case MP_TUNNELBRIDGE: |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
71 |
if (IsTileOwner(tile, OWNER_TOWN) && |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
72 |
ClosestTownFromTile(tile, (uint)-1) == t) |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
73 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
74 |
break; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
75 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
76 |
default: |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
77 |
break; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
78 |
} |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
79 |
} |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
80 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
81 |
DeleteName(t->townnametype); |
5372 | 82 |
DeleteSubsidyWithTown(t->index); |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
83 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
84 |
MarkWholeScreenDirty(); |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
85 |
} |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
86 |
|
0 | 87 |
// Local |
88 |
static int _grow_town_result; |
|
89 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
90 |
static bool BuildTownHouse(Town *t, TileIndex tile); |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
91 |
static void ClearTownHouse(Town *t, TileIndex tile); |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
92 |
static void DoBuildTownHouse(Town *t, TileIndex tile); |
0 | 93 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2430
diff
changeset
|
94 |
static void TownDrawHouseLift(const TileInfo *ti) |
0 | 95 |
{ |
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
96 |
AddChildSpriteScreen(SPR_LIFT, 14, 60 - GetLiftPosition(ti->tile)); |
0 | 97 |
} |
98 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2430
diff
changeset
|
99 |
typedef void TownDrawTileProc(const TileInfo *ti); |
0 | 100 |
static TownDrawTileProc * const _town_draw_tile_procs[1] = { |
2065
d2872c468206
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
101 |
TownDrawHouseLift |
0 | 102 |
}; |
103 |
||
104 |
||
105 |
static void DrawTile_Town(TileInfo *ti) |
|
106 |
{ |
|
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
107 |
const DrawBuildingsTileStruct *dcts; |
0 | 108 |
uint32 image; |
109 |
||
110 |
/* Retrieve pointer to the draw town tile struct */ |
|
111 |
{ |
|
480
d596ac391933
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
112 |
/* this "randomizes" on the (up to) 4 variants of a building */ |
d596ac391933
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
113 |
uint variant; |
d596ac391933
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
114 |
variant = ti->x >> 4; |
d596ac391933
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
115 |
variant ^= ti->x >> 6; |
d596ac391933
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
116 |
variant ^= ti->y >> 4; |
d596ac391933
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
117 |
variant -= ti->y >> 6; |
d596ac391933
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents:
473
diff
changeset
|
118 |
variant &= 3; |
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
119 |
dcts = &_town_draw_tile_data[GetHouseType(ti->tile) << 4 | variant << 2 | GetHouseBuildingStage(ti->tile)]; |
0 | 120 |
} |
121 |
||
4053 | 122 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh); |
123 |
DrawGroundSprite(dcts->ground); |
|
0 | 124 |
|
125 |
/* Add a house on top of the ground? */ |
|
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
126 |
image = dcts->building; |
2639 | 127 |
if (image != 0) { |
128 |
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
129 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
130 |
AddSortableSpriteToDraw(image, |
482 | 131 |
ti->x + dcts->subtile_x, |
132 |
ti->y + dcts->subtile_y, |
|
133 |
dcts->width + 1, |
|
134 |
dcts->height + 1, |
|
0 | 135 |
dcts->dz, |
4053 | 136 |
ti->z |
137 |
); |
|
0 | 138 |
|
2639 | 139 |
if (_display_opt & DO_TRANS_BUILDINGS) return; |
0 | 140 |
} |
141 |
||
142 |
{ |
|
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
143 |
int proc = dcts->draw_proc - 1; |
2639 | 144 |
|
145 |
if (proc >= 0) _town_draw_tile_procs[proc](ti); |
|
0 | 146 |
} |
147 |
} |
|
148 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
149 |
static uint GetSlopeZ_Town(TileIndex tile, uint x, uint y) |
0 | 150 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
151 |
return GetTileMaxZ(tile); |
0 | 152 |
} |
153 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
154 |
static Slope GetSlopeTileh_Town(TileIndex tile, Slope tileh) |
39 | 155 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
156 |
return SLOPE_FLAT; |
39 | 157 |
} |
158 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
159 |
static void AnimateTile_Town(TileIndex tile) |
0 | 160 |
{ |
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
161 |
int pos, dest; |
0 | 162 |
|
2639 | 163 |
if (_tick_counter & 3) return; |
0 | 164 |
|
2065
d2872c468206
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
165 |
// If the house is not one with a lift anymore, then stop this animating. |
d2872c468206
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
166 |
// Not exactly sure when this happens, but probably when a house changes. |
d2872c468206
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
167 |
// Before this was just a return...so it'd leak animated tiles.. |
d2872c468206
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
168 |
// That bug seems to have been here since day 1?? |
3377
014725164f97
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents:
3359
diff
changeset
|
169 |
if (!(_housetype_extra_flags[GetHouseType(tile)] & 0x20)) { |
2065
d2872c468206
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
170 |
DeleteAnimatedTile(tile); |
d2872c468206
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
171 |
return; |
d2872c468206
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
172 |
} |
0 | 173 |
|
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
174 |
if (!IsLiftMoving(tile)) { |
2639 | 175 |
int i; |
176 |
||
2891
db971f08e6d8
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
177 |
/** Building has 6 floors, number 0 .. 6, where 1 is illegal. |
db971f08e6d8
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
178 |
* This is due to the fact that the first floor is, in the graphics, |
db971f08e6d8
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
179 |
* the height of 2 'normal' floors. |
db971f08e6d8
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
180 |
* Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */ |
0 | 181 |
do { |
2639 | 182 |
i = (Random() & 7) - 1; |
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
183 |
} while (i < 0 || i == 1 || i * 6 == GetLiftPosition(tile)); |
0 | 184 |
|
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
185 |
SetLiftDestination(tile, i); |
0 | 186 |
} |
187 |
||
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
188 |
pos = GetLiftPosition(tile); |
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
189 |
dest = GetLiftDestination(tile) * 6; |
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
190 |
pos += (pos < dest) ? 1 : -1; |
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
191 |
SetLiftPosition(tile, pos); |
0 | 192 |
|
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
193 |
if (pos == dest) HaltLift(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
194 |
|
0 | 195 |
MarkTileDirtyByTile(tile); |
196 |
} |
|
197 |
||
198 |
static void UpdateTownRadius(Town *t); |
|
199 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
200 |
static bool IsCloseToTown(TileIndex tile, uint dist) |
0 | 201 |
{ |
2630 | 202 |
const Town* t; |
0 | 203 |
|
204 |
FOR_ALL_TOWNS(t) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
205 |
if (DistanceManhattan(tile, t->xy) < dist) return true; |
0 | 206 |
} |
207 |
return false; |
|
208 |
} |
|
209 |
||
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
210 |
static void MarkTownSignDirty(Town *t) |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
211 |
{ |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
212 |
MarkAllViewportsDirty( |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
213 |
t->sign.left-6, |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
214 |
t->sign.top-3, |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
215 |
t->sign.left+t->sign.width_1*4+12, |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
216 |
t->sign.top + 45 |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
217 |
); |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
218 |
} |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
219 |
|
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
220 |
void UpdateTownVirtCoord(Town *t) |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
221 |
{ |
836 | 222 |
Point pt; |
223 |
||
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
224 |
MarkTownSignDirty(t); |
3422
12cdb13ddb56
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
225 |
pt = RemapCoords2(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE); |
2070
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2065
diff
changeset
|
226 |
SetDParam(0, t->index); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2065
diff
changeset
|
227 |
SetDParam(1, t->population); |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2065
diff
changeset
|
228 |
UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24, |
26c657906f25
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2065
diff
changeset
|
229 |
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL); |
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
230 |
MarkTownSignDirty(t); |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
231 |
} |
0 | 232 |
|
233 |
static void ChangePopulation(Town *t, int mod) |
|
234 |
{ |
|
235 |
t->population += mod; |
|
236 |
InvalidateWindow(WC_TOWN_VIEW, t->index); |
|
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
237 |
UpdateTownVirtCoord(t); |
0 | 238 |
|
239 |
if (_town_sort_order & 2) _town_sort_dirty = true; |
|
240 |
} |
|
241 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
242 |
uint32 GetWorldPopulation(void) |
1080
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
243 |
{ |
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
244 |
uint32 pop; |
2630 | 245 |
const Town* t; |
246 |
||
1080
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
247 |
pop = 0; |
2639 | 248 |
FOR_ALL_TOWNS(t) pop += t->population; |
1080
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
249 |
return pop; |
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
250 |
} |
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
251 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
252 |
static void MakeSingleHouseBigger(TileIndex tile) |
0 | 253 |
{ |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
254 |
assert(IsTileType(tile, MP_HOUSE)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
255 |
|
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
256 |
if (LiftHasDestination(tile)) return; |
0 | 257 |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
258 |
IncHouseConstructionTick(tile); |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
259 |
if (GetHouseConstructionTick(tile) != 0) return; |
0 | 260 |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
261 |
IncHouseBuildingStage(tile); /*increase construction stage of one more step*/ |
0 | 262 |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
263 |
if (GetHouseBuildingStage(tile) == TOWN_HOUSE_COMPLETED){ |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
264 |
/*Now, construction is completed. Can add population of building to the town*/ |
3377
014725164f97
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents:
3359
diff
changeset
|
265 |
ChangePopulation(GetTownByTile(tile), _housetype_population[GetHouseType(tile)]); |
0 | 266 |
} |
267 |
MarkTileDirtyByTile(tile); |
|
268 |
} |
|
269 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
270 |
static void MakeTownHouseBigger(TileIndex tile) |
0 | 271 |
{ |
3377
014725164f97
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents:
3359
diff
changeset
|
272 |
uint flags = _house_more_flags[GetHouseType(tile)]; |
0 | 273 |
if (flags & 8) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0)); |
274 |
if (flags & 4) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1)); |
|
275 |
if (flags & 2) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0)); |
|
276 |
if (flags & 1) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1)); |
|
277 |
} |
|
278 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
279 |
static void TileLoop_Town(TileIndex tile) |
0 | 280 |
{ |
281 |
int house; |
|
282 |
Town *t; |
|
283 |
uint32 r; |
|
284 |
||
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
285 |
if (GetHouseBuildingStage(tile) != TOWN_HOUSE_COMPLETED) { |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
286 |
/*Construction is not completed. See if we can go further in construction*/ |
0 | 287 |
MakeTownHouseBigger(tile); |
288 |
return; |
|
289 |
} |
|
290 |
||
3377
014725164f97
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents:
3359
diff
changeset
|
291 |
house = GetHouseType(tile); |
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
292 |
if ((_housetype_extra_flags[house] & 0x20) && !LiftHasDestination(tile) && CHANCE16(1, 2) && AddAnimatedTile(tile)) BeginLiftMovement(tile); |
0 | 293 |
|
3319
7d04847e4689
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3310
diff
changeset
|
294 |
t = GetTownByTile(tile); |
0 | 295 |
|
296 |
r = Random(); |
|
297 |
||
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
298 |
if (GB(r, 0, 8) < _housetype_population[house]) { |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
299 |
uint amt = GB(r, 0, 8) / 8 + 1; |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
300 |
uint moved; |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
301 |
|
0 | 302 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
303 |
t->new_max_pass += amt; |
|
304 |
moved = MoveGoodsToStation(tile, 1, 1, CT_PASSENGERS, amt); |
|
305 |
t->new_act_pass += moved; |
|
306 |
} |
|
307 |
||
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
308 |
if (GB(r, 8, 8) < _housetype_mailamount[house] ) { |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
309 |
uint amt = GB(r, 8, 8) / 8 + 1; |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
310 |
uint moved; |
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
311 |
|
0 | 312 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
313 |
t->new_max_mail += amt; |
|
314 |
moved = MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt); |
|
315 |
t->new_act_mail += moved; |
|
316 |
} |
|
317 |
||
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
318 |
if (_house_more_flags[house] & 8 && HASBIT(t->flags12, TOWN_IS_FUNDED) && --t->time_until_rebuild == 0) { |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
319 |
t->time_until_rebuild = GB(r, 16, 6) + 130; |
0 | 320 |
|
321 |
_current_player = OWNER_TOWN; |
|
322 |
||
323 |
ClearTownHouse(t, tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
324 |
|
0 | 325 |
// rebuild with another house? |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
326 |
if (GB(r, 24, 8) >= 12) DoBuildTownHouse(t, tile); |
314 | 327 |
|
328 |
_current_player = OWNER_NONE; |
|
0 | 329 |
} |
330 |
} |
|
331 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
332 |
static void ClickTile_Town(TileIndex tile) |
0 | 333 |
{ |
334 |
/* not used */ |
|
335 |
} |
|
336 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
337 |
static int32 ClearTile_Town(TileIndex tile, byte flags) |
0 | 338 |
{ |
339 |
int house, rating; |
|
340 |
int32 cost; |
|
341 |
Town *t; |
|
342 |
||
343 |
// safety checks |
|
344 |
if (!EnsureNoVehicle(tile)) return CMD_ERROR; |
|
345 |
if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
346 |
||
3377
014725164f97
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents:
3359
diff
changeset
|
347 |
house = GetHouseType(tile); |
0 | 348 |
cost = _price.remove_house * _housetype_remove_cost[house] >> 8; |
349 |
||
350 |
rating = _housetype_remove_ratingmod[house]; |
|
351 |
_cleared_town_rating += rating; |
|
3319
7d04847e4689
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3310
diff
changeset
|
352 |
_cleared_town = t = GetTownByTile(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
353 |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
354 |
if (IsValidPlayer(_current_player)) { |
0 | 355 |
if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
356 |
SetDParam(0, t->index); |
0 | 357 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
358 |
} |
0 | 359 |
} |
360 |
||
361 |
if (flags & DC_EXEC) { |
|
1005 | 362 |
ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM); |
0 | 363 |
ClearTownHouse(t, tile); |
364 |
} |
|
365 |
||
366 |
return cost; |
|
367 |
} |
|
368 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
369 |
static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac) |
0 | 370 |
{ |
3377
014725164f97
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents:
3359
diff
changeset
|
371 |
byte type = GetHouseType(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
372 |
|
473
0da86c59e3ae
(svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents:
470
diff
changeset
|
373 |
ac[CT_PASSENGERS] = _housetype_cargo_passengers[type]; |
2639 | 374 |
ac[CT_MAIL] = _housetype_cargo_mail[type]; |
375 |
ac[CT_GOODS] = _housetype_cargo_goods[type]; |
|
376 |
ac[CT_FOOD] = _housetype_cargo_food[type]; |
|
0 | 377 |
} |
378 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
379 |
static void GetTileDesc_Town(TileIndex tile, TileDesc *td) |
0 | 380 |
{ |
3377
014725164f97
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents:
3359
diff
changeset
|
381 |
td->str = _town_tile_names[GetHouseType(tile)]; |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
382 |
if (GetHouseBuildingStage(tile) != TOWN_HOUSE_COMPLETED) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
383 |
SetDParamX(td->dparam, 0, td->str); |
0 | 384 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
385 |
} |
|
386 |
||
387 |
td->owner = OWNER_TOWN; |
|
388 |
} |
|
389 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
390 |
static uint32 GetTileTrackStatus_Town(TileIndex tile, TransportType mode) |
0 | 391 |
{ |
392 |
/* not used */ |
|
393 |
return 0; |
|
394 |
} |
|
395 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2430
diff
changeset
|
396 |
static void ChangeTileOwner_Town(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 397 |
{ |
398 |
/* not used */ |
|
399 |
} |
|
400 |
||
401 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
402 |
static const TileIndexDiffC _roadblock_tileadd[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
403 |
{ 0, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
404 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
405 |
{ 0, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
406 |
{-1, 0}, |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
407 |
|
0 | 408 |
// Store the first 3 elements again. |
409 |
// Lets us rotate without using &3. |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
410 |
{ 0, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
411 |
{ 1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
412 |
{ 0, 1} |
0 | 413 |
}; |
414 |
||
2817 | 415 |
|
416 |
static bool GrowTown(Town *t); |
|
417 |
||
0 | 418 |
static void TownTickHandler(Town *t) |
419 |
{ |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
420 |
if (HASBIT(t->flags12, TOWN_IS_FUNDED)) { |
0 | 421 |
int i = t->grow_counter - 1; |
422 |
if (i < 0) { |
|
423 |
if (GrowTown(t)) { |
|
424 |
i = t->growth_rate; |
|
425 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
426 |
i = 0; |
0 | 427 |
} |
428 |
} |
|
429 |
t->grow_counter = i; |
|
430 |
} |
|
431 |
||
432 |
UpdateTownRadius(t); |
|
433 |
} |
|
434 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
435 |
void OnTick_Town(void) |
0 | 436 |
{ |
2639 | 437 |
if (_game_mode == GM_EDITOR) return; |
0 | 438 |
|
1451
843188b51df8
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
439 |
/* Make sure each town's tickhandler invocation frequency is about the |
843188b51df8
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
440 |
* same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */ |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
441 |
for (_cur_town_iter += GetMaxTownIndex() + 1; |
1529
be4a2259d2ff
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
442 |
_cur_town_iter >= TOWN_GROWTH_FREQUENCY; |
be4a2259d2ff
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
443 |
_cur_town_iter -= TOWN_GROWTH_FREQUENCY) { |
1517
b77361b13ae4
(svn r2021) Fix: Enlarge _cur_town_ctr from byte to uint32 so that all the towns are considered when growing them even for big maps, where much more than 256 towns are around; reported by Tomasz Dubi?ski <uboottd@hydra.polsl.gliwice.pl>. The savegame still saves just the lowest 8 bits but that doesn't hurt so much.
pasky
parents:
1500
diff
changeset
|
444 |
uint32 i = _cur_town_ctr; |
1451
843188b51df8
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
445 |
|
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
446 |
if (++_cur_town_ctr > GetMaxTownIndex()) |
1448
ab3017415479
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
447 |
_cur_town_ctr = 0; |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
448 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
449 |
if (IsValidTownID(i)) TownTickHandler(GetTown(i)); |
1448
ab3017415479
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
450 |
} |
0 | 451 |
} |
452 |
||
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
453 |
static RoadBits GetTownRoadMask(TileIndex tile) |
0 | 454 |
{ |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
455 |
TrackBits b = GetAnyRoadTrackBits(tile); |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
456 |
RoadBits r = 0; |
2639 | 457 |
|
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
458 |
if (b & TRACK_BIT_X) r |= ROAD_X; |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
459 |
if (b & TRACK_BIT_Y) r |= ROAD_Y; |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
460 |
if (b & TRACK_BIT_UPPER) r |= ROAD_NE | ROAD_NW; |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
461 |
if (b & TRACK_BIT_LOWER) r |= ROAD_SE | ROAD_SW; |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
462 |
if (b & TRACK_BIT_LEFT) r |= ROAD_NW | ROAD_SW; |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
463 |
if (b & TRACK_BIT_RIGHT) r |= ROAD_NE | ROAD_SE; |
0 | 464 |
return r; |
465 |
} |
|
466 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
467 |
static bool IsRoadAllowedHere(TileIndex tile, int dir) |
0 | 468 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
469 |
Slope k; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
470 |
Slope slope; |
0 | 471 |
|
472 |
// If this assertion fails, it might be because the world contains |
|
473 |
// land at the edges. This is not ok. |
|
474 |
TILE_ASSERT(tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
475 |
|
2639 | 476 |
for (;;) { |
0 | 477 |
// Check if there already is a road at this point? |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
478 |
if (GetAnyRoadTrackBits(tile) == 0) { |
0 | 479 |
// No, try to build one in the direction. |
480 |
// if that fails clear the land, and if that fails exit. |
|
481 |
// This is to make sure that we can build a road here later. |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
482 |
if (CmdFailed(DoCommand(tile, (dir & 1 ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) && |
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
483 |
CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) |
0 | 484 |
return false; |
485 |
} |
|
486 |
||
487 |
slope = GetTileSlope(tile, NULL); |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
488 |
if (slope == SLOPE_FLAT) { |
465
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
489 |
no_slope: |
0 | 490 |
// Tile has no slope |
491 |
// Disallow the road if any neighboring tile has a road. |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
492 |
if (HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+1]))), dir^2) || |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
493 |
HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+3]))), dir^2) || |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
494 |
HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+1]) + ToTileIndexDiff(_roadblock_tileadd[dir+2]))), dir) || |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
495 |
HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+3]) + ToTileIndexDiff(_roadblock_tileadd[dir+2]))), dir)) |
0 | 496 |
return false; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
497 |
|
0 | 498 |
// Otherwise allow |
499 |
return true; |
|
500 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
501 |
|
0 | 502 |
// If the tile is not a slope in the right direction, then |
503 |
// maybe terraform some. |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
504 |
k = (dir & 1) ? SLOPE_NE : SLOPE_NW; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
505 |
if (k != slope && ComplementSlope(k) != slope) { |
0 | 506 |
uint32 r = Random(); |
507 |
||
2639 | 508 |
if (CHANCE16I(1, 8, r) && !_generating_world) { |
465
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
509 |
int32 res; |
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
510 |
|
2639 | 511 |
if (CHANCE16I(1, 16, r)) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
512 |
res = DoCommand(tile, slope, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, |
465
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
513 |
CMD_TERRAFORM_LAND); |
2639 | 514 |
} else { |
3639
162f06a0242a
(svn r4547) Revert a part of r4541 to silence an assertion for now
tron
parents:
3636
diff
changeset
|
515 |
res = DoCommand(tile, slope ^ 0xF, 1, DC_EXEC | DC_AUTO | DC_NO_WATER, |
465
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
516 |
CMD_TERRAFORM_LAND); |
2639 | 517 |
} |
2646
a91fd482fce5
(svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents:
2639
diff
changeset
|
518 |
if (CmdFailed(res) && CHANCE16I(1, 3, r)) { |
465
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
519 |
// We can consider building on the slope, though. |
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
520 |
goto no_slope; |
2646
a91fd482fce5
(svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents:
2639
diff
changeset
|
521 |
} |
0 | 522 |
} |
523 |
return false; |
|
524 |
} |
|
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
525 |
return true; |
0 | 526 |
} |
527 |
} |
|
528 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
529 |
static bool TerraformTownTile(TileIndex tile, int edges, int dir) |
0 | 530 |
{ |
531 |
int32 r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
532 |
|
0 | 533 |
TILE_ASSERT(tile); |
534 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
535 |
r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
2646
a91fd482fce5
(svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents:
2639
diff
changeset
|
536 |
if (CmdFailed(r) || r >= 126 * 16) return false; |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
537 |
DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND); |
0 | 538 |
return true; |
539 |
} |
|
540 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
541 |
static void LevelTownLand(TileIndex tile) |
0 | 542 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
543 |
Slope tileh; |
0 | 544 |
|
545 |
TILE_ASSERT(tile); |
|
546 |
||
547 |
// Don't terraform if land is plain or if there's a house there. |
|
3055
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
548 |
if (IsTileType(tile, MP_HOUSE)) return; |
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
549 |
tileh = GetTileSlope(tile, NULL); |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
550 |
if (tileh == SLOPE_FLAT) return; |
0 | 551 |
|
552 |
// First try up, then down |
|
3055
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
553 |
if (!TerraformTownTile(tile, ~tileh & 0xF, 1)) { |
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
554 |
TerraformTownTile(tile, tileh & 0xF, 0); |
0 | 555 |
} |
556 |
} |
|
557 |
||
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
558 |
static void GrowTownInTile(TileIndex* tile_ptr, RoadBits mask, int block, Town* t1) |
0 | 559 |
{ |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
560 |
RoadBits rcmd; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
561 |
TileIndex tmptile; |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
562 |
DiagDirection i; |
0 | 563 |
int j; |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
564 |
TileIndex tile = *tile_ptr; |
0 | 565 |
|
566 |
TILE_ASSERT(tile); |
|
567 |
||
568 |
if (mask == 0) { |
|
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
569 |
int a; |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
570 |
int b; |
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
571 |
|
0 | 572 |
// Tile has no road. First reset the status counter |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
573 |
// to say that this is the last iteration. |
0 | 574 |
_grow_town_result = 0; |
575 |
||
576 |
// Remove hills etc |
|
577 |
LevelTownLand(tile); |
|
578 |
||
579 |
// Is a road allowed here? |
|
2639 | 580 |
if (!IsRoadAllowedHere(tile, block)) return; |
0 | 581 |
|
582 |
// Randomize new road block numbers |
|
583 |
a = block; |
|
584 |
b = block ^ 2; |
|
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
585 |
if (CHANCE16(1, 4)) { |
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
586 |
do { |
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
587 |
a = GB(Random(), 0, 2); |
2952 | 588 |
} while (a == b); |
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
589 |
} |
0 | 590 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
591 |
if (!IsRoadAllowedHere(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a])), a)) { |
0 | 592 |
// A road is not allowed to continue the randomized road, |
593 |
// return if the road we're trying to build is curved. |
|
2639 | 594 |
if (a != (b ^ 2)) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
595 |
|
0 | 596 |
// Return if neither side of the new road is a house |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
597 |
if (!IsTileType(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a + 1])), MP_HOUSE) && |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
598 |
!IsTileType(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a + 3])), MP_HOUSE)) |
0 | 599 |
return; |
600 |
||
601 |
// That means that the road is only allowed if there is a house |
|
602 |
// at any side of the new road. |
|
603 |
} |
|
604 |
rcmd = (1 << a) + (1 << b); |
|
605 |
||
606 |
} else if (block < 5 && !HASBIT(mask,block^2)) { |
|
607 |
// Continue building on a partial road. |
|
608 |
// Always OK. |
|
609 |
_grow_town_result = 0; |
|
2639 | 610 |
rcmd = 1 << (block ^ 2); |
0 | 611 |
} else { |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
612 |
int i; |
0 | 613 |
|
614 |
// Reached a tunnel? Then continue at the other side of it. |
|
3184
7405329343ce
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3154
diff
changeset
|
615 |
if (IsTunnelTile(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) { |
3154 | 616 |
*tile_ptr = GetOtherTunnelEnd(tile); |
0 | 617 |
return; |
618 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
619 |
|
0 | 620 |
// For any other kind of tunnel/bridge, bail out. |
2639 | 621 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) return; |
0 | 622 |
|
623 |
// Possibly extend the road in a direction. |
|
624 |
// Randomize a direction and if it has a road, bail out. |
|
2635 | 625 |
i = GB(Random(), 0, 2); |
2639 | 626 |
if (HASBIT(mask, i)) return; |
0 | 627 |
|
628 |
// This is the tile we will reach if we extend to this direction. |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
629 |
tmptile = TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[i])); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
630 |
|
0 | 631 |
// Don't do it if it reaches to water. |
3433
ca2b963c1671
(svn r4262) -Codechange: use IsClearWaterTile instead of some "home-brewn" marco. town_cmd is now map access free
celestar
parents:
3432
diff
changeset
|
632 |
if (IsClearWaterTile(tmptile)) return; |
0 | 633 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
634 |
// Build a house at the edge. 60% chance or |
0 | 635 |
// always ok if no road allowed. |
2639 | 636 |
if (!IsRoadAllowedHere(tmptile, i) || CHANCE16(6, 10)) { |
0 | 637 |
// But not if there already is a house there. |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
638 |
if (!IsTileType(tmptile, MP_HOUSE)) { |
0 | 639 |
// Level the land if possible |
640 |
LevelTownLand(tmptile); |
|
641 |
||
642 |
// And build a house. |
|
643 |
// Set result to -1 if we managed to build it. |
|
2639 | 644 |
if (BuildTownHouse(t1, tmptile)) _grow_town_result = -1; |
0 | 645 |
} |
646 |
return; |
|
647 |
} |
|
648 |
||
649 |
_grow_town_result = 0; |
|
650 |
rcmd = 1 << i; |
|
651 |
} |
|
652 |
||
653 |
// Return if a water tile |
|
3433
ca2b963c1671
(svn r4262) -Codechange: use IsClearWaterTile instead of some "home-brewn" marco. town_cmd is now map access free
celestar
parents:
3432
diff
changeset
|
654 |
if (IsClearWaterTile(tile)) return; |
0 | 655 |
|
656 |
// Determine direction of slope, |
|
657 |
// and build a road if not a special slope. |
|
3055
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
658 |
switch (GetTileSlope(tile, NULL)) { |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
659 |
case SLOPE_SW: i = DIAGDIR_NE; break; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
660 |
case SLOPE_SE: i = DIAGDIR_NW; break; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
661 |
case SLOPE_NW: i = DIAGDIR_SE; break; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
662 |
case SLOPE_NE: i = DIAGDIR_SW; break; |
3055
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
663 |
|
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
664 |
default: |
0 | 665 |
build_road_and_exit: |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
666 |
if (!CmdFailed(DoCommand(tile, rcmd, t1->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) { |
3055
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
667 |
_grow_town_result = -1; |
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
668 |
} |
25fd76668365
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
669 |
return; |
0 | 670 |
} |
671 |
||
672 |
tmptile = tile; |
|
673 |
||
674 |
// Now it contains the direction of the slope |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
675 |
j = -11; // max 11 tile long bridges |
0 | 676 |
do { |
677 |
if (++j == 0) |
|
678 |
goto build_road_and_exit; |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4549
diff
changeset
|
679 |
tmptile = TILE_MASK(tmptile + TileOffsByDiagDir(i)); |
3433
ca2b963c1671
(svn r4262) -Codechange: use IsClearWaterTile instead of some "home-brewn" marco. town_cmd is now map access free
celestar
parents:
3432
diff
changeset
|
680 |
} while (IsClearWaterTile(tmptile)); |
0 | 681 |
|
682 |
// no water tiles in between? |
|
683 |
if (j == -10) |
|
684 |
goto build_road_and_exit; |
|
685 |
||
686 |
// Quit if it selecting an appropiate bridge type fails a large number of times. |
|
687 |
j = 22; |
|
688 |
{ |
|
689 |
int32 bridge_len = GetBridgeLength(tile, tmptile); |
|
690 |
do { |
|
691 |
byte bridge_type = RandomRange(MAX_BRIDGES - 1); |
|
692 |
if (CheckBridge_Stuff(bridge_type, bridge_len)) { |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
693 |
if (!CmdFailed(DoCommand(tile, tmptile, 0x8000 + bridge_type, DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE))) |
0 | 694 |
_grow_town_result = -1; |
695 |
||
696 |
// obviously, if building any bridge would fail, there is no need to try other bridge-types |
|
697 |
return; |
|
698 |
} |
|
2952 | 699 |
} while (--j != 0); |
0 | 700 |
} |
701 |
} |
|
702 |
||
703 |
// Returns true if a house was built, or no if the build failed. |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
704 |
static int GrowTownAtRoad(Town *t, TileIndex tile) |
0 | 705 |
{ |
706 |
int block = 5; // special case |
|
707 |
||
708 |
TILE_ASSERT(tile); |
|
709 |
||
710 |
// Number of times to search. |
|
470
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
711 |
_grow_town_result = 10 + t->num_houses * 4 / 9; |
0 | 712 |
|
713 |
do { |
|
714 |
// Get a bitmask of the road blocks on a tile |
|
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
715 |
RoadBits mask = GetTownRoadMask(tile); |
0 | 716 |
|
717 |
// Try to grow the town from this point |
|
718 |
GrowTownInTile(&tile,mask,block,t); |
|
719 |
||
720 |
// Exclude the source position from the bitmask |
|
721 |
// and return if no more road blocks available |
|
722 |
CLRBIT(mask, (block ^ 2)); |
|
723 |
if (mask == 0) |
|
724 |
return _grow_town_result; |
|
725 |
||
726 |
// Select a random bit from the blockmask, walk a step |
|
727 |
// and continue the search from there. |
|
728 |
do block = Random() & 3; while (!HASBIT(mask,block)); |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
729 |
tile += ToTileIndexDiff(_roadblock_tileadd[block]); |
0 | 730 |
|
1327
f98ba72197f5
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
731 |
if (IsTileType(tile, MP_STREET)) { |
f98ba72197f5
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
732 |
/* Don't allow building over roads of other cities */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4053
diff
changeset
|
733 |
if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t) { |
1327
f98ba72197f5
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
734 |
_grow_town_result = -1; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4053
diff
changeset
|
735 |
} else if (_game_mode == GM_EDITOR) { |
1327
f98ba72197f5
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
736 |
/* If we are in the SE, and this road-piece has no town owner yet, it just found an |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
737 |
* owner :) (happy happy happy road now) */ |
1902 | 738 |
SetTileOwner(tile, OWNER_TOWN); |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
739 |
SetTownIndex(tile, t->index); |
1327
f98ba72197f5
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
740 |
} |
f98ba72197f5
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
741 |
} |
1280
b6925875de49
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
742 |
|
0 | 743 |
// Max number of times is checked. |
744 |
} while (--_grow_town_result >= 0); |
|
745 |
||
746 |
return (_grow_town_result == -2); |
|
747 |
} |
|
748 |
||
749 |
// Generate a random road block |
|
750 |
// The probability of a straight road |
|
751 |
// is somewhat higher than a curved. |
|
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
752 |
static RoadBits GenRandomRoadBits(void) |
0 | 753 |
{ |
754 |
uint32 r = Random(); |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2070
diff
changeset
|
755 |
uint a = GB(r, 0, 2); |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2070
diff
changeset
|
756 |
uint b = GB(r, 8, 2); |
0 | 757 |
if (a == b) b ^= 2; |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2070
diff
changeset
|
758 |
return (1 << a) + (1 << b); |
0 | 759 |
} |
760 |
||
761 |
// Grow the town |
|
762 |
// Returns true if a house was built, or no if the build failed. |
|
2817 | 763 |
static bool GrowTown(Town *t) |
0 | 764 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
765 |
TileIndex tile; |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
766 |
const TileIndexDiffC *ptr; |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
767 |
PlayerID old_player; |
0 | 768 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
769 |
static const TileIndexDiffC _town_coord_mod[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
770 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
771 |
{ 1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
772 |
{ 1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
773 |
{-1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
774 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
775 |
{ 0, 2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
776 |
{ 2, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
777 |
{ 0, -2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
778 |
{-1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
779 |
{-2, 2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
780 |
{ 2, 2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
781 |
{ 2, -2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
782 |
{ 0, 0} |
0 | 783 |
}; |
784 |
||
785 |
// Current player is a town |
|
260
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
786 |
old_player = _current_player; |
0 | 787 |
_current_player = OWNER_TOWN; |
788 |
||
789 |
// Find a road that we can base the construction on. |
|
790 |
tile = t->xy; |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
791 |
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
3150
025fe8cd7104
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
792 |
if (GetAnyRoadTrackBits(tile) != 0) { |
260
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
793 |
int r = GrowTownAtRoad(t, tile); |
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
794 |
_current_player = old_player; |
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
795 |
return r; |
0 | 796 |
} |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
797 |
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
798 |
} |
0 | 799 |
|
800 |
// No road available, try to build a random road block by |
|
801 |
// clearing some land and then building a road there. |
|
802 |
tile = t->xy; |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
803 |
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
4317
c2c46cd2de15
(svn r5970) -Fix [FS#49]: town-growth removed houses under construction to make way for road. Not wanted behavoir (Rubidium)
truelight
parents:
4300
diff
changeset
|
804 |
/* Only work with plain land that not already has a house */ |
c2c46cd2de15
(svn r5970) -Fix [FS#49]: town-growth removed houses under construction to make way for road. Not wanted behavoir (Rubidium)
truelight
parents:
4300
diff
changeset
|
805 |
if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) { |
5495
ccc57a497257
(svn r9851) [0.5] -Backport from trunk (r9731, r9741, r9743, r9753, r9757):
rubidium
parents:
5372
diff
changeset
|
806 |
if (!CmdFailed(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
807 |
DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); |
260
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
808 |
_current_player = old_player; |
0 | 809 |
return true; |
810 |
} |
|
811 |
} |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
812 |
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
813 |
} |
0 | 814 |
|
260
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
815 |
_current_player = old_player; |
0 | 816 |
return false; |
817 |
} |
|
818 |
||
819 |
static void UpdateTownRadius(Town *t) |
|
820 |
{ |
|
821 |
static const uint16 _town_radius_data[23][5] = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
822 |
{ 4, 0, 0, 0, 0}, // 0 |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
823 |
{ 16, 0, 0, 0, 0}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
824 |
{ 25, 0, 0, 0, 0}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
825 |
{ 36, 0, 0, 0, 0}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
826 |
{ 49, 0, 4, 0, 0}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
827 |
{ 64, 0, 4, 0, 0}, // 20 |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
828 |
{ 64, 0, 9, 0, 1}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
829 |
{ 64, 0, 9, 0, 4}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
830 |
{ 64, 0, 16, 0, 4}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
831 |
{ 81, 0, 16, 0, 4}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
832 |
{ 81, 0, 16, 0, 4}, // 40 |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
833 |
{ 81, 0, 25, 0, 9}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
834 |
{ 81, 36, 25, 0, 9}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
835 |
{ 81, 36, 25, 16, 9}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
836 |
{ 81, 49, 0, 25, 9}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
837 |
{ 81, 64, 0, 25, 9}, // 60 |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
838 |
{ 81, 64, 0, 36, 9}, |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
839 |
{ 81, 64, 0, 36, 16}, |
470
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
840 |
{100, 81, 0, 49, 16}, |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
841 |
{100, 81, 0, 49, 25}, |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
842 |
{121, 81, 0, 49, 25}, // 80 |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
843 |
{121, 81, 0, 49, 25}, |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
844 |
{121, 81, 0, 49, 36}, // 88 |
0 | 845 |
}; |
470
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
846 |
|
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
847 |
if (t->num_houses < 92) { |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
848 |
memcpy(t->radius, _town_radius_data[t->num_houses / 4], sizeof(t->radius)); |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
849 |
} else { |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
850 |
int mass = t->num_houses / 8; |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
851 |
// At least very roughly extrapolate. Empirical numbers dancing between |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
852 |
// overwhelming by cottages and skyscrapers outskirts. |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
853 |
t->radius[0] = mass * mass; |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
854 |
// Actually we are proportional to sqrt() but that's right because |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
855 |
// we are covering an area. |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
856 |
t->radius[1] = mass * 7; |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
857 |
t->radius[2] = 0; |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
858 |
t->radius[3] = mass * 4; |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
859 |
t->radius[4] = mass * 3; |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
860 |
//debug("%d (->%d): %d %d %d %d\n", t->num_houses, mass, t->radius[0], t->radius[1], t->radius[3], t->radius[4]); |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
861 |
} |
0 | 862 |
} |
863 |
||
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
864 |
static bool CreateTownName(uint32 *townnameparts) |
0 | 865 |
{ |
866 |
Town *t2; |
|
867 |
char buf1[64]; |
|
868 |
char buf2[64]; |
|
869 |
uint32 r; |
|
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
870 |
/* Do not set too low tries, since when we run out of names, we loop |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
871 |
* for #tries only one time anyway - then we stop generating more |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
872 |
* towns. Do not show it too high neither, since looping through all |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
873 |
* the other towns may take considerable amount of time (10000 is |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
874 |
* too much). */ |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
875 |
int tries = 1000; |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
876 |
uint16 townnametype = SPECSTR_TOWNNAME_START + _opt.town_name; |
0 | 877 |
|
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
878 |
assert(townnameparts); |
0 | 879 |
|
2952 | 880 |
for (;;) { |
0 | 881 |
restart: |
882 |
r = Random(); |
|
883 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
884 |
SetDParam(0, r); |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4850
diff
changeset
|
885 |
GetString(buf1, townnametype, lastof(buf1)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
886 |
|
0 | 887 |
// Check size and width |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4559
diff
changeset
|
888 |
if (strlen(buf1) >= 31 || GetStringBoundingBox(buf1).width > 130) continue; |
0 | 889 |
|
890 |
FOR_ALL_TOWNS(t2) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
891 |
// We can't just compare the numbers since |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
892 |
// several numbers may map to a single name. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
893 |
SetDParam(0, t2->index); |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4850
diff
changeset
|
894 |
GetString(buf2, STR_TOWN, lastof(buf2)); |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
895 |
if (strcmp(buf1, buf2) == 0) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
896 |
if (tries-- < 0) return false; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
897 |
goto restart; |
0 | 898 |
} |
899 |
} |
|
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
900 |
*townnameparts = r; |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
901 |
return true; |
0 | 902 |
} |
903 |
} |
|
904 |
||
1377
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
905 |
void UpdateTownMaxPass(Town *t) |
0 | 906 |
{ |
907 |
t->max_pass = t->population >> 3; |
|
908 |
t->max_mail = t->population >> 4; |
|
909 |
} |
|
910 |
||
3674
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
911 |
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, uint size_mode) |
0 | 912 |
{ |
913 |
int x, i; |
|
914 |
||
915 |
// clear the town struct |
|
916 |
i = t->index; |
|
917 |
memset(t, 0, sizeof(Town)); |
|
918 |
t->index = i; |
|
5319
65acb2e92975
(svn r7477) -Fix (7451): Allocate(Industry|Town) get called twice when trying to build an industry/town via a command, thus incrementing the number of towns/industries twice when created via a command.
rubidium
parents:
5298
diff
changeset
|
919 |
_total_towns++; |
0 | 920 |
|
921 |
t->xy = tile; |
|
922 |
t->num_houses = 0; |
|
923 |
t->time_until_rebuild = 10; |
|
924 |
UpdateTownRadius(t); |
|
925 |
t->flags12 = 0; |
|
926 |
t->population = 0; |
|
927 |
t->grow_counter = 0; |
|
928 |
t->growth_rate = 250; |
|
929 |
t->new_max_pass = 0; |
|
930 |
t->new_max_mail = 0; |
|
931 |
t->new_act_pass = 0; |
|
932 |
t->new_act_mail = 0; |
|
933 |
t->max_pass = 0; |
|
934 |
t->max_mail = 0; |
|
935 |
t->act_pass = 0; |
|
936 |
t->act_mail = 0; |
|
937 |
||
938 |
t->pct_pass_transported = 0; |
|
939 |
t->pct_mail_transported = 0; |
|
940 |
t->fund_buildings_months = 0; |
|
941 |
t->new_act_food = 0; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
942 |
t->new_act_water = 0; |
0 | 943 |
t->act_food = 0; |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
944 |
t->act_water = 0; |
0 | 945 |
|
2952 | 946 |
for (i = 0; i != MAX_PLAYERS; i++) |
0 | 947 |
t->ratings[i] = 500; |
948 |
||
949 |
t->have_ratings = 0; |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
950 |
t->exclusivity = (byte)-1; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
951 |
t->exclusive_counter = 0; |
0 | 952 |
t->statues = 0; |
953 |
||
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
954 |
t->townnametype = SPECSTR_TOWNNAME_START + _opt.town_name; |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
955 |
t->townnameparts = townnameparts; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
956 |
|
0 | 957 |
UpdateTownVirtCoord(t); |
958 |
_town_sort_dirty = true; |
|
959 |
||
3674
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
960 |
if (size_mode == 0) { |
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
961 |
x = (Random() & 0xF) + 8; |
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
962 |
} else { |
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
963 |
x = (size_mode - 1) * 16 + 3; |
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
964 |
} |
0 | 965 |
|
966 |
t->num_houses += x; |
|
967 |
UpdateTownRadius(t); |
|
968 |
||
969 |
i = x * 4; |
|
970 |
do { |
|
971 |
GrowTown(t); |
|
972 |
} while (--i); |
|
973 |
||
974 |
t->num_houses -= x; |
|
975 |
UpdateTownRadius(t); |
|
976 |
UpdateTownMaxPass(t); |
|
977 |
} |
|
978 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
979 |
static Town *AllocateTown(void) |
0 | 980 |
{ |
981 |
Town *t; |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
982 |
|
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
983 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
984 |
* TODO - This is just a temporary stage, this will be removed. */ |
4983 | 985 |
for (t = GetTown(0); t != NULL; t = (t->index + 1U < GetTownPoolSize()) ? GetTown(t->index + 1U) : NULL) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
986 |
if (!IsValidTown(t)) { |
4330
7306bda145ab
(svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents:
4317
diff
changeset
|
987 |
TownID index = t->index; |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
988 |
|
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
989 |
memset(t, 0, sizeof(Town)); |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
990 |
t->index = index; |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
991 |
|
0 | 992 |
return t; |
993 |
} |
|
994 |
} |
|
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
995 |
|
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
996 |
/* Check if we can add a block to the pool */ |
4983 | 997 |
if (AddBlockToPool(&_Town_pool)) |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
998 |
return AllocateTown(); |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
999 |
|
0 | 1000 |
return NULL; |
1001 |
} |
|
1002 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1003 |
/** Create a new town. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1004 |
* This obviously only works in the scenario editor. Function not removed |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1005 |
* as it might be possible in the future to fund your own town :) |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1006 |
* @param tile coordinates where town is built |
5064
9042f861d711
(svn r7120) -Fix (r6631): A town size of 0 in the scenario editor is a random size. So to get a size
Darkvater
parents:
4983
diff
changeset
|
1007 |
* @param p1 size of the town (0 = random, 1 = small, 2 = medium, 3 = large) |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1008 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1009 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1010 |
int32 CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1011 |
{ |
1012 |
Town *t; |
|
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1013 |
uint32 townnameparts; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1014 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1015 |
/* Only in the scenario editor */ |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1016 |
if (_game_mode != GM_EDITOR) return CMD_ERROR; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1017 |
|
0 | 1018 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
1019 |
||
1020 |
// Check if too close to the edge of map |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
1021 |
if (DistanceFromEdge(tile) < 12) |
0 | 1022 |
return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP); |
1023 |
||
5085
91cb54f510ce
(svn r7152) -Feature (FS#396): allow towns to be built on top of trees in the scenario editor.
rubidium
parents:
5065
diff
changeset
|
1024 |
// Can only build on clear flat areas, possibly with trees. |
91cb54f510ce
(svn r7152) -Feature (FS#396): allow towns to be built on top of trees in the scenario editor.
rubidium
parents:
5065
diff
changeset
|
1025 |
if ((!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES)) || GetTileSlope(tile, NULL) != SLOPE_FLAT) { |
0 | 1026 |
return_cmd_error(STR_0239_SITE_UNSUITABLE); |
2986
f901acd775a9
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1027 |
} |
0 | 1028 |
|
1029 |
// Check distance to all other towns. |
|
1030 |
if (IsCloseToTown(tile, 20)) |
|
1031 |
return_cmd_error(STR_0238_TOO_CLOSE_TO_ANOTHER_TOWN); |
|
1032 |
||
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1033 |
// Get a unique name for the town. |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1034 |
if (!CreateTownName(&townnameparts)) |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1035 |
return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1036 |
|
0 | 1037 |
// Allocate town struct |
1038 |
t = AllocateTown(); |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1039 |
if (t == NULL) return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
0 | 1040 |
|
1041 |
// Create the town |
|
1042 |
if (flags & DC_EXEC) { |
|
1043 |
_generating_world = true; |
|
3674
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
1044 |
DoCreateTown(t, tile, townnameparts, p1); |
0 | 1045 |
_generating_world = false; |
1046 |
} |
|
1047 |
return 0; |
|
1048 |
} |
|
1049 |
||
3674
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
1050 |
Town *CreateRandomTown(uint attempts, uint size_mode) |
0 | 1051 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1052 |
TileIndex tile; |
0 | 1053 |
Town *t; |
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1054 |
uint32 townnameparts; |
0 | 1055 |
|
1056 |
do { |
|
1057 |
// Generate a tile index not too close from the edge |
|
2051 | 1058 |
tile = RandomTile(); |
2951 | 1059 |
if (DistanceFromEdge(tile) < 20) continue; |
0 | 1060 |
|
1061 |
// Make sure the tile is plain |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1062 |
if (!IsTileType(tile, MP_CLEAR) || GetTileSlope(tile, NULL) != SLOPE_FLAT) continue; |
0 | 1063 |
|
1064 |
// Check not too close to a town |
|
2951 | 1065 |
if (IsCloseToTown(tile, 20)) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1066 |
|
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1067 |
// Get a unique name for the town. |
2951 | 1068 |
if (!CreateTownName(&townnameparts)) break; |
1421
5a9eb1b81efb
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1069 |
|
0 | 1070 |
// Allocate a town struct |
1071 |
t = AllocateTown(); |
|
2951 | 1072 |
if (t == NULL) break; |
0 | 1073 |
|
3674
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
1074 |
DoCreateTown(t, tile, townnameparts, size_mode); |
0 | 1075 |
return t; |
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1076 |
} while (--attempts); |
0 | 1077 |
return NULL; |
1078 |
} |
|
1079 |
||
2430
e1da54e6bf91
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1080 |
static const byte _num_initial_towns[3] = {11, 23, 46}; |
0 | 1081 |
|
2430
e1da54e6bf91
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1082 |
bool GenerateTowns(void) |
0 | 1083 |
{ |
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1084 |
uint num = 0; |
2430
e1da54e6bf91
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1085 |
uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7)); |
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1086 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1087 |
SetGeneratingWorldProgress(GWP_TOWN, n); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1088 |
|
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1089 |
do { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1090 |
IncreaseGeneratingWorldProgress(GWP_TOWN); |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1091 |
// try 20 times to create a random-sized town for the first loop. |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1092 |
if (CreateRandomTown(20, 0) != NULL) num++; |
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1093 |
} while (--n); |
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1094 |
|
2430
e1da54e6bf91
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1095 |
// give it a last try, but now more aggressive |
3674
e55478cff17e
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
1096 |
if (num == 0 && CreateRandomTown(10000, 0) == NULL) { |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
1097 |
if (GetNumTowns() == 0) { |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1098 |
/* XXX - can we handle that more gracefully? */ |
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1099 |
if (_game_mode != GM_EDITOR) error("Could not generate any town"); |
2430
e1da54e6bf91
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1100 |
|
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1101 |
return false; |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1102 |
} |
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1103 |
} |
2430
e1da54e6bf91
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1104 |
|
e1da54e6bf91
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1105 |
return true; |
0 | 1106 |
} |
1107 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1108 |
static bool CheckBuildHouseMode(TileIndex tile, Slope tileh, int mode) |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1109 |
{ |
0 | 1110 |
int b; |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1111 |
Slope slope; |
0 | 1112 |
|
1113 |
static const byte _masks[8] = { |
|
1114 |
0xC,0x3,0x9,0x6, |
|
1115 |
0x3,0xC,0x6,0x9, |
|
1116 |
}; |
|
1117 |
||
1118 |
slope = GetTileSlope(tile, NULL); |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1119 |
if (IsSteepSlope(slope)) return false; |
0 | 1120 |
|
1121 |
b = 0; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1122 |
if ((slope != SLOPE_FLAT && ~slope & _masks[mode])) b = ~b; |
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1123 |
if ((tileh != SLOPE_FLAT && ~tileh & _masks[mode+4])) b = ~b; |
0 | 1124 |
if (b) |
1125 |
return false; |
|
1126 |
||
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1127 |
return !CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR)); |
0 | 1128 |
} |
1129 |
||
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1130 |
|
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1131 |
uint GetTownRadiusGroup(const Town* t, TileIndex tile) |
0 | 1132 |
{ |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1133 |
uint dist = DistanceSquare(tile, t->xy); |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1134 |
uint smallest; |
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1135 |
uint i; |
0 | 1136 |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1137 |
if (t->fund_buildings_months && dist <= 25) return 4; |
0 | 1138 |
|
1139 |
smallest = 0; |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2430
diff
changeset
|
1140 |
for (i = 0; i != lengthof(t->radius); i++) { |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1141 |
if (dist < t->radius[i]) smallest = i; |
0 | 1142 |
} |
1143 |
||
1144 |
return smallest; |
|
1145 |
} |
|
1146 |
||
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1147 |
static bool CheckFree2x2Area(TileIndex tile) |
0 | 1148 |
{ |
1149 |
int i; |
|
1150 |
||
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1151 |
static const TileIndexDiffC _tile_add[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1152 |
{0 , 0 }, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1153 |
{0 - 0, 1 - 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1154 |
{1 - 0, 0 - 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1155 |
{1 - 1, 1 - 0} |
0 | 1156 |
}; |
1157 |
||
2952 | 1158 |
for (i = 0; i != 4; i++) { |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1159 |
tile += ToTileIndexDiff(_tile_add[i]); |
0 | 1160 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1161 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return false; |
0 | 1162 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1163 |
if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_FORCETEST, CMD_LANDSCAPE_CLEAR))) |
0 | 1164 |
return false; |
1165 |
} |
|
1166 |
||
1167 |
return true; |
|
1168 |
} |
|
1169 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1170 |
static void DoBuildTownHouse(Town *t, TileIndex tile) |
0 | 1171 |
{ |
1172 |
int i; |
|
1173 |
uint bitmask; |
|
1174 |
int house; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1175 |
Slope slope; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
1176 |
uint z; |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1177 |
uint oneof = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1178 |
|
0 | 1179 |
// Above snow? |
1180 |
slope = GetTileSlope(tile, &z); |
|
1181 |
||
1182 |
// Get the town zone type |
|
1183 |
{ |
|
1184 |
uint rad = GetTownRadiusGroup(t, tile); |
|
1185 |
||
1186 |
int land = _opt.landscape; |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1187 |
if (land == LT_HILLY && z >= _opt.snow_line) land = -1; |
0 | 1188 |
|
1189 |
bitmask = (1 << rad) + (1 << (land + 12)); |
|
1190 |
} |
|
1191 |
||
1192 |
// bits 0-4 are used |
|
1193 |
// bits 11-15 are used |
|
1194 |
// bits 5-10 are not used. |
|
1195 |
{ |
|
1196 |
byte houses[lengthof(_housetype_flags)]; |
|
1197 |
int num = 0; |
|
1198 |
||
1199 |
// Generate a list of all possible houses that can be built. |
|
2952 | 1200 |
for (i=0; i!=lengthof(_housetype_flags); i++) { |
0 | 1201 |
if ((~_housetype_flags[i] & bitmask) == 0) |
1202 |
houses[num++] = (byte)i; |
|
1203 |
} |
|
1204 |
||
2952 | 1205 |
for (;;) { |
0 | 1206 |
house = houses[RandomRange(num)]; |
1207 |
||
1208 |
if (_cur_year < _housetype_years[house].min || _cur_year > _housetype_years[house].max) |
|
1209 |
continue; |
|
1210 |
||
1211 |
// Special houses that there can be only one of. |
|
483
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1212 |
switch (house) { |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1213 |
case HOUSE_TEMP_CHURCH: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1214 |
case HOUSE_ARCT_CHURCH: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1215 |
case HOUSE_SNOW_CHURCH: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1216 |
case HOUSE_TROP_CHURCH: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1217 |
case HOUSE_TOY_CHURCH: |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1218 |
SETBIT(oneof, TOWN_HAS_CHURCH); |
483
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1219 |
break; |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1220 |
case HOUSE_STADIUM: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1221 |
case HOUSE_MODERN_STADIUM: |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1222 |
SETBIT(oneof, TOWN_HAS_STADIUM); |
483
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1223 |
break; |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1224 |
default: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1225 |
oneof = 0; |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1226 |
break; |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1227 |
} |
0 | 1228 |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1229 |
if (HASBITS(t->flags12 , oneof)) continue; |
0 | 1230 |
|
1231 |
// Make sure there is no slope? |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1232 |
if (_housetype_extra_flags[house] & 0x12 && slope != SLOPE_FLAT) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1233 |
|
2951 | 1234 |
if (_housetype_extra_flags[house] & 0x10) { |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1235 |
if (CheckFree2x2Area(tile) || |
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1236 |
CheckFree2x2Area(tile += TileDiffXY(-1, 0)) || |
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1237 |
CheckFree2x2Area(tile += TileDiffXY( 0, -1)) || |
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1238 |
CheckFree2x2Area(tile += TileDiffXY( 1, 0))) { |
1981 | 1239 |
break; |
2951 | 1240 |
} |
1241 |
tile += TileDiffXY(0, 1); |
|
1242 |
} else if (_housetype_extra_flags[house] & 4) { |
|
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1243 |
if (CheckBuildHouseMode(tile + TileDiffXY(1, 0), slope, 0)) break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1244 |
|
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1245 |
if (CheckBuildHouseMode(tile + TileDiffXY(-1, 0), slope, 1)) { |
1981 | 1246 |
tile += TileDiffXY(-1, 0); |
0 | 1247 |
break; |
1248 |
} |
|
2951 | 1249 |
} else if (_housetype_extra_flags[house] & 8) { |
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1250 |
if (CheckBuildHouseMode(tile + TileDiffXY(0, 1), slope, 2)) break; |
0 | 1251 |
|
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1252 |
if (CheckBuildHouseMode(tile + TileDiffXY(0, -1), slope, 3)) { |
1981 | 1253 |
tile += TileDiffXY(0, -1); |
0 | 1254 |
break; |
1255 |
} |
|
2951 | 1256 |
} else { |
0 | 1257 |
break; |
2951 | 1258 |
} |
0 | 1259 |
} |
1260 |
} |
|
1261 |
||
1262 |
t->num_houses++; |
|
1263 |
||
1264 |
// Special houses that there can be only one of. |
|
1265 |
t->flags12 |= oneof; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1266 |
|
0 | 1267 |
{ |
3382
c9c8d85aa632
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1268 |
byte construction_counter = 0, construction_stage = 0, size_flags; |
0 | 1269 |
|
1270 |
if (_generating_world) { |
|
1271 |
uint32 r = Random(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1272 |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1273 |
construction_stage = TOWN_HOUSE_COMPLETED; |
3382
c9c8d85aa632
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1274 |
if (CHANCE16(1, 7)) construction_stage = GB(r, 0, 2); |
0 | 1275 |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1276 |
if (construction_stage == TOWN_HOUSE_COMPLETED) { |
3382
c9c8d85aa632
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1277 |
ChangePopulation(t, _housetype_population[house]); |
c9c8d85aa632
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1278 |
} else { |
c9c8d85aa632
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1279 |
construction_counter = GB(r, 2, 2); |
c9c8d85aa632
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1280 |
} |
0 | 1281 |
} |
3382
c9c8d85aa632
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1282 |
size_flags = GB(_housetype_extra_flags[house], 2, 3); |
c9c8d85aa632
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1283 |
MakeTownHouse(tile, t->index, construction_counter, construction_stage, size_flags, house); |
0 | 1284 |
} |
1285 |
} |
|
1286 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1287 |
static bool BuildTownHouse(Town *t, TileIndex tile) |
0 | 1288 |
{ |
1289 |
int32 r; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1290 |
|
0 | 1291 |
// make sure it's possible |
1292 |
if (!EnsureNoVehicle(tile)) return false; |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1293 |
if (IsSteepSlope(GetTileSlope(tile, NULL))) return false; |
0 | 1294 |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1295 |
r = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR); |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2646
diff
changeset
|
1296 |
if (CmdFailed(r)) return false; |
0 | 1297 |
|
1298 |
DoBuildTownHouse(t, tile); |
|
1299 |
return true; |
|
1300 |
} |
|
1301 |
||
1302 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1303 |
static void DoClearTownHouseHelper(TileIndex tile) |
0 | 1304 |
{ |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1305 |
assert(IsTileType(tile, MP_HOUSE)); |
0 | 1306 |
DoClearSquare(tile); |
1307 |
DeleteAnimatedTile(tile); |
|
1308 |
} |
|
1309 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1310 |
static void ClearTownHouse(Town *t, TileIndex tile) |
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1311 |
{ |
3377
014725164f97
(svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents:
3359
diff
changeset
|
1312 |
uint house = GetHouseType(tile); |
0 | 1313 |
uint eflags; |
1314 |
||
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1315 |
assert(IsTileType(tile, MP_HOUSE)); |
0 | 1316 |
|
1317 |
// need to align the tile to point to the upper left corner of the house |
|
1318 |
if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks. |
|
1319 |
if (_housetype_extra_flags[house-1] & 0x04) { |
|
1320 |
house--; |
|
1981 | 1321 |
tile += TileDiffXY(-1, 0); |
0 | 1322 |
} else if (_housetype_extra_flags[house-1] & 0x18) { |
1323 |
house--; |
|
1981 | 1324 |
tile += TileDiffXY(0, -1); |
0 | 1325 |
} else if (_housetype_extra_flags[house-2] & 0x10) { |
1326 |
house-=2; |
|
1981 | 1327 |
tile += TileDiffXY(-1, 0); |
0 | 1328 |
} else if (_housetype_extra_flags[house-3] & 0x10) { |
1329 |
house-=3; |
|
1981 | 1330 |
tile += TileDiffXY(-1, -1); |
0 | 1331 |
} |
1332 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1333 |
|
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1334 |
// Remove population from the town if the house is finished. |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1335 |
if (GetHouseBuildingStage(tile) == TOWN_HOUSE_COMPLETED) { |
0 | 1336 |
ChangePopulation(t, -_housetype_population[house]); |
1337 |
} |
|
1338 |
||
1339 |
t->num_houses--; |
|
1340 |
||
1341 |
// Clear flags for houses that only may exist once/town. |
|
483
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1342 |
switch (house) { |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1343 |
case HOUSE_TEMP_CHURCH: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1344 |
case HOUSE_ARCT_CHURCH: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1345 |
case HOUSE_SNOW_CHURCH: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1346 |
case HOUSE_TROP_CHURCH: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1347 |
case HOUSE_TOY_CHURCH: |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1348 |
CLRBIT(t->flags12, TOWN_HAS_CHURCH); |
483
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1349 |
break; |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1350 |
case HOUSE_STADIUM: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1351 |
case HOUSE_MODERN_STADIUM: |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1352 |
CLRBIT(t->flags12, TOWN_HAS_STADIUM); |
483
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1353 |
break; |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1354 |
default: |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1355 |
break; |
e27622930ddc
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1356 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1357 |
|
0 | 1358 |
// Do the actual clearing of tiles |
1359 |
eflags = _housetype_extra_flags[house]; |
|
1360 |
DoClearTownHouseHelper(tile); |
|
1981 | 1361 |
if (eflags & 0x14) DoClearTownHouseHelper(tile + TileDiffXY(1, 0)); |
1362 |
if (eflags & 0x18) DoClearTownHouseHelper(tile + TileDiffXY(0, 1)); |
|
1363 |
if (eflags & 0x10) DoClearTownHouseHelper(tile + TileDiffXY(1, 1)); |
|
0 | 1364 |
} |
1365 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1366 |
/** Rename a town (server-only). |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1367 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1368 |
* @param p1 town ID to rename |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1369 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1370 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1371 |
int32 CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1372 |
{ |
1373 |
StringID str; |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1374 |
Town *t; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1375 |
|
5543
4d8dfa498905
(svn r11077) [0.5] -Fix: Possible NULL pointer dereference.
rubidium
parents:
5495
diff
changeset
|
1376 |
if (!IsValidTownID(p1) || _cmd_text == NULL || _cmd_text[0] == '\0') return CMD_ERROR; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1377 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1378 |
t = GetTown(p1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1379 |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1793
diff
changeset
|
1380 |
str = AllocateNameUnique(_cmd_text, 4); |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1381 |
if (str == 0) return CMD_ERROR; |
0 | 1382 |
|
1383 |
if (flags & DC_EXEC) { |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1384 |
DeleteName(t->townnametype); |
0 | 1385 |
t->townnametype = str; |
1386 |
||
1387 |
UpdateTownVirtCoord(t); |
|
1388 |
_town_sort_dirty = true; |
|
1389 |
UpdateAllStationVirtCoord(); |
|
1390 |
MarkWholeScreenDirty(); |
|
1391 |
} else { |
|
1392 |
DeleteName(str); |
|
1393 |
} |
|
1394 |
return 0; |
|
1395 |
} |
|
1396 |
||
1397 |
// Called from GUI |
|
1398 |
void ExpandTown(Town *t) |
|
1399 |
{ |
|
1400 |
int amount, n; |
|
1401 |
||
1402 |
_generating_world = true; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1403 |
|
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1404 |
/* The more houses, the faster we grow */ |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1405 |
amount = RandomRange(t->num_houses / 10) + 3; |
0 | 1406 |
t->num_houses += amount; |
1407 |
UpdateTownRadius(t); |
|
1408 |
||
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1409 |
n = amount * 10; |
0 | 1410 |
do GrowTown(t); while (--n); |
1411 |
||
1412 |
t->num_houses -= amount; |
|
1413 |
UpdateTownRadius(t); |
|
1414 |
||
1415 |
UpdateTownMaxPass(t); |
|
1416 |
_generating_world = false; |
|
1417 |
} |
|
1418 |
||
1419 |
const byte _town_action_costs[8] = { |
|
1420 |
2, 4, 9, 35, 48, 53, 117, 175 |
|
1421 |
}; |
|
1422 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1423 |
static void TownActionAdvertiseSmall(Town* t) |
0 | 1424 |
{ |
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1425 |
ModifyStationRatingAround(t->xy, _current_player, 0x40, 10); |
0 | 1426 |
} |
1427 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1428 |
static void TownActionAdvertiseMedium(Town* t) |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1429 |
{ |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1430 |
ModifyStationRatingAround(t->xy, _current_player, 0x70, 15); |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1431 |
} |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1432 |
|
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1433 |
static void TownActionAdvertiseLarge(Town* t) |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1434 |
{ |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1435 |
ModifyStationRatingAround(t->xy, _current_player, 0xA0, 20); |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1436 |
} |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1437 |
|
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1438 |
static void TownActionRoadRebuild(Town* t) |
0 | 1439 |
{ |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
1440 |
const Player* p; |
0 | 1441 |
|
1442 |
t->road_build_months = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1443 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1444 |
SetDParam(0, t->index); |
0 | 1445 |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1928
diff
changeset
|
1446 |
p = GetPlayer(_current_player); |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1447 |
SetDParam(1, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1448 |
SetDParam(2, p->name_2); |
0 | 1449 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1450 |
AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING, |
0 | 1451 |
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0); |
1452 |
} |
|
1453 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1454 |
static bool DoBuildStatueOfCompany(TileIndex tile) |
0 | 1455 |
{ |
2498
befad2fe53d2
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1456 |
PlayerID old; |
0 | 1457 |
int32 r; |
1458 |
||
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1459 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return false; |
0 | 1460 |
|
2986
f901acd775a9
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1461 |
if (!IsTileType(tile, MP_HOUSE) && |
f901acd775a9
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1462 |
!IsTileType(tile, MP_CLEAR) && |
f901acd775a9
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1463 |
!IsTileType(tile, MP_TREES)) { |
0 | 1464 |
return false; |
2986
f901acd775a9
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1465 |
} |
0 | 1466 |
|
1467 |
old = _current_player; |
|
1468 |
_current_player = OWNER_NONE; |
|
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1469 |
r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 1470 |
_current_player = old; |
1471 |
||
2646
a91fd482fce5
(svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents:
2639
diff
changeset
|
1472 |
if (CmdFailed(r)) return false; |
0 | 1473 |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3282
diff
changeset
|
1474 |
MakeStatue(tile, _current_player); |
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3282
diff
changeset
|
1475 |
MarkTileDirtyByTile(tile); |
0 | 1476 |
|
1477 |
return true; |
|
1478 |
} |
|
1479 |
||
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1480 |
/** |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1481 |
* Search callback function for TownActionBuildStatue |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1482 |
* @param data that is passed by the caller. In this case, nothing |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1483 |
* @result of the test |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1484 |
*/ |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1485 |
static bool SearchTileForStatue(TileIndex tile, uint32 data) |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1486 |
{ |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1487 |
return DoBuildStatueOfCompany(tile); |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1488 |
} |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1489 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1490 |
/** |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1491 |
* Perform a 9x9 tiles circular search from the center of the town |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1492 |
* in order to find a free tile to place a statue |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1493 |
* @param t town to search in |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1494 |
*/ |
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1495 |
static void TownActionBuildStatue(Town* t) |
0 | 1496 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1497 |
TileIndex tile = t->xy; |
0 | 1498 |
|
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1499 |
if (CircularTileSearch(tile, 9, SearchTileForStatue, 0)) |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
1500 |
SETBIT(t->statues, _current_player); ///< Once found and built, "inform" the Town |
0 | 1501 |
} |
1502 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1503 |
static void TownActionFundBuildings(Town* t) |
0 | 1504 |
{ |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1505 |
// Build next tick |
0 | 1506 |
t->grow_counter = 1; |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1507 |
// If we were not already growing |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1508 |
SETBIT(t->flags12, TOWN_IS_FUNDED); |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1509 |
// And grow for 3 months |
0 | 1510 |
t->fund_buildings_months = 3; |
1511 |
} |
|
1512 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1513 |
static void TownActionBuyRights(Town* t) |
0 | 1514 |
{ |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1515 |
t->exclusive_counter = 12; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1516 |
t->exclusivity = _current_player; |
0 | 1517 |
|
1518 |
ModifyStationRatingAround(t->xy, _current_player, 130, 17); |
|
1519 |
} |
|
1520 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1521 |
static void TownActionBribe(Town* t) |
0 | 1522 |
{ |
1523 |
if (!RandomRange(15)) { |
|
1524 |
Station *st; |
|
1525 |
||
1526 |
// set as unwanted for 6 months |
|
1527 |
t->unwanted[_current_player] = 6; |
|
1528 |
||
1529 |
// set all close by station ratings to 0 |
|
1530 |
FOR_ALL_STATIONS(st) { |
|
1531 |
if (st->town == t && st->owner == _current_player) { |
|
2549 | 1532 |
uint i; |
1533 |
||
1534 |
for (i = 0; i != NUM_CARGO; i++) st->goods[i].rating = 0; |
|
0 | 1535 |
} |
1536 |
} |
|
1537 |
||
1538 |
// only show errormessage to the executing player. All errors are handled command.c |
|
1539 |
// but this is special, because it can only 'fail' on a DC_EXEC |
|
2425
99e1e8430a28
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2360
diff
changeset
|
1540 |
if (IsLocalPlayer()) ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0); |
0 | 1541 |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1542 |
/* decrease by a lot! |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1543 |
* ChangeTownRating is only for stuff in demolishing. Bribe failure should |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1544 |
* be independent of any cheat settings |
0 | 1545 |
*/ |
2549 | 1546 |
if (t->ratings[_current_player] > RATING_BRIBE_DOWN_TO) { |
1005 | 1547 |
t->ratings[_current_player] = RATING_BRIBE_DOWN_TO; |
2549 | 1548 |
} |
0 | 1549 |
} else { |
1005 | 1550 |
ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM); |
0 | 1551 |
} |
1552 |
} |
|
1553 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1554 |
typedef void TownActionProc(Town* t); |
0 | 1555 |
static TownActionProc * const _town_action_proc[] = { |
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1556 |
TownActionAdvertiseSmall, |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1557 |
TownActionAdvertiseMedium, |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1558 |
TownActionAdvertiseLarge, |
0 | 1559 |
TownActionRoadRebuild, |
1560 |
TownActionBuildStatue, |
|
1561 |
TownActionFundBuildings, |
|
1562 |
TownActionBuyRights, |
|
1563 |
TownActionBribe |
|
1564 |
}; |
|
1565 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1566 |
extern uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1567 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1568 |
/** Do a town action. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1569 |
* This performs an action such as advertising, building a statue, funding buildings, |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1570 |
* but also bribing the town-council |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1571 |
* @param tile unused |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1572 |
* @param p1 town to do the action at |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1573 |
* @param p2 action to perform, @see _town_action_proc for the list of available actions |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1574 |
*/ |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1575 |
int32 CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1576 |
{ |
1577 |
int32 cost; |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1578 |
Town *t; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1579 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
1580 |
if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1581 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1582 |
t = GetTown(p1); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1583 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1584 |
if (!HASBIT(GetMaskOfTownActions(NULL, _current_player, t), p2)) return CMD_ERROR; |
0 | 1585 |
|
1586 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1587 |
||
1588 |
cost = (_price.build_industry >> 8) * _town_action_costs[p2]; |
|
1589 |
||
1590 |
if (flags & DC_EXEC) { |
|
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1591 |
_town_action_proc[p2](t); |
0 | 1592 |
InvalidateWindow(WC_TOWN_AUTHORITY, p1); |
1593 |
} |
|
1594 |
||
1595 |
return cost; |
|
1596 |
} |
|
1597 |
||
1598 |
static void UpdateTownGrowRate(Town *t) |
|
1599 |
{ |
|
1600 |
int n; |
|
1601 |
Station *st; |
|
1602 |
byte m; |
|
1603 |
Player *p; |
|
1604 |
||
1605 |
// Reset player ratings if they're low |
|
1606 |
FOR_ALL_PLAYERS(p) { |
|
1607 |
if (p->is_active && t->ratings[p->index] <= 200) { |
|
1608 |
t->ratings[p->index] += 5; |
|
1609 |
} |
|
1610 |
} |
|
1611 |
||
1612 |
n = 0; |
|
1613 |
FOR_ALL_STATIONS(st) { |
|
1245
768d9bc95aaa
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
1614 |
if (DistanceSquare(st->xy, t->xy) <= t->radius[0]) { |
0 | 1615 |
if (st->time_since_load <= 20 || st->time_since_unload <= 20) { |
1616 |
n++; |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
1617 |
if (IsValidPlayer(st->owner) && t->ratings[st->owner] <= 1000-12) |
0 | 1618 |
t->ratings[st->owner] += 12; |
1619 |
} else { |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
1620 |
if (IsValidPlayer(st->owner) && t->ratings[st->owner] >= -1000+15) |
0 | 1621 |
t->ratings[st->owner] -= 15; |
1622 |
} |
|
1623 |
} |
|
1624 |
} |
|
1625 |
||
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1626 |
CLRBIT(t->flags12, TOWN_IS_FUNDED); |
0 | 1627 |
|
1628 |
if (t->fund_buildings_months != 0) { |
|
470
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1629 |
static const byte _grow_count_values[6] = { |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1630 |
60, 60, 60, 50, 40, 30 |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1631 |
}; |
80d30b9c3552
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1632 |
m = _grow_count_values[min(n, 5)]; |
0 | 1633 |
t->fund_buildings_months--; |
1634 |
} else if (n == 0) { |
|
1635 |
m = 160; |
|
1636 |
if (!CHANCE16(1, 12)) |
|
1637 |
return; |
|
1638 |
} else { |
|
1639 |
static const byte _grow_count_values[5] = { |
|
1640 |
210, 150, 110, 80, 50 |
|
1641 |
}; |
|
1642 |
m = _grow_count_values[min(n, 5) - 1]; |
|
1643 |
} |
|
1644 |
||
1645 |
if (_opt.landscape == LT_HILLY) { |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1646 |
if (TilePixelHeight(t->xy) >= _opt.snow_line && t->act_food == 0 && t->population > 90) |
0 | 1647 |
return; |
1648 |
} else if (_opt.landscape == LT_DESERT) { |
|
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1649 |
if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food==0 || t->act_water==0) && t->population > 60) |
0 | 1650 |
return; |
1651 |
} |
|
1652 |
||
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1653 |
t->growth_rate = m / (t->num_houses / 50 + 1); |
0 | 1654 |
if (m <= t->grow_counter) |
1655 |
t->grow_counter = m; |
|
1656 |
||
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1657 |
SETBIT(t->flags12, TOWN_IS_FUNDED); |
0 | 1658 |
} |
1659 |
||
1660 |
static void UpdateTownAmounts(Town *t) |
|
1661 |
{ |
|
1662 |
// Using +1 here to prevent overflow and division by zero |
|
1663 |
t->pct_pass_transported = t->new_act_pass * 256 / (t->new_max_pass + 1); |
|
1664 |
||
1665 |
t->max_pass = t->new_max_pass; t->new_max_pass = 0; |
|
1666 |
t->act_pass = t->new_act_pass; t->new_act_pass = 0; |
|
1667 |
t->act_food = t->new_act_food; t->new_act_food = 0; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1668 |
t->act_water = t->new_act_water; t->new_act_water = 0; |
0 | 1669 |
|
1670 |
// Using +1 here to prevent overflow and division by zero |
|
1671 |
t->pct_mail_transported = t->new_act_mail * 256 / (t->new_max_mail + 1); |
|
1672 |
t->max_mail = t->new_max_mail; t->new_max_mail = 0; |
|
1673 |
t->act_mail = t->new_act_mail; t->new_act_mail = 0; |
|
1674 |
||
1675 |
InvalidateWindow(WC_TOWN_VIEW, t->index); |
|
1676 |
} |
|
1677 |
||
1678 |
static void UpdateTownUnwanted(Town *t) |
|
1679 |
{ |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1680 |
const Player* p; |
0 | 1681 |
|
1682 |
FOR_ALL_PLAYERS(p) { |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1683 |
if (t->unwanted[p->index] > 0) t->unwanted[p->index]--; |
0 | 1684 |
} |
1685 |
} |
|
1686 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1687 |
bool CheckIfAuthorityAllows(TileIndex tile) |
0 | 1688 |
{ |
1689 |
Town *t; |
|
1690 |
||
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
1691 |
if (!IsValidPlayer(_current_player)) return true; |
0 | 1692 |
|
1693 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1694 |
if (t == NULL) return true; |
0 | 1695 |
|
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1696 |
if (t->ratings[_current_player] > -200) return true; |
0 | 1697 |
|
1698 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1699 |
SetDParam(0, t->index); |
0 | 1700 |
|
1701 |
return false; |
|
1702 |
} |
|
1703 |
||
1704 |
||
3983
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1705 |
Town* CalcClosestTownFromTile(TileIndex tile, uint threshold) |
0 | 1706 |
{ |
1707 |
Town *t; |
|
1708 |
uint dist, best = threshold; |
|
1709 |
Town *best_town = NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1710 |
|
0 | 1711 |
FOR_ALL_TOWNS(t) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1712 |
dist = DistanceManhattan(tile, t->xy); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1713 |
if (dist < best) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1714 |
best = dist; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1715 |
best_town = t; |
0 | 1716 |
} |
1717 |
} |
|
1718 |
||
1719 |
return best_town; |
|
1720 |
} |
|
1721 |
||
3983
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1722 |
|
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1723 |
Town *ClosestTownFromTile(TileIndex tile, uint threshold) |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1724 |
{ |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1725 |
if (IsTileType(tile, MP_HOUSE) || ( |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1726 |
IsTileType(tile, MP_STREET) && |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1727 |
(IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1728 |
)) { |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1729 |
return GetTownByTile(tile); |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1730 |
} else { |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1731 |
return CalcClosestTownFromTile(tile, threshold); |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1732 |
} |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1733 |
} |
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1734 |
|
d2d6496238e4
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
1735 |
|
0 | 1736 |
void ChangeTownRating(Town *t, int add, int max) |
1737 |
{ |
|
1738 |
int rating; |
|
1739 |
||
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1740 |
// if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff |
2639 | 1741 |
if (t == NULL || |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
1742 |
!IsValidPlayer(_current_player) || |
2639 | 1743 |
(_cheats.magic_bulldozer.value && add < 0)) { |
0 | 1744 |
return; |
2639 | 1745 |
} |
0 | 1746 |
|
1747 |
SETBIT(t->have_ratings, _current_player); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1748 |
|
0 | 1749 |
rating = t->ratings[_current_player]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1750 |
|
0 | 1751 |
if (add < 0) { |
1752 |
if (rating > max) { |
|
1753 |
rating += add; |
|
1754 |
if (rating < max) rating = max; |
|
1755 |
} |
|
1756 |
} else { |
|
1757 |
if (rating < max) { |
|
1758 |
rating += add; |
|
1759 |
if (rating > max) rating = max; |
|
1760 |
} |
|
1761 |
} |
|
1762 |
t->ratings[_current_player] = rating; |
|
1763 |
} |
|
1764 |
||
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1765 |
/* penalty for removing town-owned stuff */ |
0 | 1766 |
static const int _default_rating_settings [3][3] = { |
1767 |
// ROAD_REMOVE, TUNNELBRIDGE_REMOVE, INDUSTRY_REMOVE |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1768 |
{ 0, 128, 384}, // Permissive |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1769 |
{ 48, 192, 480}, // Neutral |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1770 |
{ 96, 384, 768}, // Hostile |
0 | 1771 |
}; |
1772 |
||
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1773 |
bool CheckforTownRating(uint32 flags, Town *t, byte type) |
0 | 1774 |
{ |
1775 |
int modemod; |
|
1776 |
||
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1777 |
// if magic_bulldozer cheat is active, town doesn't restrict your destructive actions |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
1778 |
if (t == NULL || !IsValidPlayer(_current_player) || _cheats.magic_bulldozer.value) |
0 | 1779 |
return true; |
1780 |
||
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1781 |
/* check if you're allowed to remove the street/bridge/tunnel/industry |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1782 |
* owned by a town no removal if rating is lower than ... depends now on |
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
1783 |
* difficulty setting. Minimum town rating selected by difficulty level |
0 | 1784 |
*/ |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1451
diff
changeset
|
1785 |
modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type]; |
0 | 1786 |
|
1787 |
if (t->ratings[_current_player] < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) { |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1788 |
SetDParam(0, t->index); |
0 | 1789 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
1790 |
return false; |
|
1791 |
} |
|
1792 |
||
1793 |
return true; |
|
1794 |
} |
|
1795 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
1796 |
void TownsMonthlyLoop(void) |
0 | 1797 |
{ |
1798 |
Town *t; |
|
1799 |
||
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1800 |
FOR_ALL_TOWNS(t) { |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1801 |
if (t->road_build_months != 0) t->road_build_months--; |
0 | 1802 |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1803 |
if (t->exclusive_counter != 0) |
4000
bab1ebc37da0
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1804 |
if (--t->exclusive_counter == 0) t->exclusivity = (byte)-1; |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1805 |
|
0 | 1806 |
UpdateTownGrowRate(t); |
1807 |
UpdateTownAmounts(t); |
|
1808 |
UpdateTownUnwanted(t); |
|
1809 |
} |
|
1810 |
} |
|
1811 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
1812 |
void InitializeTowns(void) |
0 | 1813 |
{ |
1814 |
Subsidy *s; |
|
1815 |
||
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1816 |
/* Clean the town pool and create 1 block in it */ |
4983 | 1817 |
CleanPool(&_Town_pool); |
1818 |
AddBlockToPool(&_Town_pool); |
|
0 | 1819 |
|
1820 |
memset(_subsidies, 0, sizeof(_subsidies)); |
|
1821 |
for (s=_subsidies; s != endof(_subsidies); s++) |
|
2469
1bfbb0dc0b75
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1822 |
s->cargo_type = CT_INVALID; |
0 | 1823 |
|
1824 |
_cur_town_ctr = 0; |
|
1529
be4a2259d2ff
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
1825 |
_cur_town_iter = 0; |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1826 |
_total_towns = 0; |
0 | 1827 |
_town_sort_dirty = true; |
1828 |
} |
|
1829 |
||
1830 |
const TileTypeProcs _tile_type_town_procs = { |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1831 |
DrawTile_Town, /* draw_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1832 |
GetSlopeZ_Town, /* get_slope_z_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1833 |
ClearTile_Town, /* clear_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1834 |
GetAcceptedCargo_Town, /* get_accepted_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1835 |
GetTileDesc_Town, /* get_tile_desc_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1836 |
GetTileTrackStatus_Town, /* get_tile_track_status_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1837 |
ClickTile_Town, /* click_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1838 |
AnimateTile_Town, /* animate_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1839 |
TileLoop_Town, /* tile_loop_clear */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1840 |
ChangeTileOwner_Town, /* change_tile_owner_clear */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1841 |
NULL, /* get_produced_cargo_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1842 |
NULL, /* vehicle_enter_tile_proc */ |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1843 |
GetSlopeTileh_Town, /* get_slope_tileh_proc */ |
0 | 1844 |
}; |
1845 |
||
1846 |
||
1847 |
// Save and load of towns. |
|
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
1848 |
static const SaveLoad _town_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1849 |
SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1850 |
SLE_CONDVAR(Town, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1851 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1852 |
SLE_CONDVAR(Town, population, SLE_FILE_U16 | SLE_VAR_U32, 0, 2), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1853 |
SLE_CONDVAR(Town, population, SLE_UINT32, 3, SL_MAX_VERSION), |
0 | 1854 |
|
1855 |
||
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1856 |
SLE_VAR(Town, num_houses, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1857 |
SLE_VAR(Town, townnametype, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1858 |
SLE_VAR(Town, townnameparts, SLE_UINT32), |
0 | 1859 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1860 |
SLE_VAR(Town, flags12, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1861 |
SLE_VAR(Town, statues, SLE_UINT8), |
0 | 1862 |
|
1863 |
// sort_index_obsolete was stored here in savegame format 0 - 1 |
|
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3184
diff
changeset
|
1864 |
SLE_CONDNULL(1, 0, 1), |
0 | 1865 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1866 |
SLE_VAR(Town, have_ratings, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1867 |
SLE_ARR(Town, ratings, SLE_INT16, 8), |
0 | 1868 |
// failed bribe attempts are stored since savegame format 4 |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1869 |
SLE_CONDARR(Town, unwanted, SLE_INT8, 8, 4,SL_MAX_VERSION), |
1377
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1870 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1871 |
SLE_CONDVAR(Town, max_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1872 |
SLE_CONDVAR(Town, max_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1873 |
SLE_CONDVAR(Town, new_max_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1874 |
SLE_CONDVAR(Town, new_max_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1875 |
SLE_CONDVAR(Town, act_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1876 |
SLE_CONDVAR(Town, act_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1877 |
SLE_CONDVAR(Town, new_act_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1878 |
SLE_CONDVAR(Town, new_act_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
0 | 1879 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1880 |
SLE_CONDVAR(Town, max_pass, SLE_UINT32, 9, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1881 |
SLE_CONDVAR(Town, max_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1882 |
SLE_CONDVAR(Town, new_max_pass, SLE_UINT32, 9, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1883 |
SLE_CONDVAR(Town, new_max_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1884 |
SLE_CONDVAR(Town, act_pass, SLE_UINT32, 9, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1885 |
SLE_CONDVAR(Town, act_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1886 |
SLE_CONDVAR(Town, new_act_pass, SLE_UINT32, 9, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1887 |
SLE_CONDVAR(Town, new_act_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
0 | 1888 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1889 |
SLE_VAR(Town, pct_pass_transported, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1890 |
SLE_VAR(Town, pct_mail_transported, SLE_UINT8), |
0 | 1891 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1892 |
SLE_VAR(Town, act_food, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1893 |
SLE_VAR(Town, act_water, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1894 |
SLE_VAR(Town, new_act_food, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1895 |
SLE_VAR(Town, new_act_water, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1896 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1897 |
SLE_VAR(Town, time_until_rebuild, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1898 |
SLE_VAR(Town, grow_counter, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1899 |
SLE_VAR(Town, growth_rate, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1900 |
SLE_VAR(Town, fund_buildings_months, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1901 |
SLE_VAR(Town, road_build_months, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1902 |
|
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1903 |
SLE_VAR(Town, exclusivity, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1904 |
SLE_VAR(Town, exclusive_counter, SLE_UINT8), |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1905 |
// reserve extra space in savegame here. (currently 30 bytes) |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3184
diff
changeset
|
1906 |
SLE_CONDNULL(30, 2, SL_MAX_VERSION), |
0 | 1907 |
|
1908 |
SLE_END() |
|
1909 |
}; |
|
1910 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
1911 |
static void Save_TOWN(void) |
0 | 1912 |
{ |
1913 |
Town *t; |
|
1914 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1915 |
FOR_ALL_TOWNS(t) { |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1916 |
SlSetArrayIndex(t->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1917 |
SlObject(t, _town_desc); |
0 | 1918 |
} |
1919 |
} |
|
1920 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
1921 |
static void Load_TOWN(void) |
0 | 1922 |
{ |
1923 |
int index; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1924 |
|
1261
d7c7447dd22d
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
1925 |
_total_towns = 0; |
d7c7447dd22d
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
1926 |
|
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1927 |
while ((index = SlIterateArray()) != -1) { |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1928 |
Town *t; |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1929 |
|
4983 | 1930 |
if (!AddBlockIfNeeded(&_Town_pool, index)) |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1931 |
error("Towns: failed loading savegame: too many towns"); |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1932 |
|
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1933 |
t = GetTown(index); |
0 | 1934 |
SlObject(t, _town_desc); |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1935 |
|
5298
6d4c150bdd94
(svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents:
5247
diff
changeset
|
1936 |
_total_towns++; |
0 | 1937 |
} |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1938 |
|
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1939 |
/* This is to ensure all pointers are within the limits of |
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1940 |
* the size of the TownPool */ |
5247
c3eece01af11
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
1941 |
if (_cur_town_ctr > GetMaxTownIndex()) |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
1942 |
_cur_town_ctr = 0; |
0 | 1943 |
} |
1944 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1080
diff
changeset
|
1945 |
void AfterLoadTown(void) |
0 | 1946 |
{ |
1947 |
Town *t; |
|
1948 |
FOR_ALL_TOWNS(t) { |
|
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1949 |
UpdateTownRadius(t); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1950 |
UpdateTownVirtCoord(t); |
0 | 1951 |
} |
1952 |
_town_sort_dirty = true; |
|
1953 |
} |
|
1954 |
||
1955 |
||
1956 |
const ChunkHandler _town_chunk_handlers[] = { |
|
1957 |
{ 'CITY', Save_TOWN, Load_TOWN, CH_ARRAY | CH_LAST}, |
|
1958 |
}; |