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