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