author | smatz |
Thu, 03 Apr 2008 19:55:40 +0000 | |
changeset 9302 | 4aa3c4a44b16 |
parent 9292 | 4f5612017238 |
child 9310 | 08b3b745d299 |
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" |
8615
6b91ca653bad
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8612
diff
changeset
|
7 |
#include "tile_cmd.h" |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
8 |
#include "debug.h" |
3144
426b825578f9
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3071
diff
changeset
|
9 |
#include "road_map.h" |
8598
14ae80fe4c8f
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8584
diff
changeset
|
10 |
#include "road_internal.h" /* Cleaning up road bits */ |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6668
diff
changeset
|
11 |
#include "landscape.h" |
3319
7d04847e4689
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3310
diff
changeset
|
12 |
#include "town_map.h" |
3154 | 13 |
#include "tunnel_map.h" |
8720
4e60c30e2006
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8710
diff
changeset
|
14 |
#include "viewport_func.h" |
0 | 15 |
#include "town.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
16 |
#include "command_func.h" |
0 | 17 |
#include "industry.h" |
9281
d8cd9ac52a68
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents:
9259
diff
changeset
|
18 |
#include "station_base.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8728
diff
changeset
|
19 |
#include "player_base.h" |
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
9203
diff
changeset
|
20 |
#include "news_func.h" |
0 | 21 |
#include "saveload.h" |
22 |
#include "gui.h" |
|
3310
7339b2b1e957
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3282
diff
changeset
|
23 |
#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
|
24 |
#include "water_map.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
25 |
#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
|
26 |
#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
|
27 |
#include "bridge_map.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
28 |
#include "genworld.h" |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
29 |
#include "newgrf.h" |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
30 |
#include "newgrf_callbacks.h" |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
31 |
#include "newgrf_house.h" |
7125
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
32 |
#include "newgrf_commons.h" |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
33 |
#include "newgrf_townname.h" |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
34 |
#include "misc/autoptr.hpp" |
8078
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
35 |
#include "autoslope.h" |
8205
71006e01e45b
(svn r11243) -Fix: update waypoint signs when renaming a town
glx
parents:
8180
diff
changeset
|
36 |
#include "waypoint.h" |
8345
6caa3fdb972c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
8343
diff
changeset
|
37 |
#include "transparency.h" |
8579
3efbb430092e
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents:
8465
diff
changeset
|
38 |
#include "tunnelbridge_map.h" |
8610
17cc343a23dd
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8604
diff
changeset
|
39 |
#include "strings_func.h" |
8627
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8620
diff
changeset
|
40 |
#include "window_func.h" |
8710
52015340050c
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8693
diff
changeset
|
41 |
#include "string_func.h" |
9283
624272490f5a
(svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium
parents:
9281
diff
changeset
|
42 |
#include "newgrf_cargo.h" |
8579
3efbb430092e
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents:
8465
diff
changeset
|
43 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
44 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
45 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
46 |
#include "table/town_land.h" |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
47 |
|
8764
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
48 |
uint _total_towns; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
49 |
HouseSpec _house_specs[HOUSE_MAX]; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
50 |
|
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
51 |
bool _town_sort_dirty; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
52 |
byte _town_sort_order; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
53 |
const Town **_town_sort; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
54 |
|
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
55 |
Town *_cleared_town; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
56 |
int _cleared_town_rating; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
57 |
|
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
58 |
/* Initialize the town-pool */ |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
59 |
DEFINE_OLD_POOL_GENERIC(Town, Town) |
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
60 |
|
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
61 |
Town::Town(TileIndex tile) |
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
62 |
{ |
7906
3fe5ef622ddd
(svn r10787) -Fix r10755: _total_towns was not increased when placing town manually in scenario editor
glx
parents:
7897
diff
changeset
|
63 |
if (tile != 0) _total_towns++; |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
64 |
this->xy = tile; |
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
65 |
} |
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
66 |
|
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
67 |
Town::~Town() |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
68 |
{ |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
69 |
free(this->name); |
7909
8df54a2839a1
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7906
diff
changeset
|
70 |
|
8df54a2839a1
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7906
diff
changeset
|
71 |
if (CleaningPool()) return; |
8df54a2839a1
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7906
diff
changeset
|
72 |
|
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
73 |
Industry *i; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
74 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
75 |
/* Delete town authority window |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
76 |
* and remove from list of sorted towns */ |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
77 |
DeleteWindowById(WC_TOWN_VIEW, this->index); |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
78 |
_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
|
79 |
_total_towns--; |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
80 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
81 |
/* Delete all industries belonging to the town */ |
7886
b02aa3532d1d
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7882
diff
changeset
|
82 |
FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i; |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
83 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
84 |
/* Go through all tiles and delete those belonging to the town */ |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
85 |
for (TileIndex tile = 0; tile < MapSize(); ++tile) { |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
86 |
switch (GetTileType(tile)) { |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
87 |
case MP_HOUSE: |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
88 |
if (GetTownByTile(tile) == this) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
89 |
break; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
90 |
|
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7831
diff
changeset
|
91 |
case MP_ROAD: |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
92 |
case MP_TUNNELBRIDGE: |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
93 |
if (IsTileOwner(tile, OWNER_TOWN) && |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
94 |
ClosestTownFromTile(tile, (uint)-1) == this) |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
95 |
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
|
96 |
break; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
97 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
98 |
default: |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
99 |
break; |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
100 |
} |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
101 |
} |
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
102 |
|
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
103 |
DeleteSubsidyWithTown(this->index); |
4396
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
104 |
|
549f28155809
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
105 |
MarkWholeScreenDirty(); |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
106 |
|
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
107 |
this->xy = 0; |
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
108 |
} |
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
109 |
|
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
110 |
/** |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
111 |
* Generate a random town road layout. |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
112 |
* |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
113 |
* The layout is based on the TileHash. |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
114 |
*/ |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
115 |
void Town::InitializeLayout() |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
116 |
{ |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
117 |
this->layout = (TownLayout)(TileHash(TileX(this->xy), TileY(this->xy)) % NUM_TLS); |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
118 |
|
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
119 |
/* Set invalid layouts to valid ones */ |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
120 |
switch (this->layout) { |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
121 |
default: break; |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
122 |
case TL_RANDOM: this->layout = TL_ORIGINAL; break; |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
123 |
case TL_NO_ROADS: this->layout = TL_BETTER_ROADS; break; |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
124 |
} |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
125 |
} |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
126 |
|
0 | 127 |
// Local |
128 |
static int _grow_town_result; |
|
129 |
||
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
130 |
/* Describe the possible states */ |
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
131 |
enum TownGrowthResult { |
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
132 |
GROWTH_SUCCEED = -1, |
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
133 |
GROWTH_SEARCH_STOPPED = 0 |
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
134 |
// GROWTH_SEARCH_RUNNING >= 1 |
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
135 |
}; |
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
136 |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
137 |
static bool BuildTownHouse(Town *t, TileIndex tile); |
0 | 138 |
|
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
|
139 |
static void TownDrawHouseLift(const TileInfo *ti) |
0 | 140 |
{ |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
141 |
AddChildSpriteScreen(SPR_LIFT, PAL_NONE, 14, 60 - GetLiftPosition(ti->tile)); |
0 | 142 |
} |
143 |
||
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
|
144 |
typedef void TownDrawTileProc(const TileInfo *ti); |
0 | 145 |
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
|
146 |
TownDrawHouseLift |
0 | 147 |
}; |
148 |
||
9287
2e497ff0d009
(svn r12513) -Codechange: rename OriginalTileRandomiser something more descriptive
skidd13
parents:
9283
diff
changeset
|
149 |
/** |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
150 |
* Return a random direction |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
151 |
* |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
152 |
* @return a random direction |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
153 |
*/ |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
154 |
static inline DiagDirection RandomDiagDir() |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
155 |
{ |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
156 |
return (DiagDirection)(3 & Random()); |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
157 |
} |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
158 |
|
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
159 |
/** |
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
160 |
* House Tile drawing handler. |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
161 |
* Part of the tile loop process |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
162 |
* @param ti TileInfo of the tile to draw |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
163 |
*/ |
0 | 164 |
static void DrawTile_Town(TileInfo *ti) |
165 |
{ |
|
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
166 |
const DrawBuildingsTileStruct *dcts; |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
167 |
SpriteID image; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
168 |
SpriteID pal; |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
169 |
HouseID house_id = GetHouseType(ti->tile); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
170 |
|
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
171 |
if (house_id >= NEW_HOUSE_OFFSET) { |
6668
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
172 |
/* Houses don't necessarily need new graphics. If they don't have a |
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
173 |
* spritegroup associated with them, then the sprite for the substitute |
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
174 |
* house id is drawn instead. */ |
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
175 |
if (GetHouseSpecs(house_id)->spritegroup != NULL) { |
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
176 |
DrawNewHouseTile(ti, house_id); |
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
177 |
return; |
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
178 |
} else { |
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
179 |
house_id = GetHouseSpecs(house_id)->substitute_id; |
ed19c5d57a3a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6667
diff
changeset
|
180 |
} |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
181 |
} |
0 | 182 |
|
183 |
/* Retrieve pointer to the draw town tile struct */ |
|
9287
2e497ff0d009
(svn r12513) -Codechange: rename OriginalTileRandomiser something more descriptive
skidd13
parents:
9283
diff
changeset
|
184 |
dcts = &_town_draw_tile_data[house_id << 4 | TileHash2Bit(ti->x, ti->y) << 2 | GetHouseBuildingStage(ti->tile)]; |
0 | 185 |
|
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7829
diff
changeset
|
186 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); |
5919
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
187 |
|
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
188 |
image = dcts->ground.sprite; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
189 |
pal = dcts->ground.pal; |
2b58160d667d
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5838
diff
changeset
|
190 |
DrawGroundSprite(image, pal); |
0 | 191 |
|
9302
4aa3c4a44b16
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
9292
diff
changeset
|
192 |
/* If houses are invisible, do not draw the upper part */ |
4aa3c4a44b16
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
9292
diff
changeset
|
193 |
if (IsInvisibilitySet(TO_HOUSES)) return; |
4aa3c4a44b16
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents:
9292
diff
changeset
|
194 |
|
0 | 195 |
/* 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
|
196 |
image = dcts->building.sprite; |
2639 | 197 |
if (image != 0) { |
7829
88883899c9e6
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7722
diff
changeset
|
198 |
AddSortableSpriteToDraw(image, dcts->building.pal, |
482 | 199 |
ti->x + dcts->subtile_x, |
200 |
ti->y + dcts->subtile_y, |
|
8073
42007d9c81bb
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents:
8062
diff
changeset
|
201 |
dcts->width, |
42007d9c81bb
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents:
8062
diff
changeset
|
202 |
dcts->height, |
0 | 203 |
dcts->dz, |
7829
88883899c9e6
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7722
diff
changeset
|
204 |
ti->z, |
8345
6caa3fdb972c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
8343
diff
changeset
|
205 |
IsTransparencySet(TO_HOUSES) |
4053 | 206 |
); |
0 | 207 |
|
8345
6caa3fdb972c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
8343
diff
changeset
|
208 |
if (IsTransparencySet(TO_HOUSES)) return; |
0 | 209 |
} |
210 |
||
211 |
{ |
|
3654
4a3f8056a61c
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
212 |
int proc = dcts->draw_proc - 1; |
2639 | 213 |
|
214 |
if (proc >= 0) _town_draw_tile_procs[proc](ti); |
|
0 | 215 |
} |
216 |
} |
|
217 |
||
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
218 |
static uint GetSlopeZ_Town(TileIndex tile, uint x, uint y) |
0 | 219 |
{ |
4231
dea6a63dd058
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
220 |
return GetTileMaxZ(tile); |
0 | 221 |
} |
222 |
||
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7829
diff
changeset
|
223 |
static Foundation GetFoundation_Town(TileIndex tile, Slope tileh) |
39 | 224 |
{ |
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7829
diff
changeset
|
225 |
return FlatteningFoundation(tileh); |
39 | 226 |
} |
227 |
||
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
228 |
/** |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
229 |
* Animate a tile for a town |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
230 |
* Only certain houses can be animated |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
231 |
* The newhouses animation superseeds regular ones |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
232 |
* @param tile TileIndex of the house to animate |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
233 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
234 |
static void AnimateTile_Town(TileIndex tile) |
0 | 235 |
{ |
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
236 |
int pos, dest; |
0 | 237 |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
238 |
if (GetHouseType(tile) >= NEW_HOUSE_OFFSET) { |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
239 |
AnimateNewHouseTile(tile); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
240 |
return; |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
241 |
} |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
242 |
|
2639 | 243 |
if (_tick_counter & 3) return; |
0 | 244 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
245 |
/* If the house is not one with a lift anymore, then stop this animating. |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
246 |
* Not exactly sure when this happens, but probably when a house changes. |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
247 |
* Before this was just a return...so it'd leak animated tiles.. |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
248 |
* That bug seems to have been here since day 1?? */ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
} |
0 | 253 |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
254 |
if (!LiftHasDestination(tile)) { |
2639 | 255 |
int i; |
256 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
257 |
/* Building has 6 floors, number 0 .. 6, where 1 is illegal. |
2891
db971f08e6d8
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
258 |
* 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
|
259 |
* the height of 2 'normal' floors. |
db971f08e6d8
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
260 |
* Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */ |
0 | 261 |
do { |
2639 | 262 |
i = (Random() & 7) - 1; |
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
263 |
} while (i < 0 || i == 1 || i * 6 == GetLiftPosition(tile)); |
0 | 264 |
|
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
265 |
SetLiftDestination(tile, i); |
0 | 266 |
} |
267 |
||
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
268 |
pos = GetLiftPosition(tile); |
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
269 |
dest = GetLiftDestination(tile) * 6; |
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
270 |
pos += (pos < dest) ? 1 : -1; |
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
271 |
SetLiftPosition(tile, pos); |
0 | 272 |
|
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
273 |
if (pos == dest) HaltLift(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
274 |
|
0 | 275 |
MarkTileDirtyByTile(tile); |
276 |
} |
|
277 |
||
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
278 |
/** |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
279 |
* Determines if a town is close to a tile |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
280 |
* @param tile TileIndex of the tile to query |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
281 |
* @param dist maximum distance to be accepted |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
282 |
* @returns true if the tile correspond to the distance criteria |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
283 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
284 |
static bool IsCloseToTown(TileIndex tile, uint dist) |
0 | 285 |
{ |
2630 | 286 |
const Town* t; |
0 | 287 |
|
288 |
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
|
289 |
if (DistanceManhattan(tile, t->xy) < dist) return true; |
0 | 290 |
} |
291 |
return false; |
|
292 |
} |
|
293 |
||
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
294 |
/** |
8041
63e760418a15
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7996
diff
changeset
|
295 |
* Marks the town sign as needing a repaint. |
63e760418a15
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7996
diff
changeset
|
296 |
* |
63e760418a15
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7996
diff
changeset
|
297 |
* This function marks the area of the sign of a town as dirty for repaint. |
63e760418a15
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7996
diff
changeset
|
298 |
* |
63e760418a15
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7996
diff
changeset
|
299 |
* @param t Town requesting town sign for repaint |
63e760418a15
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7996
diff
changeset
|
300 |
* @ingroup dirty |
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
301 |
*/ |
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
302 |
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
|
303 |
{ |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
304 |
MarkAllViewportsDirty( |
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6982
diff
changeset
|
305 |
t->sign.left - 6, |
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6982
diff
changeset
|
306 |
t->sign.top - 3, |
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6982
diff
changeset
|
307 |
t->sign.left + t->sign.width_1 * 4 + 12, |
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
308 |
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
|
309 |
); |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
310 |
} |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
311 |
|
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
312 |
/** |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
313 |
* Resize the sign(label) of the town after changes in |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
314 |
* population (creation or growth or else) |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
315 |
* @param t Town to update |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
316 |
*/ |
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
317 |
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
|
318 |
{ |
836 | 319 |
Point pt; |
320 |
||
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
_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
|
327 |
MarkTownSignDirty(t); |
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
328 |
} |
0 | 329 |
|
8465
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
330 |
/** Update the virtual coords needed to draw the town sign for all towns. */ |
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
331 |
void UpdateAllTownVirtCoords() |
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
332 |
{ |
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
333 |
Town *t; |
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
334 |
FOR_ALL_TOWNS(t) { |
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
335 |
UpdateTownVirtCoord(t); |
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
336 |
} |
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
337 |
} |
d5faf7afaafd
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
8463
diff
changeset
|
338 |
|
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
339 |
/** |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
340 |
* Change the towns population |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
341 |
* @param t Town which polulation has changed |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
342 |
* @param mod polulation change (can be positive or negative) |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
343 |
*/ |
0 | 344 |
static void ChangePopulation(Town *t, int mod) |
345 |
{ |
|
346 |
t->population += mod; |
|
347 |
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
|
348 |
UpdateTownVirtCoord(t); |
0 | 349 |
|
350 |
if (_town_sort_order & 2) _town_sort_dirty = true; |
|
351 |
} |
|
352 |
||
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
353 |
/** |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
354 |
* Determines the world population |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
355 |
* Basically, count population of all towns, one by one |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
356 |
* @return uint32 the calculated population of the world |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
357 |
*/ |
6573 | 358 |
uint32 GetWorldPopulation() |
1080
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
359 |
{ |
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
360 |
uint32 pop; |
2630 | 361 |
const Town* t; |
362 |
||
1080
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
363 |
pop = 0; |
2639 | 364 |
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
|
365 |
return pop; |
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
366 |
} |
9695461dc645
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
367 |
|
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
368 |
/** |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
369 |
* Helper function for house completion stages progression |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
370 |
* @param tile TileIndex of the house (or parts of it) to "grow" |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
371 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
372 |
static void MakeSingleHouseBigger(TileIndex tile) |
0 | 373 |
{ |
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
|
374 |
assert(IsTileType(tile, MP_HOUSE)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
375 |
|
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
376 |
/* means it is completed, get out. */ |
3426
dab412dcee39
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
377 |
if (LiftHasDestination(tile)) return; |
0 | 378 |
|
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
379 |
/* progress in construction stages */ |
3432
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
380 |
IncHouseConstructionTick(tile); |
507fa7fd189d
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
381 |
if (GetHouseConstructionTick(tile) != 0) return; |
0 | 382 |
|
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
383 |
/* Check and/or */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8399
diff
changeset
|
384 |
if (HasBit(GetHouseSpecs(GetHouseType(tile))->callback_mask, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE)) { |
7711
66dffbd3b136
(svn r10493) -Codechange: update some callback ID enums to reflect their changed usage, add a few and update the comments.
rubidium
parents:
7635
diff
changeset
|
385 |
uint16 callback_res = GetHouseCallback(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
386 |
if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
387 |
} |
0 | 388 |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
389 |
if (IsHouseCompleted(tile)) { |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
390 |
/* Now that construction is complete, we can add the population of the |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
391 |
* building to the town. */ |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
392 |
ChangePopulation(GetTownByTile(tile), GetHouseSpecs(GetHouseType(tile))->population); |
0 | 393 |
} |
394 |
MarkTileDirtyByTile(tile); |
|
395 |
} |
|
396 |
||
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
397 |
/** Make the house advances in its construction stages until completion |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
398 |
* @param tile TileIndex of house |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
399 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
400 |
static void MakeTownHouseBigger(TileIndex tile) |
0 | 401 |
{ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
402 |
uint flags = GetHouseSpecs(GetHouseType(tile))->building_flags; |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
403 |
if (flags & BUILDING_HAS_1_TILE) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0)); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
404 |
if (flags & BUILDING_2_TILES_Y) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1)); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
405 |
if (flags & BUILDING_2_TILES_X) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0)); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
406 |
if (flags & BUILDING_HAS_4_TILES) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1)); |
0 | 407 |
} |
408 |
||
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
409 |
/** |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
410 |
* Periodic tic handler for houses and town |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
411 |
* @param tile been asked to do its stuff |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
412 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
413 |
static void TileLoop_Town(TileIndex tile) |
0 | 414 |
{ |
415 |
Town *t; |
|
416 |
uint32 r; |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
417 |
HouseID house_id = GetHouseType(tile); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
418 |
HouseSpec *hs = GetHouseSpecs(house_id); |
0 | 419 |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
420 |
/* NewHouseTileLoop returns false if Callback 21 succeeded, i.e. the house |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
421 |
* doesn't exist any more, so don't continue here. */ |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
422 |
if (house_id >= NEW_HOUSE_OFFSET && !NewHouseTileLoop(tile)) return; |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
423 |
|
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
424 |
if (!IsHouseCompleted(tile)) { |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
425 |
/* Construction is not completed. See if we can go further in construction*/ |
0 | 426 |
MakeTownHouseBigger(tile); |
427 |
return; |
|
428 |
} |
|
429 |
||
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
430 |
/* If the lift has a destination, it is already an animated tile. */ |
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
431 |
if ((hs->building_flags & BUILDING_IS_ANIMATED) && |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
432 |
house_id < NEW_HOUSE_OFFSET && |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
433 |
!LiftHasDestination(tile) && |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8427
diff
changeset
|
434 |
Chance16(1, 2)) |
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
435 |
AddAnimatedTile(tile); |
0 | 436 |
|
3319
7d04847e4689
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3310
diff
changeset
|
437 |
t = GetTownByTile(tile); |
0 | 438 |
|
439 |
r = Random(); |
|
440 |
||
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8399
diff
changeset
|
441 |
if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) { |
7141
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
442 |
for (uint i = 0; i < 256; i++) { |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
443 |
uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, r, house_id, t, tile); |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
444 |
|
8783
9ae8c79c7708
(svn r11851) -Codechange: A few magic numbers removal, plus a little code style
belugas
parents:
8764
diff
changeset
|
445 |
if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break; |
7141
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
446 |
|
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
447 |
CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grffile); |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
448 |
if (cargo == CT_INVALID) continue; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
449 |
|
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
450 |
uint amt = GB(callback, 0, 8); |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
451 |
uint moved = MoveGoodsToStation(tile, 1, 1, cargo, amt); |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
452 |
|
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
453 |
const CargoSpec *cs = GetCargo(cargo); |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
454 |
switch (cs->town_effect) { |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
455 |
case TE_PASSENGERS: |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
456 |
t->new_max_pass += amt; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
457 |
t->new_act_pass += moved; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
458 |
break; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
459 |
|
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
460 |
case TE_MAIL: |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
461 |
t->new_max_mail += amt; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
462 |
t->new_act_mail += moved; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
463 |
break; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
464 |
|
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
465 |
default: |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
466 |
break; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
467 |
} |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
468 |
} |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
469 |
} else { |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
470 |
if (GB(r, 0, 8) < hs->population) { |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
471 |
uint amt = GB(r, 0, 8) / 8 + 1; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
472 |
uint moved; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
473 |
|
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
474 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
475 |
t->new_max_pass += amt; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
476 |
moved = MoveGoodsToStation(tile, 1, 1, CT_PASSENGERS, amt); |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
477 |
t->new_act_pass += moved; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
478 |
} |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
479 |
|
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
480 |
if (GB(r, 8, 8) < hs->mail_generation) { |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
481 |
uint amt = GB(r, 8, 8) / 8 + 1; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
482 |
uint moved; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
483 |
|
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
484 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
485 |
t->new_max_mail += amt; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
486 |
moved = MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt); |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
487 |
t->new_act_mail += moved; |
470199c6dda0
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
7138
diff
changeset
|
488 |
} |
0 | 489 |
} |
490 |
||
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
491 |
_current_player = OWNER_TOWN; |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
492 |
|
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
493 |
if (hs->building_flags & BUILDING_HAS_1_TILE && |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8399
diff
changeset
|
494 |
HasBit(t->flags12, TOWN_IS_FUNDED) && |
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
495 |
CanDeleteHouse(tile) && |
7101
ff1b42bfd622
(svn r9823) -Feature: Add support for house property 1F - minimum life span.
maedhros
parents:
7067
diff
changeset
|
496 |
max(_cur_year - GetHouseConstructionYear(tile), 0) >= hs->minimum_life && |
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
497 |
--t->time_until_rebuild == 0) { |
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
498 |
t->time_until_rebuild = GB(r, 16, 8) + 192; |
0 | 499 |
|
500 |
ClearTownHouse(t, tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
501 |
|
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
502 |
/* Rebuild with another house? */ |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
503 |
if (GB(r, 24, 8) >= 12) BuildTownHouse(t, tile); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
504 |
} |
314 | 505 |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
506 |
_current_player = OWNER_NONE; |
0 | 507 |
} |
508 |
||
7030
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
509 |
/** |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
510 |
* Unused handler |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
511 |
* @param tile unused |
09d75e8577d6
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
7021
diff
changeset
|
512 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
513 |
static void ClickTile_Town(TileIndex tile) |
0 | 514 |
{ |
515 |
/* not used */ |
|
516 |
} |
|
517 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7410
diff
changeset
|
518 |
static CommandCost ClearTile_Town(TileIndex tile, byte flags) |
0 | 519 |
{ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
520 |
int rating; |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8720
diff
changeset
|
521 |
CommandCost cost(EXPENSES_CONSTRUCTION); |
0 | 522 |
Town *t; |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
523 |
HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
0 | 524 |
|
525 |
if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
526 |
if (!CanDeleteHouse(tile)) return CMD_ERROR; |
0 | 527 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
528 |
cost.AddCost(_price.remove_house * hs->removal_cost >> 8); |
0 | 529 |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
530 |
rating = hs->remove_rating_decrease; |
0 | 531 |
_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
|
532 |
_cleared_town = t = GetTownByTile(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
533 |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
534 |
if (IsValidPlayer(_current_player)) { |
0 | 535 |
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
|
536 |
SetDParam(0, t->index); |
0 | 537 |
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
|
538 |
} |
0 | 539 |
} |
540 |
||
8728
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
541 |
ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM); |
0 | 542 |
if (flags & DC_EXEC) { |
543 |
ClearTownHouse(t, tile); |
|
544 |
} |
|
545 |
||
546 |
return cost; |
|
547 |
} |
|
548 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
549 |
static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac) |
0 | 550 |
{ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
551 |
HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
7021
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
552 |
CargoID accepts[3]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
553 |
|
7021
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
554 |
/* Set the initial accepted cargo types */ |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
555 |
for (uint8 i = 0; i < lengthof(accepts); i++) { |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
556 |
accepts[i] = hs->accepts_cargo[i]; |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
557 |
} |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
558 |
|
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
559 |
/* Check for custom accepted cargo types */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8399
diff
changeset
|
560 |
if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) { |
7138
feca3eff4054
(svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents:
7125
diff
changeset
|
561 |
uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
7021
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
562 |
if (callback != CALLBACK_FAILED) { |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
563 |
/* Replace accepted cargo types with translated values from callback */ |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
564 |
accepts[0] = GetCargoTranslation(GB(callback, 0, 5), hs->grffile); |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
565 |
accepts[1] = GetCargoTranslation(GB(callback, 5, 5), hs->grffile); |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
566 |
accepts[2] = GetCargoTranslation(GB(callback, 10, 5), hs->grffile); |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
567 |
} |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
568 |
} |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
569 |
|
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
570 |
/* Check for custom cargo acceptance */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8399
diff
changeset
|
571 |
if (HasBit(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) { |
7138
feca3eff4054
(svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents:
7125
diff
changeset
|
572 |
uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
7021
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
573 |
if (callback != CALLBACK_FAILED) { |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
574 |
if (accepts[0] != CT_INVALID) ac[accepts[0]] = GB(callback, 0, 4); |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
575 |
if (accepts[1] != CT_INVALID) ac[accepts[1]] = GB(callback, 4, 4); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8399
diff
changeset
|
576 |
if (_opt.landscape != LT_TEMPERATE && HasBit(callback, 12)) { |
7021
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
577 |
/* The 'S' bit indicates food instead of goods */ |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
578 |
ac[CT_FOOD] = GB(callback, 8, 4); |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
579 |
} else { |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
580 |
if (accepts[2] != CT_INVALID) ac[accepts[2]] = GB(callback, 8, 4); |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
581 |
} |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
582 |
return; |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
583 |
} |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
584 |
} |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
585 |
|
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
586 |
/* No custom acceptance, so fill in with the default values */ |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
587 |
for (uint8 i = 0; i < lengthof(accepts); i++) { |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
588 |
if (accepts[i] != CT_INVALID) ac[accepts[i]] = hs->cargo_acceptance[i]; |
1004d4b66546
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6987
diff
changeset
|
589 |
} |
0 | 590 |
} |
591 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
592 |
static void GetTileDesc_Town(TileIndex tile, TileDesc *td) |
0 | 593 |
{ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
594 |
td->str = GetHouseSpecs(GetHouseType(tile))->building_name; |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
595 |
if (!IsHouseCompleted(tile)) { |
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
596 |
SetDParamX(td->dparam, 0, td->str); |
0 | 597 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
598 |
} |
|
599 |
||
600 |
td->owner = OWNER_TOWN; |
|
601 |
} |
|
602 |
||
9112
ec6800eaa340
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents:
9092
diff
changeset
|
603 |
static TrackStatus GetTileTrackStatus_Town(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) |
0 | 604 |
{ |
605 |
/* not used */ |
|
606 |
return 0; |
|
607 |
} |
|
608 |
||
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
|
609 |
static void ChangeTileOwner_Town(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 610 |
{ |
611 |
/* not used */ |
|
612 |
} |
|
613 |
||
2817 | 614 |
static bool GrowTown(Town *t); |
615 |
||
0 | 616 |
static void TownTickHandler(Town *t) |
617 |
{ |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8399
diff
changeset
|
618 |
if (HasBit(t->flags12, TOWN_IS_FUNDED)) { |
0 | 619 |
int i = t->grow_counter - 1; |
620 |
if (i < 0) { |
|
621 |
if (GrowTown(t)) { |
|
622 |
i = t->growth_rate; |
|
623 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
624 |
i = 0; |
0 | 625 |
} |
626 |
} |
|
627 |
t->grow_counter = i; |
|
628 |
} |
|
629 |
||
630 |
UpdateTownRadius(t); |
|
631 |
} |
|
632 |
||
6573 | 633 |
void OnTick_Town() |
0 | 634 |
{ |
2639 | 635 |
if (_game_mode == GM_EDITOR) return; |
0 | 636 |
|
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
|
637 |
/* 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
|
638 |
* 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
|
639 |
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
|
640 |
_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
|
641 |
_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
|
642 |
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
|
643 |
|
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
|
644 |
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
|
645 |
_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
|
646 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
647 |
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
|
648 |
} |
0 | 649 |
} |
650 |
||
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
651 |
/** |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
652 |
* Return the RoadBits of a tile |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
653 |
* |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
654 |
* @note There are many other functions doing things like that. |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
655 |
* @note Needs to be checked for needlessness. |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
656 |
* @param tile The tile we want to analyse |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
657 |
* @return The roadbits of the given tile |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
658 |
*/ |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
659 |
static RoadBits GetTownRoadBits(TileIndex tile) |
0 | 660 |
{ |
7157
270bc5b64e08
(svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents:
7141
diff
changeset
|
661 |
TrackBits b = GetAnyRoadTrackBits(tile, ROADTYPE_ROAD); |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
662 |
RoadBits r = ROAD_NONE; |
2639 | 663 |
|
7721
7286fe1fedef
(svn r10504) -Codechange: Shorten the test if no track bit has been found
belugas
parents:
7711
diff
changeset
|
664 |
if (b == TRACK_BIT_NONE) return r; |
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
|
665 |
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
|
666 |
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
|
667 |
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
|
668 |
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
|
669 |
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
|
670 |
if (b & TRACK_BIT_RIGHT) r |= ROAD_NE | ROAD_SE; |
0 | 671 |
return r; |
672 |
} |
|
673 |
||
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
674 |
/** |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
675 |
* Check if a neighboring tile has a road |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
676 |
* |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
677 |
* @param tile curent tile |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
678 |
* @param dir target direction |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
679 |
* @param dist_multi distance multiplyer |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
680 |
* @return true if one of the neighboring tiles at the |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
681 |
* given distance is a road tile else false |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
682 |
*/ |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
683 |
static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dist_multi) |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
684 |
{ |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
685 |
/* Lookup table for the used diff values */ |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
686 |
const TileIndexDiff tid_lt[3] = { |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
687 |
TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT)), |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
688 |
TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT)), |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
689 |
TileOffsByDiagDir(ReverseDiagDir(dir)), |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
690 |
}; |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
691 |
|
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
692 |
/* We add 1 to the distance because we want to get 1 for |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
693 |
* the min distance multiplyer and not 0. |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
694 |
* Therefore we start at 4. The 4 is used because |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
695 |
* there are 4 tiles per distance step to check. */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
696 |
dist_multi = (dist_multi + 1) * 4; |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
697 |
for (uint pos = 4; pos < dist_multi; pos++) { |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
698 |
TileIndexDiff cur = 0; |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
699 |
/* For each even value of pos add the right TileIndexDiff |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
700 |
* for each uneven value the left TileIndexDiff |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
701 |
* for each with 2nd bit set (2,3,6,7,..) add the reversed TileIndexDiff */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
702 |
cur += tid_lt[(pos & 1) ? 0 : 1]; |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
703 |
if (pos & 2) cur += tid_lt[2]; |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
704 |
|
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
705 |
cur = (uint)(pos / 4) * cur; // Multiply for the fitting distance |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
706 |
if (GetTownRoadBits(TILE_ADD(tile, cur)) & DiagDirToRoadBits((pos & 2) ? dir : ReverseDiagDir(dir))) return true; |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
707 |
} |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
708 |
return false; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
709 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
710 |
|
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
711 |
/** |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
712 |
* Check if a Road is allowed on a given tile |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
713 |
* |
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
714 |
* @param t The current town |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
715 |
* @param tile The target tile |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
716 |
* @param dir The direction in which we want to extend the town |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
717 |
* @return true if it is allowed else false |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
718 |
*/ |
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
719 |
static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir) |
0 | 720 |
{ |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
721 |
if (TileX(tile) < 2 || TileX(tile) >= MapMaxX() || TileY(tile) < 2 || TileY(tile) >= MapMaxY()) return false; |
7489
0f25d9e299d0
(svn r10249) -Fix [FS#906]: town tried to gather information about the neighbourhood of a tile when it couldn't even *ever* build on that tile.
rubidium
parents:
7452
diff
changeset
|
722 |
|
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
723 |
Slope cur_slope, desired_slope; |
0 | 724 |
|
2639 | 725 |
for (;;) { |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
726 |
/* Check if there already is a road at this point? */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
727 |
if (GetTownRoadBits(tile) == ROAD_NONE) { |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
728 |
/* No, try if we are able to build a road piece there. |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
729 |
* If that fails clear the land, and if that fails exit. |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
730 |
* This is to make sure that we can build a road here later. */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
731 |
if (CmdFailed(DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) && |
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
|
732 |
CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) |
0 | 733 |
return false; |
734 |
} |
|
735 |
||
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
736 |
cur_slope = GetTileSlope(tile, NULL); |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
737 |
if (cur_slope == SLOPE_FLAT) { |
465
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
738 |
no_slope: |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
739 |
/* Tile has no slope */ |
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
740 |
switch (t->GetActiveLayout()) { |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
741 |
default: NOT_REACHED(); |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
742 |
|
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
743 |
case TL_ORIGINAL: // Disallow the road if any neighboring tile has a road (distance: 1) |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
744 |
return !IsNeighborRoadTile(tile, dir, 1); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
745 |
|
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
746 |
case TL_BETTER_ROADS: // Disallow the road if any neighboring tile has a road (distance: 1 and 2). |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
747 |
return !IsNeighborRoadTile(tile, dir, 2); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
748 |
} |
0 | 749 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
750 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
751 |
/* If the tile is not a slope in the right direction, then |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
752 |
* maybe terraform some. */ |
8381
895c66491749
(svn r11436) -Fix [FS#1439]: Towns would not build roads on slopes. Patch by divide.
rubidium
parents:
8376
diff
changeset
|
753 |
desired_slope = (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? SLOPE_NW : SLOPE_NE; |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
754 |
if (desired_slope != cur_slope && ComplementSlope(desired_slope) != cur_slope) { |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8427
diff
changeset
|
755 |
if (Chance16(1, 8)) { |
8262
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
756 |
CommandCost res = CMD_ERROR; |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8427
diff
changeset
|
757 |
if (!_generating_world && Chance16(1, 10)) { |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
758 |
/* Note: Do not replace "^ SLOPE_ELEVATED" with ComplementSlope(). The slope might be steep. */ |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
759 |
res = DoCommand(tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0, |
8262
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
760 |
DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
2639 | 761 |
} |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8427
diff
changeset
|
762 |
if (CmdFailed(res) && Chance16(1, 3)) { |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
763 |
/* We can consider building on the slope, though. */ |
465
64f0772071fb
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
764 |
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
|
765 |
} |
0 | 766 |
} |
767 |
return false; |
|
768 |
} |
|
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
769 |
return true; |
0 | 770 |
} |
771 |
} |
|
772 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
773 |
static bool TerraformTownTile(TileIndex tile, int edges, int dir) |
0 | 774 |
{ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7410
diff
changeset
|
775 |
CommandCost r; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
776 |
|
0 | 777 |
TILE_ASSERT(tile); |
778 |
||
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
|
779 |
r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
780 |
if (CmdFailed(r) || r.GetCost() >= 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
|
781 |
DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND); |
0 | 782 |
return true; |
783 |
} |
|
784 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
785 |
static void LevelTownLand(TileIndex tile) |
0 | 786 |
{ |
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
787 |
Slope tileh; |
0 | 788 |
|
789 |
TILE_ASSERT(tile); |
|
790 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
791 |
/* 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
|
792 |
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
|
793 |
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
|
794 |
if (tileh == SLOPE_FLAT) return; |
0 | 795 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
796 |
/* First try up, then down */ |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
797 |
if (!TerraformTownTile(tile, ~tileh & SLOPE_ELEVATED, 1)) { |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
798 |
TerraformTownTile(tile, tileh & SLOPE_ELEVATED, 0); |
0 | 799 |
} |
800 |
} |
|
801 |
||
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
802 |
/** |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
803 |
* Generate the RoadBits of a grid tile |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
804 |
* |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
805 |
* @param t current town |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
806 |
* @param tile tile in reference to the town |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
807 |
* @param dir The direction to which we are growing ATM |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
808 |
* @return the RoadBit of the current tile regarding |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
809 |
* the selected town layout |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
810 |
*/ |
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
811 |
static RoadBits GetTownRoadGridElement(Town *t, TileIndex tile, DiagDirection dir) |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
812 |
{ |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
813 |
/* align the grid to the downtown */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
814 |
TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile); // Vector from downtown to the tile |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
815 |
RoadBits rcmd = ROAD_NONE; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
816 |
|
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
817 |
switch (t->GetActiveLayout()) { |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
818 |
default: NOT_REACHED(); |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
819 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
820 |
case TL_2X2_GRID: |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
821 |
if ((grid_pos.x % 3) == 0) rcmd |= ROAD_Y; |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
822 |
if ((grid_pos.y % 3) == 0) rcmd |= ROAD_X; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
823 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
824 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
825 |
case TL_3X3_GRID: |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
826 |
if ((grid_pos.x % 4) == 0) rcmd |= ROAD_Y; |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
827 |
if ((grid_pos.y % 4) == 0) rcmd |= ROAD_X; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
828 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
829 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
830 |
|
8099
fab936821b10
(svn r11130) -Fix [FS#1207]: towns build roads that weren't connected to any other road.
rubidium
parents:
8078
diff
changeset
|
831 |
/* Optimise only X-junctions */ |
8262
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
832 |
if (rcmd != ROAD_ALL) return rcmd; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
833 |
|
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
834 |
RoadBits rb_template; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
835 |
|
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
836 |
switch (GetTileSlope(tile, NULL)) { |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
837 |
default: rb_template = ROAD_ALL; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
838 |
case SLOPE_W: rb_template = ROAD_NW | ROAD_SW; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
839 |
case SLOPE_SW: rb_template = ROAD_Y | ROAD_SW; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
840 |
case SLOPE_S: rb_template = ROAD_SW | ROAD_SE; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
841 |
case SLOPE_SE: rb_template = ROAD_X | ROAD_SE; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
842 |
case SLOPE_E: rb_template = ROAD_SE | ROAD_NE; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
843 |
case SLOPE_NE: rb_template = ROAD_Y | ROAD_NE; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
844 |
case SLOPE_N: rb_template = ROAD_NE | ROAD_NW; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
845 |
case SLOPE_NW: rb_template = ROAD_X | ROAD_NW; break; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
846 |
case SLOPE_STEEP_W: |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
847 |
case SLOPE_STEEP_S: |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
848 |
case SLOPE_STEEP_E: |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
849 |
case SLOPE_STEEP_N: |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
850 |
rb_template = ROAD_NONE; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
851 |
break; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
852 |
} |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
853 |
|
8262
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
854 |
/* Stop if the template is compatible to the growth dir */ |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
855 |
if (DiagDirToRoadBits(ReverseDiagDir(dir)) & rb_template) return rb_template; |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
856 |
/* If not generate a straight road in the direction of the growth */ |
b3865f8f7aba
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
8258
diff
changeset
|
857 |
return DiagDirToRoadBits(dir) | DiagDirToRoadBits(ReverseDiagDir(dir)); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
858 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
859 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
860 |
/** |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
861 |
* Grows the town with an extra house. |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
862 |
* Check if there are enough neighbor house tiles |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
863 |
* next to the current tile. If there are enough |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
864 |
* add another house. |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
865 |
* |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
866 |
* @param t The current town |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
867 |
* @param tile The target tile for the extra house |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
868 |
* @return true if an extra house has been added |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
869 |
*/ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
870 |
static bool GrowTownWithExtraHouse(Town *t, TileIndex tile) |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
871 |
{ |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
872 |
/* We can't look further than that. */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
873 |
if (TileX(tile) < 2 || TileY(tile) < 2 || MapMaxX() <= TileX(tile) || MapMaxY() <= TileY(tile)) return false; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
874 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
875 |
uint counter = 0; // counts the house neighbor tiles |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
876 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
877 |
/* Check the tiles E,N,W and S of the current tile for houses */ |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
878 |
for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
879 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
880 |
if (IsTileType(TileAddByDiagDir(tile, dir), MP_HOUSE)) counter++; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
881 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
882 |
/* If there are enough neighbors stop here */ |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
883 |
if (counter >= 3) { |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
884 |
if (BuildTownHouse(t, tile)) { |
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
885 |
_grow_town_result = GROWTH_SUCCEED; |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
886 |
return true; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
887 |
} |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
888 |
return false; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
889 |
} |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
890 |
} |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
891 |
return false; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
892 |
} |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
893 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
894 |
/** |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
895 |
* Grows the town with a road piece. |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
896 |
* |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
897 |
* @param t The current town |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
898 |
* @param tile The current tile |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
899 |
* @param rcmd The RoadBits we want to build on the tile |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
900 |
* @return true if the RoadBits have been added else false |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
901 |
*/ |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
902 |
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd) |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
903 |
{ |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
904 |
if (CmdSucceeded(DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) { |
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
905 |
_grow_town_result = GROWTH_SUCCEED; |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
906 |
return true; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
907 |
} |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
908 |
return false; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
909 |
} |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
910 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
911 |
/** |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
912 |
* Grows the town with a bridge. |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
913 |
* At first we check if a bridge is reasonable. |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
914 |
* If so we check if we are able to build it. |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
915 |
* |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
916 |
* @param t The current town |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
917 |
* @param tile The current tile |
8341
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
918 |
* @param bridge_dir The valid direction in which to grow a bridge |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
919 |
* @return true if a bridge has been build else false |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
920 |
*/ |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
921 |
static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDirection bridge_dir) |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
922 |
{ |
8341
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
923 |
assert(bridge_dir < DIAGDIR_END); |
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
924 |
|
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
925 |
const Slope slope = GetTileSlope(tile, NULL); |
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
926 |
if (slope == SLOPE_FLAT) return false; // no slope, no bridge |
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
927 |
|
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
928 |
/* Make sure the direction is compatible with the slope. |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
929 |
* Well we check if the slope has an up bit set in the |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
930 |
* reverse direction. */ |
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
931 |
if (HASBITS(slope, InclinedSlope(bridge_dir))) return false; |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
932 |
|
8343
471bee030391
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
8341
diff
changeset
|
933 |
/* Assure that the bridge is connectable to the start side */ |
471bee030391
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
8341
diff
changeset
|
934 |
if (!(GetTownRoadBits(TileAddByDiagDir(tile, ReverseDiagDir(bridge_dir))) & DiagDirToRoadBits(bridge_dir))) return false; |
471bee030391
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
8341
diff
changeset
|
935 |
|
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
936 |
/* We are in the right direction */ |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
937 |
uint8 bridge_length = 0; // This value stores the length of the possible bridge |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
938 |
TileIndex bridge_tile = tile; // Used to store the other waterside |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
939 |
|
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
940 |
const int delta = TileOffsByDiagDir(bridge_dir); |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
941 |
do { |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
942 |
if (bridge_length++ >= 11) { |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
943 |
/* Max 11 tile long bridges */ |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
944 |
return false; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
945 |
} |
8367
40eba45653e2
(svn r11421) -Fix [FS#1431]: do not use a function that asserts when wrapping around the map's edge when you use the wrapping (and MP_VOID tiles) to determine whether the bridge can be build.
rubidium
parents:
8345
diff
changeset
|
946 |
bridge_tile += delta; |
8947
3b7bb9f2770c
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13
parents:
8855
diff
changeset
|
947 |
} while (TileX(bridge_tile) != 0 && TileY(bridge_tile) != 0 && IsWaterTile(bridge_tile)); |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
948 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
949 |
/* no water tiles in between? */ |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
950 |
if (bridge_length == 1) return false; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
951 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
952 |
for (uint8 times = 0; times <= 22; times++) { |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
953 |
byte bridge_type = RandomRange(MAX_BRIDGES - 1); |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
954 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
955 |
/* Can we actually build the bridge? */ |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
956 |
if (CmdSucceeded(DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE))) { |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
957 |
DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE); |
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
958 |
_grow_town_result = GROWTH_SUCCEED; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
959 |
return true; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
960 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
961 |
} |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
962 |
/* Quit if it selecting an appropiate bridge type fails a large number of times. */ |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
963 |
return false; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
964 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
965 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
966 |
/** |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
967 |
* Grows the given town. |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
968 |
* There are at the moment 3 possible way's for |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
969 |
* the town expansion: |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
970 |
* @li Generate a random tile and check if there is a road allowed |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
971 |
* @li TL_ORIGINAL |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
972 |
* @li TL_BETTER_ROADS |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
973 |
* @li Check if the town geometry allows a road and which one |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
974 |
* @li TL_2X2_GRID |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
975 |
* @li TL_3X3_GRID |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
976 |
* @li Forbid roads, only build houses |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
977 |
* @li TL_NO_ROADS |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
978 |
* |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
979 |
* @param tile_ptr The current tile |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
980 |
* @param cur_rb The current tiles RoadBits |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
981 |
* @param target_dir The target road dir |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
982 |
* @param t1 The current town |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
983 |
*/ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
984 |
static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1) |
0 | 985 |
{ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
986 |
RoadBits rcmd = ROAD_NONE; // RoadBits for the road construction command |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
987 |
TileIndex tile = *tile_ptr; // The main tile on which we base our growth |
0 | 988 |
|
989 |
TILE_ASSERT(tile); |
|
990 |
||
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
991 |
if (cur_rb == ROAD_NONE) { |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
992 |
/* Tile has no road. First reset the status counter |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
993 |
* to say that this is the last iteration. */ |
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
994 |
_grow_town_result = GROWTH_SEARCH_STOPPED; |
0 | 995 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
996 |
/* Remove hills etc */ |
0 | 997 |
LevelTownLand(tile); |
998 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
999 |
/* Is a road allowed here? */ |
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1000 |
switch (t1->GetActiveLayout()) { |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1001 |
default: NOT_REACHED(); |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1002 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1003 |
case TL_NO_ROADS: /* Disallow Roads */ |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1004 |
return; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1005 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1006 |
case TL_3X3_GRID: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1007 |
case TL_2X2_GRID: |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1008 |
rcmd = GetTownRoadGridElement(t1, tile, target_dir); |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1009 |
if (rcmd == ROAD_NONE) return; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1010 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1011 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1012 |
case TL_BETTER_ROADS: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1013 |
case TL_ORIGINAL: |
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1014 |
if (!IsRoadAllowedHere(t1, tile, target_dir)) return; |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1015 |
|
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1016 |
DiagDirection source_dir = ReverseDiagDir(target_dir); |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1017 |
|
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8427
diff
changeset
|
1018 |
if (Chance16(1, 4)) { |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1019 |
/* Randomize a new target dir */ |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1020 |
do target_dir = RandomDiagDir(); while (target_dir == source_dir); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1021 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1022 |
|
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1023 |
if (!IsRoadAllowedHere(t1, TileAddByDiagDir(tile, target_dir), target_dir)) { |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1024 |
/* A road is not allowed to continue the randomized road, |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1025 |
* return if the road we're trying to build is curved. */ |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1026 |
if (target_dir != ReverseDiagDir(source_dir)) return; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1027 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1028 |
/* Return if neither side of the new road is a house */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1029 |
if (!IsTileType(TileAddByDiagDir(tile, ChangeDiagDir(target_dir, DIAGDIRDIFF_90RIGHT)), MP_HOUSE) && |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1030 |
!IsTileType(TileAddByDiagDir(tile, ChangeDiagDir(target_dir, DIAGDIRDIFF_90LEFT)), MP_HOUSE)) { |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1031 |
return; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1032 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1033 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1034 |
/* That means that the road is only allowed if there is a house |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1035 |
* at any side of the new road. */ |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1036 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1037 |
|
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1038 |
rcmd = DiagDirToRoadBits(target_dir) | DiagDirToRoadBits(source_dir); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1039 |
break; |
2637
8807e6a63f89
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
1040 |
} |
0 | 1041 |
|
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1042 |
} else if (target_dir < DIAGDIR_END && !(cur_rb & DiagDirToRoadBits(ReverseDiagDir(target_dir)))) { |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1043 |
/* Continue building on a partial road. |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1044 |
* Should be allways OK, so we only generate |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1045 |
* the fitting RoadBits */ |
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
1046 |
_grow_town_result = GROWTH_SEARCH_STOPPED; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1047 |
|
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1048 |
switch (t1->GetActiveLayout()) { |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1049 |
default: NOT_REACHED(); |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1050 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1051 |
case TL_NO_ROADS: /* Disallow Roads */ |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1052 |
return; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1053 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1054 |
case TL_3X3_GRID: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1055 |
case TL_2X2_GRID: |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1056 |
rcmd = GetTownRoadGridElement(t1, tile, target_dir); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1057 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1058 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1059 |
case TL_BETTER_ROADS: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1060 |
case TL_ORIGINAL: |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1061 |
rcmd = DiagDirToRoadBits(ReverseDiagDir(target_dir)); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1062 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1063 |
} |
0 | 1064 |
} else { |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1065 |
bool allow_house = false; // Value which decides if we want to construct a house |
0 | 1066 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1067 |
/* Reached a tunnel/bridge? Then continue at the other side of it. */ |
5696
4d40b22a9a96
(svn r7698) -Fix (r7573): towns did not grow beyond bridges.
rubidium
parents:
5573
diff
changeset
|
1068 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
8584
a8b6dffead63
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents:
8579
diff
changeset
|
1069 |
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) { |
8693
3d721429cc4f
(svn r11760) -Codechange: unify the way how other end of a tunnel/bridge is determined at some places
smatz
parents:
8683
diff
changeset
|
1070 |
*tile_ptr = GetOtherTunnelBridgeEnd(tile); |
5696
4d40b22a9a96
(svn r7698) -Fix (r7573): towns did not grow beyond bridges.
rubidium
parents:
5573
diff
changeset
|
1071 |
} |
0 | 1072 |
return; |
1073 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1074 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1075 |
/* Possibly extend the road in a direction. |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1076 |
* Randomize a direction and if it has a road, bail out. */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1077 |
target_dir = RandomDiagDir(); |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1078 |
if (cur_rb & DiagDirToRoadBits(target_dir)) return; |
0 | 1079 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1080 |
/* This is the tile we will reach if we extend to this direction. */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1081 |
TileIndex house_tile = TileAddByDiagDir(tile, target_dir); // position of a possible house |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1082 |
|
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1083 |
/* Don't walk into water. */ |
8235
fc75e5ad02b6
(svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents:
8205
diff
changeset
|
1084 |
if (IsWaterTile(house_tile)) return; |
0 | 1085 |
|
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1086 |
switch (t1->GetActiveLayout()) { |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1087 |
default: NOT_REACHED(); |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1088 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1089 |
case TL_NO_ROADS: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1090 |
allow_house = true; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1091 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1092 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1093 |
case TL_3X3_GRID: /* Use 2x2 grid afterwards! */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1094 |
GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir)); |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1095 |
/* FALL THROUGH */ |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1096 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1097 |
case TL_2X2_GRID: |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1098 |
rcmd = GetTownRoadGridElement(t1, house_tile, target_dir); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1099 |
allow_house = (rcmd == ROAD_NONE); |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1100 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1101 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1102 |
case TL_BETTER_ROADS: /* Use original afterwards! */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1103 |
GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir)); |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1104 |
/* FALL THROUGH */ |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1105 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1106 |
case TL_ORIGINAL: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1107 |
/* Allow a house at the edge. 60% chance or |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1108 |
* always ok if no road allowed. */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1109 |
rcmd = DiagDirToRoadBits(target_dir); |
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1110 |
allow_house = (!IsRoadAllowedHere(t1, house_tile, target_dir) || Chance16(6, 10)); |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1111 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1112 |
} |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1113 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1114 |
if (allow_house) { |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1115 |
/* Build a house, but not if there already is a house there. */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1116 |
if (!IsTileType(house_tile, MP_HOUSE)) { |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1117 |
/* Level the land if possible */ |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8427
diff
changeset
|
1118 |
if (Chance16(1, 6)) LevelTownLand(house_tile); |
0 | 1119 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1120 |
/* And build a house. |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1121 |
* Set result to -1 if we managed to build it. */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1122 |
if (BuildTownHouse(t1, house_tile)) { |
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
1123 |
_grow_town_result = GROWTH_SUCCEED; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1124 |
} |
0 | 1125 |
} |
1126 |
return; |
|
1127 |
} |
|
1128 |
||
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
1129 |
_grow_town_result = GROWTH_SEARCH_STOPPED; |
0 | 1130 |
} |
1131 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1132 |
/* Return if a water tile */ |
8235
fc75e5ad02b6
(svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents:
8205
diff
changeset
|
1133 |
if (IsWaterTile(tile)) return; |
0 | 1134 |
|
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1135 |
/* Make the roads look nicer */ |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1136 |
rcmd = CleanUpRoadBits(tile, rcmd); |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1137 |
if (rcmd == ROAD_NONE) return; |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1138 |
|
8341
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
1139 |
/* Only use the target direction for bridges to ensure they're connected. |
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
1140 |
* The target_dir is as computed previously according to town layout, so |
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
1141 |
* it will match it perfectly. */ |
a7fef35fe38b
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
8262
diff
changeset
|
1142 |
if (GrowTownWithBridge(t1, tile, target_dir)) return; |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1143 |
|
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1144 |
GrowTownWithRoad(t1, tile, rcmd); |
0 | 1145 |
} |
1146 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1147 |
/** Returns "growth" if a house was built, or no if the build failed. |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1148 |
* @param t town to inquiry |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1149 |
* @param tile to inquiry |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1150 |
* @return something other than zero(0)if town expansion was possible |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1151 |
*/ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1152 |
static int GrowTownAtRoad(Town *t, TileIndex tile) |
0 | 1153 |
{ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1154 |
/* Special case. |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1155 |
* @see GrowTownInTile Check the else if |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1156 |
*/ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1157 |
DiagDirection target_dir = DIAGDIR_END; // The direction in which we want to extend the town |
0 | 1158 |
|
1159 |
TILE_ASSERT(tile); |
|
1160 |
||
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1161 |
/* Number of times to search. |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1162 |
* Better roads, 2X2 and 3X3 grid grow quite fast so we give |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1163 |
* them a little handicap. */ |
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1164 |
switch (t->GetActiveLayout()) { |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1165 |
case TL_BETTER_ROADS: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1166 |
_grow_town_result = 10 + t->num_houses * 2 / 9; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1167 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1168 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1169 |
case TL_3X3_GRID: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1170 |
case TL_2X2_GRID: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1171 |
_grow_town_result = 10 + t->num_houses * 1 / 9; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1172 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1173 |
|
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1174 |
default: |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1175 |
_grow_town_result = 10 + t->num_houses * 4 / 9; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1176 |
break; |
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1177 |
} |
0 | 1178 |
|
1179 |
do { |
|
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1180 |
RoadBits cur_rb = GetTownRoadBits(tile); // The RoadBits of the current tile |
0 | 1181 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1182 |
/* Try to grow the town from this point */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1183 |
GrowTownInTile(&tile, cur_rb, target_dir, t); |
0 | 1184 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1185 |
/* Exclude the source position from the bitmask |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1186 |
* and return if no more road blocks available */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1187 |
cur_rb &= ~DiagDirToRoadBits(ReverseDiagDir(target_dir)); |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1188 |
if (cur_rb == ROAD_NONE) |
0 | 1189 |
return _grow_town_result; |
1190 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1191 |
/* Select a random bit from the blockmask, walk a step |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1192 |
* and continue the search from there. */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1193 |
do target_dir = RandomDiagDir(); while (!(cur_rb & DiagDirToRoadBits(target_dir))); |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1194 |
tile = TileAddByDiagDir(tile, target_dir); |
0 | 1195 |
|
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7831
diff
changeset
|
1196 |
if (IsTileType(tile, MP_ROAD)) { |
1327
f98ba72197f5
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
1197 |
/* 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
|
1198 |
if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t) { |
8180
a790d5cf76ce
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
8162
diff
changeset
|
1199 |
_grow_town_result = GROWTH_SUCCEED; |
8957
ed06a4be28b9
(svn r12031) -Fix [FS#1689,FS#1719]: Prevent towns from removing or claiming ownership of player owned tiles when growing.
peter1138
parents:
8947
diff
changeset
|
1200 |
} else if (IsTileOwner(tile, OWNER_NONE) && _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
|
1201 |
/* 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
|
1202 |
* owner :) (happy happy happy road now) */ |
1902 | 1203 |
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
|
1204 |
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
|
1205 |
} |
f98ba72197f5
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
1206 |
} |
1280
b6925875de49
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
1207 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1208 |
/* Max number of times is checked. */ |
0 | 1209 |
} while (--_grow_town_result >= 0); |
1210 |
||
1211 |
return (_grow_town_result == -2); |
|
1212 |
} |
|
1213 |
||
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1214 |
/** |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1215 |
* Generate a random road block. |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1216 |
* The probability of a straight road |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1217 |
* is somewhat higher than a curved. |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1218 |
* |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1219 |
* @return A RoadBits value with 2 bits set |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1220 |
*/ |
6573 | 1221 |
static RoadBits GenRandomRoadBits() |
0 | 1222 |
{ |
1223 |
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
|
1224 |
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
|
1225 |
uint b = GB(r, 8, 2); |
0 | 1226 |
if (a == b) b ^= 2; |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1227 |
return (RoadBits)((ROAD_NW << a) + (ROAD_NW << b)); |
0 | 1228 |
} |
1229 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1230 |
/** Grow the town |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1231 |
* @Return true if a house was built, or no if the build failed. */ |
2817 | 1232 |
static bool GrowTown(Town *t) |
0 | 1233 |
{ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1234 |
|
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1235 |
/* Let the town be a ghost town |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1236 |
* The player wanted it in such a way. Thus there he has it. ;) |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1237 |
* Never reached in editor mode. */ |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1238 |
if (_patches.town_layout == TL_NO_ROADS && _generating_world) { |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1239 |
return false; |
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1240 |
} |
0 | 1241 |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1242 |
static const TileIndexDiffC _town_coord_mod[] = { |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1243 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1244 |
{ 1, 1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1245 |
{ 1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1246 |
{-1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1247 |
{-1, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1248 |
{ 0, 2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1249 |
{ 2, 0}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1250 |
{ 0, -2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1251 |
{-1, -1}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1252 |
{-2, 2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1253 |
{ 2, 2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1254 |
{ 2, -2}, |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1255 |
{ 0, 0} |
0 | 1256 |
}; |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1257 |
const TileIndexDiffC *ptr; |
7067
ea55b6046015
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
7056
diff
changeset
|
1258 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1259 |
/* Current player is a town */ |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1260 |
PlayerID old_player = _current_player; |
0 | 1261 |
_current_player = OWNER_TOWN; |
1262 |
||
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
1263 |
TileIndex tile = t->xy; // The tile we are working with ATM |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1264 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1265 |
/* Find a road that we can base the construction on. */ |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1266 |
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
8062
9eb6efa04d44
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
8045
diff
changeset
|
1267 |
if (GetTownRoadBits(tile) != ROAD_NONE) { |
260
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
1268 |
int r = GrowTownAtRoad(t, tile); |
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
1269 |
_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
|
1270 |
return r != 0; |
0 | 1271 |
} |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1272 |
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1273 |
} |
0 | 1274 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1275 |
/* No road available, try to build a random road block by |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1276 |
* clearing some land and then building a road there. */ |
0 | 1277 |
tile = t->xy; |
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1278 |
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
|
1279 |
/* 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
|
1280 |
if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) { |
7442
a4f7989f27d4
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
7439
diff
changeset
|
1281 |
if (CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) { |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1282 |
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
|
1283 |
_current_player = old_player; |
0 | 1284 |
return true; |
1285 |
} |
|
1286 |
} |
|
909
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1287 |
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
81bc9ef93f50
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1288 |
} |
0 | 1289 |
|
260
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
1290 |
_current_player = old_player; |
0 | 1291 |
return false; |
1292 |
} |
|
1293 |
||
9203
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
1294 |
void UpdateTownRadius(Town *t) |
0 | 1295 |
{ |
1296 |
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
|
1297 |
{ 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
|
1298 |
{ 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
|
1299 |
{ 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
|
1300 |
{ 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
|
1301 |
{ 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
|
1302 |
{ 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
|
1303 |
{ 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
|
1304 |
{ 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
|
1305 |
{ 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
|
1306 |
{ 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
|
1307 |
{ 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
|
1308 |
{ 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
|
1309 |
{ 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
|
1310 |
{ 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
|
1311 |
{ 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
|
1312 |
{ 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
|
1313 |
{ 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
|
1314 |
{ 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
|
1315 |
{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
|
1316 |
{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
|
1317 |
{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
|
1318 |
{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
|
1319 |
{121, 81, 0, 49, 36}, // 88 |
0 | 1320 |
}; |
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
|
1321 |
|
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
|
1322 |
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
|
1323 |
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
|
1324 |
} 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
|
1325 |
int mass = t->num_houses / 8; |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1326 |
/* At least very roughly extrapolate. Empirical numbers dancing between |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1327 |
* overwhelming by cottages and skyscrapers outskirts. */ |
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
|
1328 |
t->radius[0] = mass * mass; |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1329 |
/* Actually we are proportional to sqrt() but that's right because |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1330 |
* we are covering an area. */ |
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
|
1331 |
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
|
1332 |
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
|
1333 |
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
|
1334 |
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
|
1335 |
//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
|
1336 |
} |
0 | 1337 |
} |
1338 |
||
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
|
1339 |
static bool CreateTownName(uint32 *townnameparts) |
0 | 1340 |
{ |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1341 |
extern int _nb_orig_names; |
0 | 1342 |
Town *t2; |
1343 |
char buf1[64]; |
|
1344 |
char buf2[64]; |
|
1345 |
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
|
1346 |
/* 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
|
1347 |
* 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
|
1348 |
* 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
|
1349 |
* 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
|
1350 |
* 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
|
1351 |
int tries = 1000; |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1352 |
bool grf = (_opt.town_name >= _nb_orig_names); |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1353 |
uint32 grfid = grf ? GetGRFTownNameId(_opt.town_name - _nb_orig_names) : 0; |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1354 |
uint16 townnametype = grf ? GetGRFTownNameType(_opt.town_name - _nb_orig_names) : SPECSTR_TOWNNAME_START + _opt.town_name; |
0 | 1355 |
|
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
|
1356 |
assert(townnameparts); |
0 | 1357 |
|
2952 | 1358 |
for (;;) { |
0 | 1359 |
restart: |
1360 |
r = Random(); |
|
1361 |
||
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1362 |
SetDParam(0, r); |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1363 |
if (grf && grfid != 0) { |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1364 |
GRFTownNameGenerate(buf1, grfid, townnametype, r, lastof(buf1)); |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1365 |
} else { |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1366 |
GetString(buf1, townnametype, lastof(buf1)); |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1367 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1368 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1369 |
/* Check size and width */ |
4609
6c337b3fbf4b
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4559
diff
changeset
|
1370 |
if (strlen(buf1) >= 31 || GetStringBoundingBox(buf1).width > 130) continue; |
0 | 1371 |
|
1372 |
FOR_ALL_TOWNS(t2) { |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1373 |
/* We can't just compare the numbers since |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1374 |
* several numbers may map to a single name. */ |
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1375 |
SetDParam(0, t2->index); |
4912
d04b3f2bca70
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4850
diff
changeset
|
1376 |
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
|
1377 |
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
|
1378 |
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
|
1379 |
goto restart; |
0 | 1380 |
} |
1381 |
} |
|
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
|
1382 |
*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
|
1383 |
return true; |
0 | 1384 |
} |
1385 |
} |
|
1386 |
||
1377
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1387 |
void UpdateTownMaxPass(Town *t) |
0 | 1388 |
{ |
1389 |
t->max_pass = t->population >> 3; |
|
1390 |
t->max_mail = t->population >> 4; |
|
1391 |
} |
|
1392 |
||
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1393 |
/** |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1394 |
* Does the actual town creation. |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1395 |
* |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1396 |
* @param t The town |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1397 |
* @param tile Where to put it |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1398 |
* @param townnameparts The town name |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1399 |
* @param size_mode How the size should be determined |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1400 |
* @param size Parameter for size determination |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1401 |
*/ |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1402 |
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSizeMode size_mode, uint size) |
0 | 1403 |
{ |
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1404 |
extern int _nb_orig_names; |
0 | 1405 |
int x, i; |
1406 |
||
1407 |
t->xy = tile; |
|
1408 |
t->num_houses = 0; |
|
1409 |
t->time_until_rebuild = 10; |
|
1410 |
UpdateTownRadius(t); |
|
1411 |
t->flags12 = 0; |
|
1412 |
t->population = 0; |
|
1413 |
t->grow_counter = 0; |
|
1414 |
t->growth_rate = 250; |
|
1415 |
t->new_max_pass = 0; |
|
1416 |
t->new_max_mail = 0; |
|
1417 |
t->new_act_pass = 0; |
|
1418 |
t->new_act_mail = 0; |
|
1419 |
t->max_pass = 0; |
|
1420 |
t->max_mail = 0; |
|
1421 |
t->act_pass = 0; |
|
1422 |
t->act_mail = 0; |
|
1423 |
||
1424 |
t->pct_pass_transported = 0; |
|
1425 |
t->pct_mail_transported = 0; |
|
1426 |
t->fund_buildings_months = 0; |
|
1427 |
t->new_act_food = 0; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1428 |
t->new_act_water = 0; |
0 | 1429 |
t->act_food = 0; |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1430 |
t->act_water = 0; |
0 | 1431 |
|
2952 | 1432 |
for (i = 0; i != MAX_PLAYERS; i++) |
0 | 1433 |
t->ratings[i] = 500; |
1434 |
||
1435 |
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
|
1436 |
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
|
1437 |
t->exclusive_counter = 0; |
0 | 1438 |
t->statues = 0; |
1439 |
||
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1440 |
if (_opt.town_name < _nb_orig_names) { |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1441 |
/* Original town name */ |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1442 |
t->townnamegrfid = 0; |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1443 |
t->townnametype = SPECSTR_TOWNNAME_START + _opt.town_name; |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1444 |
} else { |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1445 |
/* Newgrf town name */ |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1446 |
t->townnamegrfid = GetGRFTownNameId(_opt.town_name - _nb_orig_names); |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1447 |
t->townnametype = GetGRFTownNameType(_opt.town_name - _nb_orig_names); |
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
1448 |
} |
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
|
1449 |
t->townnameparts = townnameparts; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1450 |
|
0 | 1451 |
UpdateTownVirtCoord(t); |
1452 |
_town_sort_dirty = true; |
|
1453 |
||
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1454 |
t->InitializeLayout(); |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1455 |
|
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1456 |
/* Random town size. */ |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1457 |
x = (Random() & 0xF) + 8; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1458 |
|
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1459 |
switch (size_mode) { |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1460 |
default: NOT_REACHED(); |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1461 |
|
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1462 |
case TSM_RANDOM: |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1463 |
t->larger_town = false; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1464 |
break; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1465 |
|
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1466 |
case TSM_FIXED: |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1467 |
x = size * 16 + 3; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1468 |
t->larger_town = false; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1469 |
break; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1470 |
|
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1471 |
case TSM_CITY: |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1472 |
x *= _patches.initial_city_size; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1473 |
t->larger_town = true; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1474 |
break; |
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
|
1475 |
} |
0 | 1476 |
|
1477 |
t->num_houses += x; |
|
1478 |
UpdateTownRadius(t); |
|
1479 |
||
1480 |
i = x * 4; |
|
1481 |
do { |
|
1482 |
GrowTown(t); |
|
1483 |
} while (--i); |
|
1484 |
||
1485 |
t->num_houses -= x; |
|
1486 |
UpdateTownRadius(t); |
|
1487 |
UpdateTownMaxPass(t); |
|
1488 |
} |
|
1489 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1490 |
/** Create a new town. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1491 |
* 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
|
1492 |
* 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
|
1493 |
* @param tile coordinates where town is built |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1494 |
* @param flags type of operation |
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1495 |
* @param p1 size of the town (0 = small, 1 = medium, 2 = large) |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1496 |
* @param p2 size mode (@see TownSizeMode) |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1497 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7410
diff
changeset
|
1498 |
CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1499 |
{ |
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
|
1500 |
uint32 townnameparts; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1501 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1502 |
/* Only in the scenario editor */ |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1503 |
if (_game_mode != GM_EDITOR) return CMD_ERROR; |
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1504 |
if (p2 > TSM_CITY) return CMD_ERROR; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1505 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1506 |
/* 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
|
1507 |
if (DistanceFromEdge(tile) < 12) |
0 | 1508 |
return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP); |
1509 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1510 |
/* Can only build on clear flat areas, possibly with trees. */ |
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
|
1511 |
if ((!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES)) || GetTileSlope(tile, NULL) != SLOPE_FLAT) { |
0 | 1512 |
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
|
1513 |
} |
0 | 1514 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1515 |
/* Check distance to all other towns. */ |
0 | 1516 |
if (IsCloseToTown(tile, 20)) |
1517 |
return_cmd_error(STR_0238_TOO_CLOSE_TO_ANOTHER_TOWN); |
|
1518 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1519 |
/* Get a unique name for the town. */ |
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
|
1520 |
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
|
1521 |
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
|
1522 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1523 |
/* Allocate town struct */ |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
1524 |
Town *t = new Town(tile); |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1525 |
if (t == NULL) return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
1526 |
AutoPtrT<Town> t_auto_delete = t; |
0 | 1527 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1528 |
/* Create the town */ |
0 | 1529 |
if (flags & DC_EXEC) { |
1530 |
_generating_world = true; |
|
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1531 |
DoCreateTown(t, tile, townnameparts, (TownSizeMode)p2, p1); |
0 | 1532 |
_generating_world = false; |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
1533 |
t_auto_delete.Detach(); |
0 | 1534 |
} |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
1535 |
return CommandCost(); |
0 | 1536 |
} |
1537 |
||
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1538 |
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size) |
0 | 1539 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1540 |
TileIndex tile; |
0 | 1541 |
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
|
1542 |
uint32 townnameparts; |
0 | 1543 |
|
1544 |
do { |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1545 |
/* Generate a tile index not too close from the edge */ |
2051 | 1546 |
tile = RandomTile(); |
2951 | 1547 |
if (DistanceFromEdge(tile) < 20) continue; |
0 | 1548 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1549 |
/* 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
|
1550 |
if (!IsTileType(tile, MP_CLEAR) || GetTileSlope(tile, NULL) != SLOPE_FLAT) continue; |
0 | 1551 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1552 |
/* Check not too close to a town */ |
2951 | 1553 |
if (IsCloseToTown(tile, 20)) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1554 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1555 |
/* Get a unique name for the town. */ |
2951 | 1556 |
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
|
1557 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1558 |
/* Allocate a town struct */ |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
1559 |
t = new Town(tile); |
2951 | 1560 |
if (t == NULL) break; |
0 | 1561 |
|
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1562 |
DoCreateTown(t, tile, townnameparts, mode, size); |
0 | 1563 |
return t; |
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1564 |
} while (--attempts); |
0 | 1565 |
return NULL; |
1566 |
} |
|
1567 |
||
7056
b4f146586c97
(svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents:
7043
diff
changeset
|
1568 |
static const byte _num_initial_towns[4] = {5, 11, 23, 46}; |
0 | 1569 |
|
6573 | 1570 |
bool GenerateTowns() |
0 | 1571 |
{ |
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1572 |
uint num = 0; |
6387
7ef7536b6861
(svn r8791) -Revert: r8790 Committed too much in last commit
miham
parents:
6386
diff
changeset
|
1573 |
uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7)); |
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1574 |
uint num_cities = _patches.larger_towns == 0 ? 0 : n / _patches.larger_towns; |
1202
7d8b86bd8ba2
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1575 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1576 |
SetGeneratingWorldProgress(GWP_TOWN, n); |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1577 |
|
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1578 |
do { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1579 |
IncreaseGeneratingWorldProgress(GWP_TOWN); |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1580 |
/* try 20 times to create a random-sized town for the first loop. */ |
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1581 |
TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1582 |
if (CreateRandomTown(20, mode, _patches.initial_city_size) != NULL) num++; |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1583 |
if (num_cities > 0) num_cities--; |
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1584 |
} while (--n); |
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1585 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1586 |
/* give it a last try, but now more aggressive */ |
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
1587 |
if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 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
|
1588 |
if (GetNumTowns() == 0) { |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1589 |
/* XXX - can we handle that more gracefully? */ |
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1590 |
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
|
1591 |
|
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1592 |
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
|
1593 |
} |
1362
adfd229bdc01
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1594 |
} |
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
|
1595 |
|
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
|
1596 |
return true; |
0 | 1597 |
} |
1598 |
||
1599 |
||
8804
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1600 |
/** Returns the bit corresponding to the town zone of the specified tile |
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1601 |
* @param t Town on which radius is to be found |
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1602 |
* @param tile TileIndex where radius needs to be found |
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1603 |
* @return the bit position of the given zone, as defined in HouseZones |
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1604 |
*/ |
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1605 |
HouseZonesBits GetTownRadiusGroup(const Town* t, TileIndex tile) |
0 | 1606 |
{ |
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
|
1607 |
uint dist = DistanceSquare(tile, t->xy); |
8804
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1608 |
HouseZonesBits smallest; |
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
|
1609 |
uint i; |
0 | 1610 |
|
8804
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1611 |
if (t->fund_buildings_months && dist <= 25) return HZB_TOWN_CENTRE; |
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1612 |
|
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1613 |
smallest = HZB_TOWN_EDGE; |
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
|
1614 |
for (i = 0; i != lengthof(t->radius); i++) { |
8804
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1615 |
if (dist < t->radius[i]) smallest = (HouseZonesBits)i; |
0 | 1616 |
} |
1617 |
||
1618 |
return smallest; |
|
1619 |
} |
|
1620 |
||
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1621 |
/** |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1622 |
* Clears tile and builds a house or house part. |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1623 |
* @param t tile index |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1624 |
* @param tid Town index |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1625 |
* @param counter of construction step |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1626 |
* @param stage of construction (used for drawing) |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1627 |
* @param type of house. Index into house specs array |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1628 |
* @param random_bits required for newgrf houses |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1629 |
* @pre house can be built here |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1630 |
*/ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1631 |
static inline void ClearMakeHouseTile(TileIndex tile, TownID tid, byte counter, byte stage, HouseID type, byte random_bits) |
0 | 1632 |
{ |
9114
6e7d4c2a60ae
(svn r12201) -Fix (r12060): compilation warnings - uninitialized variable when compiling with assert disabled
smatz
parents:
9112
diff
changeset
|
1633 |
#if !defined(NDEBUG) || defined(WITH_ASSERT) |
6e7d4c2a60ae
(svn r12201) -Fix (r12060): compilation warnings - uninitialized variable when compiling with assert disabled
smatz
parents:
9112
diff
changeset
|
1634 |
CommandCost cc = |
6e7d4c2a60ae
(svn r12201) -Fix (r12060): compilation warnings - uninitialized variable when compiling with assert disabled
smatz
parents:
9112
diff
changeset
|
1635 |
#endif /* !defined(NDEBUG) || defined(WITH_ASSERT) */ |
6e7d4c2a60ae
(svn r12201) -Fix (r12060): compilation warnings - uninitialized variable when compiling with assert disabled
smatz
parents:
9112
diff
changeset
|
1636 |
|
6e7d4c2a60ae
(svn r12201) -Fix (r12060): compilation warnings - uninitialized variable when compiling with assert disabled
smatz
parents:
9112
diff
changeset
|
1637 |
DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR); |
6e7d4c2a60ae
(svn r12201) -Fix (r12060): compilation warnings - uninitialized variable when compiling with assert disabled
smatz
parents:
9112
diff
changeset
|
1638 |
|
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1639 |
assert(CmdSucceeded(cc)); |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1640 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1641 |
MakeHouseTile(tile, tid, counter, stage, type, random_bits); |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1642 |
} |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1643 |
|
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1644 |
|
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1645 |
/** |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1646 |
* Write house information into the map. For houses > 1 tile, all tiles are marked. |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1647 |
* @param t tile index |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1648 |
* @param tid Town index |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1649 |
* @param counter of construction step |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1650 |
* @param stage of construction (used for drawing) |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1651 |
* @param type of house. Index into house specs array |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1652 |
* @param random_bits required for newgrf houses |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1653 |
* @pre house can be built here |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1654 |
*/ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1655 |
static void MakeTownHouse(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits) |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1656 |
{ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1657 |
BuildingFlags size = GetHouseSpecs(type)->building_flags; |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1658 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1659 |
ClearMakeHouseTile(t, tid, counter, stage, type, random_bits); |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1660 |
if (size & BUILDING_2_TILES_Y) ClearMakeHouseTile(t + TileDiffXY(0, 1), tid, counter, stage, ++type, random_bits); |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1661 |
if (size & BUILDING_2_TILES_X) ClearMakeHouseTile(t + TileDiffXY(1, 0), tid, counter, stage, ++type, random_bits); |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1662 |
if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(t + TileDiffXY(1, 1), tid, counter, stage, ++type, random_bits); |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1663 |
} |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1664 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1665 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1666 |
/** |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1667 |
* Checks if a house can be built here. Important is slope, bridge above |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1668 |
* and ability to clear the land. |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1669 |
* @param tile tile to check |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1670 |
* @param town town that is checking |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1671 |
* @param noslope are slopes (foundations) allowed? |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1672 |
* @return true iff house can be built here |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1673 |
*/ |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1674 |
static inline bool CanBuildHouseHere(TileIndex tile, TownID town, bool noslope) |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1675 |
{ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1676 |
/* cannot build on these slopes... */ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1677 |
Slope slope = GetTileSlope(tile, NULL); |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1678 |
if ((noslope && slope != SLOPE_FLAT) || IsSteepSlope(slope)) return false; |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1679 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1680 |
/* building under a bridge? */ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1681 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1682 |
|
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1683 |
/* do not try to build over house owned by another town */ |
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1684 |
if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) != town) return false; |
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1685 |
|
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1686 |
/* can we clear the land? */ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1687 |
return CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR)); |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1688 |
} |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1689 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1690 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1691 |
/** |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1692 |
* Checks if a house can be built at this tile, must have the same max z as parameter. |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1693 |
* @param tile tile to check |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1694 |
* @param town town that is checking |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1695 |
* @param z max z of this tile so more parts of a house are at the same height (with foundation) |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1696 |
* @param noslope are slopes (foundations) allowed? |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1697 |
* @return true iff house can be built here |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1698 |
* @see CanBuildHouseHere() |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1699 |
*/ |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1700 |
static inline bool CheckBuildHouseSameZ(TileIndex tile, TownID town, uint z, bool noslope) |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1701 |
{ |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1702 |
if (!CanBuildHouseHere(tile, town, noslope)) return false; |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1703 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1704 |
/* if building on slopes is allowed, there will be flattening foundation (to tile max z) */ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1705 |
if (GetTileMaxZ(tile) != z) return false; |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1706 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1707 |
return true; |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1708 |
} |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1709 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1710 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1711 |
/** |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1712 |
* Checks if a house of size 2x2 can be built at this tile |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1713 |
* @param tile tile, N corner |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1714 |
* @param town town that is checking |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1715 |
* @param z maximum tile z so all tile have the same max z |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1716 |
* @param noslope are slopes (foundations) allowed? |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1717 |
* @return true iff house can be built |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1718 |
* @see CheckBuildHouseSameZ() |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1719 |
*/ |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1720 |
static bool CheckFree2x2Area(TileIndex tile, TownID town, uint z, bool noslope) |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1721 |
{ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1722 |
/* we need to check this tile too because we can be at different tile now */ |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1723 |
if (!CheckBuildHouseSameZ(tile, town, z, noslope)) return false; |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1724 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1725 |
for (DiagDirection d = DIAGDIR_SE; d < DIAGDIR_END; d++) { |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1726 |
tile += TileOffsByDiagDir(d); |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1727 |
if (!CheckBuildHouseSameZ(tile, town, z, noslope)) return false; |
0 | 1728 |
} |
1729 |
||
1730 |
return true; |
|
1731 |
} |
|
1732 |
||
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1733 |
|
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1734 |
/** |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1735 |
* Checks if current town layout allows building here |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1736 |
* @param t town |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1737 |
* @param tile tile to check |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1738 |
* @return true iff town layout allows building here |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1739 |
* @note see layouts |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1740 |
*/ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1741 |
static inline bool TownLayoutAllowsHouseHere(Town *t, TileIndex tile) |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1742 |
{ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1743 |
TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile); |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1744 |
|
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1745 |
switch (t->GetActiveLayout()) { |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1746 |
case TL_2X2_GRID: |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1747 |
if ((grid_pos.x % 3) == 0 || (grid_pos.y % 3) == 0) return false; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1748 |
break; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1749 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1750 |
case TL_3X3_GRID: |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1751 |
if ((grid_pos.x % 4) == 0 || (grid_pos.y % 4) == 0) return false; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1752 |
break; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1753 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1754 |
default: |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1755 |
break; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1756 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1757 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1758 |
return true; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1759 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1760 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1761 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1762 |
/** |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1763 |
* Checks if current town layout allows 2x2 building here |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1764 |
* @param t town |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1765 |
* @param tile tile to check |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1766 |
* @return true iff town layout allows 2x2 building here |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1767 |
* @note see layouts |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1768 |
*/ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1769 |
static inline bool TownLayoutAllows2x2HouseHere(Town *t, TileIndex tile) |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1770 |
{ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1771 |
/* MapSize() is sure dividable by both MapSizeX() and MapSizeY(), |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1772 |
* so to do only one memory access, use MapSize() */ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1773 |
uint dx = MapSize() + TileX(t->xy) - TileX(tile); |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1774 |
uint dy = MapSize() + TileY(t->xy) - TileY(tile); |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1775 |
|
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
1776 |
switch (t->GetActiveLayout()) { |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1777 |
case TL_2X2_GRID: |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1778 |
if ((dx % 3) != 0 || (dy % 3) != 0) return false; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1779 |
break; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1780 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1781 |
case TL_3X3_GRID: |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1782 |
if ((dx % 4) < 2 || (dy % 4) < 2) return false; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1783 |
break; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1784 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1785 |
default: |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1786 |
break; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1787 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1788 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1789 |
return true; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1790 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1791 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1792 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1793 |
/** |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1794 |
* Checks if 1x2 or 2x1 building is allowed here, also takes into account current town layout |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1795 |
* Also, tests both building positions that occupy this tile |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1796 |
* @param tile tile where the building should be built |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1797 |
* @param t town |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1798 |
* @param maxz all tiles should have the same height |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1799 |
* @param noslope are slopes forbidden? |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1800 |
* @param second diagdir from first tile to second tile |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1801 |
**/ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1802 |
static bool CheckTownBuild2House(TileIndex *tile, Town *t, uint maxz, bool noslope, DiagDirection second) |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1803 |
{ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1804 |
/* 'tile' is already checked in BuildTownHouse() - CanBuildHouseHere() and slope test */ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1805 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1806 |
TileIndex tile2 = *tile + TileOffsByDiagDir(second); |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1807 |
if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, t->index, maxz, noslope)) return true; |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1808 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1809 |
tile2 = *tile + TileOffsByDiagDir(ReverseDiagDir(second)); |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1810 |
if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, t->index, maxz, noslope)) { |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1811 |
*tile = tile2; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1812 |
return true; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1813 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1814 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1815 |
return false; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1816 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1817 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1818 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1819 |
/** |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1820 |
* Checks if 2x2 building is allowed here, also takes into account current town layout |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1821 |
* Also, tests all four building positions that occupy this tile |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1822 |
* @param tile tile where the building should be built |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1823 |
* @param t town |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1824 |
* @param maxz all tiles should have the same height |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1825 |
* @param noslope are slopes forbidden? |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1826 |
**/ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1827 |
static bool CheckTownBuild2x2House(TileIndex *tile, Town *t, uint maxz, bool noslope) |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1828 |
{ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1829 |
TileIndex tile2 = *tile; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1830 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1831 |
for (DiagDirection d = DIAGDIR_SE;;d++) { // 'd' goes through DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_END |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1832 |
if (TownLayoutAllows2x2HouseHere(t, tile2) && CheckFree2x2Area(tile2, t->index, maxz, noslope)) { |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1833 |
*tile = tile2; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1834 |
return true; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1835 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1836 |
if (d == DIAGDIR_END) break; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1837 |
tile2 += TileOffsByDiagDir(ReverseDiagDir(d)); // go clockwise |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1838 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1839 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1840 |
return false; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1841 |
} |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1842 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1843 |
|
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1844 |
/** |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1845 |
* Tries to build a house at this tile |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1846 |
* @param t town the house will belong to |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1847 |
* @param tile where the house will be built |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1848 |
* @return false iff no house can be built at this tile |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1849 |
*/ |
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1850 |
static bool BuildTownHouse(Town *t, TileIndex tile) |
0 | 1851 |
{ |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1852 |
/* forbidden building here by town layout */ |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1853 |
if (!TownLayoutAllowsHouseHere(t, tile)) return false; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1854 |
|
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1855 |
/* no house allowed at all, bail out */ |
9077
dbb5f2dc2414
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz
parents:
9076
diff
changeset
|
1856 |
if (!CanBuildHouseHere(tile, t->index, false)) return false; |
8981
005e2c86844c
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz
parents:
8957
diff
changeset
|
1857 |
|
8984
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1858 |
uint z; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1859 |
Slope slope = GetTileSlope(tile, &z); |
0 | 1860 |
|
8804
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1861 |
/* Get the town zone type of the current tile, as well as the climate. |
6d7e8b85529e
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas
parents:
8787
diff
changeset
|
1862 |
* This will allow to easily compare with the specs of the new house to build */ |
8984
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1863 |
HouseZonesBits rad = GetTownRadiusGroup(t, tile); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1864 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1865 |
/* Above snow? */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1866 |
int land = _opt.landscape; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1867 |
if (land == LT_ARCTIC && z >= _opt.snow_line) land = -1; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1868 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1869 |
uint bitmask = (1 << rad) + (1 << (land + 12)); |
0 | 1870 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1871 |
/* bits 0-4 are used |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1872 |
* bits 11-15 are used |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
1873 |
* bits 5-10 are not used. */ |
8984
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1874 |
HouseID houses[HOUSE_MAX]; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1875 |
uint num = 0; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1876 |
uint probs[HOUSE_MAX]; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1877 |
uint probability_max = 0; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1878 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1879 |
/* Generate a list of all possible houses that can be built. */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1880 |
for (uint i = 0; i < HOUSE_MAX; i++) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1881 |
HouseSpec *hs = GetHouseSpecs(i); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1882 |
/* Verify that the candidate house spec matches the current tile status */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1883 |
if ((~hs->building_availability & bitmask) == 0 && hs->enabled) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1884 |
/* Without NewHouses, all houses have probability '1' */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1885 |
uint cur_prob = (_loaded_newgrf_features.has_newhouses ? hs->probability : 1); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1886 |
probability_max += cur_prob; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1887 |
probs[num] = cur_prob; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1888 |
houses[num++] = (HouseID)i; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1889 |
} |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1890 |
} |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1891 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1892 |
uint maxz = GetTileMaxZ(tile); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1893 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1894 |
while (probability_max > 0) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1895 |
uint r = RandomRange(probability_max); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1896 |
uint i; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1897 |
for (i = 0; i < num; i++) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1898 |
if (probs[i] > r) break; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1899 |
r -= probs[i]; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1900 |
} |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1901 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1902 |
HouseID house = houses[i]; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1903 |
probability_max -= probs[i]; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1904 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1905 |
/* remove tested house from the set */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1906 |
num--; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1907 |
houses[i] = houses[num]; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1908 |
probs[i] = probs[num]; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1909 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1910 |
HouseSpec *hs = GetHouseSpecs(house); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1911 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1912 |
if (_loaded_newgrf_features.has_newhouses) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1913 |
if (hs->override != 0) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1914 |
house = hs->override; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1915 |
hs = GetHouseSpecs(house); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1916 |
} |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1917 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1918 |
if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1919 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1920 |
if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1921 |
uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1922 |
if (callback_res != CALLBACK_FAILED && callback_res == 0) continue; |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
1923 |
} |
0 | 1924 |
} |
1925 |
||
8984
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1926 |
if (_cur_year < hs->min_date || _cur_year > hs->max_date) continue; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1927 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1928 |
/* Special houses that there can be only one of. */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1929 |
uint oneof = 0; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1930 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1931 |
if (hs->building_flags & BUILDING_IS_CHURCH) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1932 |
SetBit(oneof, TOWN_HAS_CHURCH); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1933 |
} else if (hs->building_flags & BUILDING_IS_STADIUM) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1934 |
SetBit(oneof, TOWN_HAS_STADIUM); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1935 |
} |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1936 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1937 |
if (HASBITS(t->flags12 , oneof)) continue; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1938 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1939 |
/* Make sure there is no slope? */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1940 |
bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1941 |
if (noslope && slope != SLOPE_FLAT) continue; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1942 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1943 |
if (hs->building_flags & TILE_SIZE_2x2) { |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1944 |
if (!CheckTownBuild2x2House(&tile, t, maxz, noslope)) continue; |
8984
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1945 |
} else if (hs->building_flags & TILE_SIZE_2x1) { |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1946 |
if (!CheckTownBuild2House(&tile, t, maxz, noslope, DIAGDIR_SW)) continue; |
8984
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1947 |
} else if (hs->building_flags & TILE_SIZE_1x2) { |
9076
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1948 |
if (!CheckTownBuild2House(&tile, t, maxz, noslope, DIAGDIR_SE)) continue; |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1949 |
} else { |
02117bd3ee61
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz
parents:
8984
diff
changeset
|
1950 |
/* 1x1 house checks are already done */ |
0 | 1951 |
} |
8984
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1952 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1953 |
/* build the house */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1954 |
t->num_houses++; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1955 |
IncreaseBuildingCount(t, house); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1956 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1957 |
/* Special houses that there can be only one of. */ |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1958 |
t->flags12 |= oneof; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1959 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1960 |
byte construction_counter = 0; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1961 |
byte construction_stage = 0; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1962 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1963 |
if (_generating_world) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1964 |
uint32 r = Random(); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1965 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1966 |
construction_stage = TOWN_HOUSE_COMPLETED; |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1967 |
if (Chance16(1, 7)) construction_stage = GB(r, 0, 2); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1968 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1969 |
if (construction_stage == TOWN_HOUSE_COMPLETED) { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1970 |
ChangePopulation(t, hs->population); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1971 |
} else { |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1972 |
construction_counter = GB(r, 2, 2); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1973 |
} |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1974 |
} |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1975 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1976 |
MakeTownHouse(tile, t->index, construction_counter, construction_stage, house, Random()); |
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1977 |
|
210bf891b465
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz
parents:
8983
diff
changeset
|
1978 |
return true; |
0 | 1979 |
} |
1980 |
||
8983
7a5e7b1d01dd
(svn r12062) -Fix: possible deadlock when there are no houses available to build at given tile
smatz
parents:
8981
diff
changeset
|
1981 |
return false; |
0 | 1982 |
} |
1983 |
||
1984 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1985 |
static void DoClearTownHouseHelper(TileIndex tile) |
0 | 1986 |
{ |
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
|
1987 |
assert(IsTileType(tile, MP_HOUSE)); |
0 | 1988 |
DoClearSquare(tile); |
1989 |
DeleteAnimatedTile(tile); |
|
1990 |
} |
|
1991 |
||
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
1992 |
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
|
1993 |
{ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
1994 |
HouseID house = GetHouseType(tile); |
0 | 1995 |
uint eflags; |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
1996 |
HouseSpec *hs; |
0 | 1997 |
|
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
|
1998 |
assert(IsTileType(tile, MP_HOUSE)); |
0 | 1999 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2000 |
/* need to align the tile to point to the upper left corner of the house */ |
0 | 2001 |
if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks. |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2002 |
if (GetHouseSpecs(house-1)->building_flags & TILE_SIZE_2x1) { |
0 | 2003 |
house--; |
1981 | 2004 |
tile += TileDiffXY(-1, 0); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2005 |
} else if (GetHouseSpecs(house-1)->building_flags & BUILDING_2_TILES_Y) { |
0 | 2006 |
house--; |
1981 | 2007 |
tile += TileDiffXY(0, -1); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2008 |
} else if (GetHouseSpecs(house-2)->building_flags & BUILDING_HAS_4_TILES) { |
0 | 2009 |
house-=2; |
1981 | 2010 |
tile += TileDiffXY(-1, 0); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2011 |
} else if (GetHouseSpecs(house-3)->building_flags & BUILDING_HAS_4_TILES) { |
0 | 2012 |
house-=3; |
1981 | 2013 |
tile += TileDiffXY(-1, -1); |
0 | 2014 |
} |
2015 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2016 |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2017 |
hs = GetHouseSpecs(house); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2018 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2019 |
/* Remove population from the town if the house is finished. */ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2020 |
if (IsHouseCompleted(tile)) { |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2021 |
ChangePopulation(t, -hs->population); |
0 | 2022 |
} |
2023 |
||
2024 |
t->num_houses--; |
|
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2025 |
DecreaseBuildingCount(t, house); |
0 | 2026 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2027 |
/* Clear flags for houses that only may exist once/town. */ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2028 |
if (hs->building_flags & BUILDING_IS_CHURCH) { |
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
2029 |
ClrBit(t->flags12, TOWN_HAS_CHURCH); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2030 |
} else if (hs->building_flags & BUILDING_IS_STADIUM) { |
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
2031 |
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
|
2032 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2033 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2034 |
/* Do the actual clearing of tiles */ |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2035 |
eflags = hs->building_flags; |
0 | 2036 |
DoClearTownHouseHelper(tile); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2037 |
if (eflags & BUILDING_2_TILES_X) DoClearTownHouseHelper(tile + TileDiffXY(1, 0)); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2038 |
if (eflags & BUILDING_2_TILES_Y) DoClearTownHouseHelper(tile + TileDiffXY(0, 1)); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2039 |
if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1)); |
0 | 2040 |
} |
2041 |
||
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2042 |
static bool IsUniqueTownName(const char *name) |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2043 |
{ |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2044 |
const Town *t; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2045 |
char buf[512]; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2046 |
|
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2047 |
FOR_ALL_TOWNS(t) { |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2048 |
SetDParam(0, t->index); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2049 |
GetString(buf, STR_TOWN, lastof(buf)); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2050 |
if (strcmp(buf, name) == 0) return false; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2051 |
} |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2052 |
|
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2053 |
return true; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2054 |
} |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2055 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2056 |
/** 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
|
2057 |
* @param tile unused |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2058 |
* @param flags type of operation |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2059 |
* @param p1 town ID to rename |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2060 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2061 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7410
diff
changeset
|
2062 |
CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2063 |
{ |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2064 |
Town *t; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2065 |
|
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2066 |
if (!IsValidTownID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2067 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2068 |
t = GetTown(p1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2069 |
|
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2070 |
if (!IsUniqueTownName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7554
diff
changeset
|
2071 |
|
0 | 2072 |
if (flags & DC_EXEC) { |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
2073 |
free(t->name); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
2074 |
t->name = strdup(_cmd_text); |
0 | 2075 |
|
2076 |
UpdateTownVirtCoord(t); |
|
2077 |
_town_sort_dirty = true; |
|
2078 |
UpdateAllStationVirtCoord(); |
|
8205
71006e01e45b
(svn r11243) -Fix: update waypoint signs when renaming a town
glx
parents:
8180
diff
changeset
|
2079 |
UpdateAllWaypointSigns(); |
0 | 2080 |
MarkWholeScreenDirty(); |
2081 |
} |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7442
diff
changeset
|
2082 |
return CommandCost(); |
0 | 2083 |
} |
2084 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2085 |
/** Called from GUI */ |
0 | 2086 |
void ExpandTown(Town *t) |
2087 |
{ |
|
9203
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
2088 |
uint amount, n; |
0 | 2089 |
|
2090 |
_generating_world = true; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2091 |
|
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
2092 |
/* The more houses, the faster we grow */ |
9203
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
2093 |
amount = RandomRange(ClampToU16(t->num_houses / 10)) + 3; |
0 | 2094 |
t->num_houses += amount; |
2095 |
UpdateTownRadius(t); |
|
2096 |
||
835
a22d6bc16a51
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
2097 |
n = amount * 10; |
0 | 2098 |
do GrowTown(t); while (--n); |
2099 |
||
2100 |
t->num_houses -= amount; |
|
2101 |
UpdateTownRadius(t); |
|
2102 |
||
2103 |
UpdateTownMaxPass(t); |
|
2104 |
_generating_world = false; |
|
2105 |
} |
|
2106 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2107 |
extern const byte _town_action_costs[8] = { |
0 | 2108 |
2, 4, 9, 35, 48, 53, 117, 175 |
2109 |
}; |
|
2110 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2111 |
static void TownActionAdvertiseSmall(Town* t) |
0 | 2112 |
{ |
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2113 |
ModifyStationRatingAround(t->xy, _current_player, 0x40, 10); |
0 | 2114 |
} |
2115 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2116 |
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
|
2117 |
{ |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2118 |
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
|
2119 |
} |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2120 |
|
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2121 |
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
|
2122 |
{ |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2123 |
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
|
2124 |
} |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2125 |
|
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2126 |
static void TownActionRoadRebuild(Town* t) |
0 | 2127 |
{ |
2128 |
t->road_build_months = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2129 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
2130 |
SetDParam(0, t->index); |
7554
076c42f44a83
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
7493
diff
changeset
|
2131 |
SetDParam(1, _current_player); |
0 | 2132 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2133 |
AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING, |
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
9203
diff
changeset
|
2134 |
NM_NORMAL, NF_TILE, NT_GENERAL, DNC_NONE, t->xy, 0); |
0 | 2135 |
} |
2136 |
||
6583
82012e77b10c
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6573
diff
changeset
|
2137 |
static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id) |
0 | 2138 |
{ |
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
|
2139 |
PlayerID old; |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7410
diff
changeset
|
2140 |
CommandCost r; |
0 | 2141 |
|
8045
2878bb74729f
(svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium
parents:
8041
diff
changeset
|
2142 |
/* Statues can be build on slopes, just like houses. Only the steep slopes is a no go. */ |
2878bb74729f
(svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium
parents:
8041
diff
changeset
|
2143 |
if (IsSteepSlope(GetTileSlope(tile, NULL))) return false; |
0 | 2144 |
|
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
|
2145 |
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
|
2146 |
!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
|
2147 |
!IsTileType(tile, MP_TREES)) { |
0 | 2148 |
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
|
2149 |
} |
0 | 2150 |
|
2151 |
old = _current_player; |
|
2152 |
_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
|
2153 |
r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 2154 |
_current_player = old; |
2155 |
||
2646
a91fd482fce5
(svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents:
2639
diff
changeset
|
2156 |
if (CmdFailed(r)) return false; |
0 | 2157 |
|
6583
82012e77b10c
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6573
diff
changeset
|
2158 |
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
|
2159 |
MarkTileDirtyByTile(tile); |
0 | 2160 |
|
2161 |
return true; |
|
2162 |
} |
|
2163 |
||
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2164 |
/** |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2165 |
* Search callback function for TownActionBuildStatue |
6980
6b5dee376733
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents:
6951
diff
changeset
|
2166 |
* @param tile on which to perform the search |
6583
82012e77b10c
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6573
diff
changeset
|
2167 |
* @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
|
2168 |
* @return the result of the test |
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2169 |
*/ |
6583
82012e77b10c
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6573
diff
changeset
|
2170 |
static bool SearchTileForStatue(TileIndex tile, uint32 town_id) |
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2171 |
{ |
6583
82012e77b10c
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6573
diff
changeset
|
2172 |
return DoBuildStatueOfCompany(tile, town_id); |
5118
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2173 |
} |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2174 |
|
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2175 |
/** |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2176 |
* 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
|
2177 |
* 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
|
2178 |
* @param t town to search in |
5a56a0f12206
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2179 |
*/ |
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2180 |
static void TownActionBuildStatue(Town* t) |
0 | 2181 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
2182 |
TileIndex tile = t->xy; |
0 | 2183 |
|
6583
82012e77b10c
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6573
diff
changeset
|
2184 |
if (CircularTileSearch(tile, 9, SearchTileForStatue, t->index)) |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
2185 |
SetBit(t->statues, _current_player); // Once found and built, "inform" the Town |
0 | 2186 |
} |
2187 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2188 |
static void TownActionFundBuildings(Town* t) |
0 | 2189 |
{ |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2190 |
/* Build next tick */ |
0 | 2191 |
t->grow_counter = 1; |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2192 |
/* If we were not already growing */ |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
2193 |
SetBit(t->flags12, TOWN_IS_FUNDED); |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2194 |
/* And grow for 3 months */ |
0 | 2195 |
t->fund_buildings_months = 3; |
2196 |
} |
|
2197 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2198 |
static void TownActionBuyRights(Town* t) |
0 | 2199 |
{ |
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
8138
diff
changeset
|
2200 |
/* Check if it's allowed to by the rights */ |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
8138
diff
changeset
|
2201 |
if (!_patches.exclusive_rights) return; |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
8138
diff
changeset
|
2202 |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
2203 |
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
|
2204 |
t->exclusivity = _current_player; |
0 | 2205 |
|
2206 |
ModifyStationRatingAround(t->xy, _current_player, 130, 17); |
|
2207 |
} |
|
2208 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2209 |
static void TownActionBribe(Town* t) |
0 | 2210 |
{ |
2211 |
if (!RandomRange(15)) { |
|
2212 |
Station *st; |
|
2213 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2214 |
/* set as unwanted for 6 months */ |
0 | 2215 |
t->unwanted[_current_player] = 6; |
2216 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2217 |
/* set all close by station ratings to 0 */ |
0 | 2218 |
FOR_ALL_STATIONS(st) { |
2219 |
if (st->town == t && st->owner == _current_player) { |
|
6676
30aea9ac89bc
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6669
diff
changeset
|
2220 |
for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0; |
0 | 2221 |
} |
2222 |
} |
|
2223 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2224 |
/* only show errormessage to the executing player. All errors are handled command.c |
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2225 |
* 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
|
2226 |
if (IsLocalPlayer()) ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0); |
0 | 2227 |
|
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
|
2228 |
/* 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
|
2229 |
* 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
|
2230 |
* be independent of any cheat settings |
0 | 2231 |
*/ |
2549 | 2232 |
if (t->ratings[_current_player] > RATING_BRIBE_DOWN_TO) { |
1005 | 2233 |
t->ratings[_current_player] = RATING_BRIBE_DOWN_TO; |
2549 | 2234 |
} |
0 | 2235 |
} else { |
1005 | 2236 |
ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM); |
0 | 2237 |
} |
2238 |
} |
|
2239 |
||
3877
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2240 |
typedef void TownActionProc(Town* t); |
0 | 2241 |
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
|
2242 |
TownActionAdvertiseSmall, |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2243 |
TownActionAdvertiseMedium, |
53efa8118448
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2244 |
TownActionAdvertiseLarge, |
0 | 2245 |
TownActionRoadRebuild, |
2246 |
TownActionBuildStatue, |
|
2247 |
TownActionFundBuildings, |
|
2248 |
TownActionBuyRights, |
|
2249 |
TownActionBribe |
|
2250 |
}; |
|
2251 |
||
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2252 |
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
|
2253 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2254 |
/** Do a town action. |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2255 |
* 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
|
2256 |
* 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
|
2257 |
* @param tile unused |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2258 |
* @param flags type of operation |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2259 |
* @param p1 town to do the action at |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2260 |
* @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
|
2261 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7410
diff
changeset
|
2262 |
CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2263 |
{ |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2264 |
Town *t; |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2265 |
|
4352
8ddb01bc6075
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2266 |
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
|
2267 |
|
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2268 |
t = GetTown(p1); |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2269 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8399
diff
changeset
|
2270 |
if (!HasBit(GetMaskOfTownActions(NULL, _current_player, t), p2)) return CMD_ERROR; |
0 | 2271 |
|
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8720
diff
changeset
|
2272 |
CommandCost cost(EXPENSES_OTHER, (_price.build_industry >> 8) * _town_action_costs[p2]); |
0 | 2273 |
|
2274 |
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
|
2275 |
_town_action_proc[p2](t); |
0 | 2276 |
InvalidateWindow(WC_TOWN_AUTHORITY, p1); |
2277 |
} |
|
2278 |
||
2279 |
return cost; |
|
2280 |
} |
|
2281 |
||
2282 |
static void UpdateTownGrowRate(Town *t) |
|
2283 |
{ |
|
2284 |
int n; |
|
2285 |
Station *st; |
|
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2286 |
uint16 m; |
0 | 2287 |
Player *p; |
2288 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2289 |
/* Reset player ratings if they're low */ |
0 | 2290 |
FOR_ALL_PLAYERS(p) { |
2291 |
if (p->is_active && t->ratings[p->index] <= 200) { |
|
2292 |
t->ratings[p->index] += 5; |
|
2293 |
} |
|
2294 |
} |
|
2295 |
||
2296 |
n = 0; |
|
2297 |
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
|
2298 |
if (DistanceSquare(st->xy, t->xy) <= t->radius[0]) { |
0 | 2299 |
if (st->time_since_load <= 20 || st->time_since_unload <= 20) { |
2300 |
n++; |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2301 |
if (IsValidPlayer(st->owner) && t->ratings[st->owner] <= 1000-12) |
0 | 2302 |
t->ratings[st->owner] += 12; |
2303 |
} else { |
|
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2304 |
if (IsValidPlayer(st->owner) && t->ratings[st->owner] >= -1000+15) |
0 | 2305 |
t->ratings[st->owner] -= 15; |
2306 |
} |
|
2307 |
} |
|
2308 |
} |
|
2309 |
||
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
2310 |
ClrBit(t->flags12, TOWN_IS_FUNDED); |
6951
5b4480a013e6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6950
diff
changeset
|
2311 |
if (_patches.town_growth_rate == 0 && t->fund_buildings_months == 0) return; |
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2312 |
|
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2313 |
/** Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the |
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2314 |
* number of times towns are processed before a new building is built. */ |
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2315 |
static const uint16 _grow_count_values[2][6] = { |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
2316 |
{ 120, 120, 120, 100, 80, 60 }, // Fund new buildings has been activated |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
2317 |
{ 320, 420, 300, 220, 160, 100 } // Normal values |
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2318 |
}; |
0 | 2319 |
|
2320 |
if (t->fund_buildings_months != 0) { |
|
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2321 |
m = _grow_count_values[0][min(n, 5)]; |
0 | 2322 |
t->fund_buildings_months--; |
2323 |
} else { |
|
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2324 |
m = _grow_count_values[1][min(n, 5)]; |
8463
3920ac0ab803
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
8427
diff
changeset
|
2325 |
if (n == 0 && !Chance16(1, 12)) return; |
0 | 2326 |
} |
2327 |
||
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6676
diff
changeset
|
2328 |
if (_opt.landscape == LT_ARCTIC) { |
6669
487ac09b95c4
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6668
diff
changeset
|
2329 |
if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90) |
0 | 2330 |
return; |
6683
7ec558346172
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6676
diff
changeset
|
2331 |
} else if (_opt.landscape == LT_TROPIC) { |
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
|
2332 |
if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food==0 || t->act_water==0) && t->population > 60) |
0 | 2333 |
return; |
2334 |
} |
|
2335 |
||
6951
5b4480a013e6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6950
diff
changeset
|
2336 |
/* Use the normal growth rate values if new buildings have been funded in |
5b4480a013e6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6950
diff
changeset
|
2337 |
* this town and the growth rate is set to none. */ |
5b4480a013e6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6950
diff
changeset
|
2338 |
uint growth_multiplier = _patches.town_growth_rate != 0 ? _patches.town_growth_rate - 1 : 1; |
5b4480a013e6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6950
diff
changeset
|
2339 |
|
5b4480a013e6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6950
diff
changeset
|
2340 |
m >>= growth_multiplier; |
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
2341 |
if (t->larger_town) m /= 2; |
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2342 |
|
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
|
2343 |
t->growth_rate = m / (t->num_houses / 50 + 1); |
0 | 2344 |
if (m <= t->grow_counter) |
2345 |
t->grow_counter = m; |
|
2346 |
||
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
2347 |
SetBit(t->flags12, TOWN_IS_FUNDED); |
0 | 2348 |
} |
2349 |
||
2350 |
static void UpdateTownAmounts(Town *t) |
|
2351 |
{ |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2352 |
/* Using +1 here to prevent overflow and division by zero */ |
0 | 2353 |
t->pct_pass_transported = t->new_act_pass * 256 / (t->new_max_pass + 1); |
2354 |
||
2355 |
t->max_pass = t->new_max_pass; t->new_max_pass = 0; |
|
2356 |
t->act_pass = t->new_act_pass; t->new_act_pass = 0; |
|
2357 |
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
|
2358 |
t->act_water = t->new_act_water; t->new_act_water = 0; |
0 | 2359 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2360 |
/* Using +1 here to prevent overflow and division by zero */ |
0 | 2361 |
t->pct_mail_transported = t->new_act_mail * 256 / (t->new_max_mail + 1); |
2362 |
t->max_mail = t->new_max_mail; t->new_max_mail = 0; |
|
2363 |
t->act_mail = t->new_act_mail; t->new_act_mail = 0; |
|
2364 |
||
2365 |
InvalidateWindow(WC_TOWN_VIEW, t->index); |
|
2366 |
} |
|
2367 |
||
2368 |
static void UpdateTownUnwanted(Town *t) |
|
2369 |
{ |
|
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
|
2370 |
const Player* p; |
0 | 2371 |
|
2372 |
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
|
2373 |
if (t->unwanted[p->index] > 0) t->unwanted[p->index]--; |
0 | 2374 |
} |
2375 |
} |
|
2376 |
||
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
2377 |
bool CheckIfAuthorityAllows(TileIndex tile) |
0 | 2378 |
{ |
2379 |
Town *t; |
|
2380 |
||
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2381 |
if (!IsValidPlayer(_current_player)) return true; |
0 | 2382 |
|
2383 |
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
|
2384 |
if (t == NULL) return true; |
0 | 2385 |
|
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
|
2386 |
if (t->ratings[_current_player] > -200) return true; |
0 | 2387 |
|
2388 |
_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
|
2389 |
SetDParam(0, t->index); |
0 | 2390 |
|
2391 |
return false; |
|
2392 |
} |
|
2393 |
||
2394 |
||
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
|
2395 |
Town* CalcClosestTownFromTile(TileIndex tile, uint threshold) |
0 | 2396 |
{ |
2397 |
Town *t; |
|
2398 |
uint dist, best = threshold; |
|
2399 |
Town *best_town = NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2400 |
|
0 | 2401 |
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
|
2402 |
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
|
2403 |
if (dist < best) { |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2404 |
best = dist; |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2405 |
best_town = t; |
0 | 2406 |
} |
2407 |
} |
|
2408 |
||
2409 |
return best_town; |
|
2410 |
} |
|
2411 |
||
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
|
2412 |
|
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
|
2413 |
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
|
2414 |
{ |
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
|
2415 |
if (IsTileType(tile, MP_HOUSE) || ( |
7866
e19fda04e8d3
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7831
diff
changeset
|
2416 |
IsTileType(tile, MP_ROAD) && |
7157
270bc5b64e08
(svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents:
7141
diff
changeset
|
2417 |
GetRoadOwner(tile, ROADTYPE_ROAD) == OWNER_TOWN |
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
|
2418 |
)) { |
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
|
2419 |
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
|
2420 |
} 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
|
2421 |
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
|
2422 |
} |
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
|
2423 |
} |
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
|
2424 |
|
8728
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2425 |
static bool _town_rating_test = false; |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2426 |
|
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2427 |
void SetTownRatingTestMode(bool mode) |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2428 |
{ |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2429 |
static int ref_count = 0; |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2430 |
if (mode) { |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2431 |
if (ref_count == 0) { |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2432 |
Town *t; |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2433 |
FOR_ALL_TOWNS(t) t->test_rating = t->ratings[_current_player]; |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2434 |
} |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2435 |
ref_count++; |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2436 |
} else { |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2437 |
assert(ref_count > 0); |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2438 |
ref_count--; |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2439 |
} |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2440 |
_town_rating_test = !(ref_count == 0); |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2441 |
} |
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
|
2442 |
|
0 | 2443 |
void ChangeTownRating(Town *t, int add, int max) |
2444 |
{ |
|
2445 |
int rating; |
|
2446 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2447 |
/* if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff */ |
2639 | 2448 |
if (t == NULL || |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2449 |
!IsValidPlayer(_current_player) || |
2639 | 2450 |
(_cheats.magic_bulldozer.value && add < 0)) { |
0 | 2451 |
return; |
2639 | 2452 |
} |
0 | 2453 |
|
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
2454 |
SetBit(t->have_ratings, _current_player); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2455 |
|
8728
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2456 |
rating = _town_rating_test ? t->test_rating : t->ratings[_current_player]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2457 |
|
0 | 2458 |
if (add < 0) { |
2459 |
if (rating > max) { |
|
2460 |
rating += add; |
|
2461 |
if (rating < max) rating = max; |
|
2462 |
} |
|
2463 |
} else { |
|
2464 |
if (rating < max) { |
|
2465 |
rating += add; |
|
2466 |
if (rating > max) rating = max; |
|
2467 |
} |
|
2468 |
} |
|
8728
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2469 |
if (_town_rating_test) { |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2470 |
t->test_rating = rating; |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2471 |
} else { |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2472 |
t->ratings[_current_player] = rating; |
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2473 |
} |
0 | 2474 |
} |
2475 |
||
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
|
2476 |
/* penalty for removing town-owned stuff */ |
0 | 2477 |
static const int _default_rating_settings [3][3] = { |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2478 |
/* ROAD_REMOVE, TUNNELBRIDGE_REMOVE, INDUSTRY_REMOVE */ |
8137
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
2479 |
{ 0, 128, 384}, // Permissive |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
2480 |
{ 48, 192, 480}, // Neutral |
67a9579abd74
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
8099
diff
changeset
|
2481 |
{ 96, 384, 768}, // Hostile |
0 | 2482 |
}; |
2483 |
||
2958
3f8946daf55f
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
2484 |
bool CheckforTownRating(uint32 flags, Town *t, byte type) |
0 | 2485 |
{ |
2486 |
int modemod; |
|
2487 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2488 |
/* 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
|
2489 |
if (t == NULL || !IsValidPlayer(_current_player) || _cheats.magic_bulldozer.value) |
0 | 2490 |
return true; |
2491 |
||
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
|
2492 |
/* 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
|
2493 |
* 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
|
2494 |
* difficulty setting. Minimum town rating selected by difficulty level |
0 | 2495 |
*/ |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1451
diff
changeset
|
2496 |
modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type]; |
0 | 2497 |
|
8728
26930bbf9bee
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx
parents:
8726
diff
changeset
|
2498 |
if ((_town_rating_test ? t->test_rating : 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
|
2499 |
SetDParam(0, t->index); |
0 | 2500 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
2501 |
return false; |
|
2502 |
} |
|
2503 |
||
2504 |
return true; |
|
2505 |
} |
|
2506 |
||
6573 | 2507 |
void TownsMonthlyLoop() |
0 | 2508 |
{ |
2509 |
Town *t; |
|
2510 |
||
4346
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2511 |
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
|
2512 |
if (t->road_build_months != 0) t->road_build_months--; |
0 | 2513 |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
2514 |
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
|
2515 |
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
|
2516 |
|
0 | 2517 |
UpdateTownGrowRate(t); |
2518 |
UpdateTownAmounts(t); |
|
2519 |
UpdateTownUnwanted(t); |
|
2520 |
} |
|
2521 |
} |
|
2522 |
||
6573 | 2523 |
void InitializeTowns() |
0 | 2524 |
{ |
2525 |
Subsidy *s; |
|
2526 |
||
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2527 |
/* Clean the town pool and create 1 block in it */ |
7897
222641b84fc4
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents:
7886
diff
changeset
|
2528 |
_Town_pool.CleanPool(); |
222641b84fc4
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents:
7886
diff
changeset
|
2529 |
_Town_pool.AddBlockToPool(); |
0 | 2530 |
|
2531 |
memset(_subsidies, 0, sizeof(_subsidies)); |
|
2532 |
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
|
2533 |
s->cargo_type = CT_INVALID; |
0 | 2534 |
|
2535 |
_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
|
2536 |
_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
|
2537 |
_total_towns = 0; |
0 | 2538 |
_town_sort_dirty = true; |
2539 |
} |
|
2540 |
||
7990
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7979
diff
changeset
|
2541 |
static CommandCost TerraformTile_Town(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7979
diff
changeset
|
2542 |
{ |
8078
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2543 |
if (AutoslopeEnabled()) { |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2544 |
HouseID house = GetHouseType(tile); |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2545 |
HouseSpec *hs = GetHouseSpecs(house); |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2546 |
|
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2547 |
/* Here we differ from TTDP by checking TILE_NOT_SLOPED */ |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2548 |
if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) && |
8726
5ae45b46506b
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents:
8720
diff
changeset
|
2549 |
(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
8078
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2550 |
} |
bdf94bf88568
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
8073
diff
changeset
|
2551 |
|
7990
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7979
diff
changeset
|
2552 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7979
diff
changeset
|
2553 |
} |
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7979
diff
changeset
|
2554 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2555 |
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
|
2556 |
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
|
2557 |
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
|
2558 |
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
|
2559 |
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
|
2560 |
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
|
2561 |
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
|
2562 |
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
|
2563 |
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
|
2564 |
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
|
2565 |
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
|
2566 |
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
|
2567 |
NULL, /* vehicle_enter_tile_proc */ |
7831
5dded9b03500
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7829
diff
changeset
|
2568 |
GetFoundation_Town, /* get_foundation_proc */ |
7990
70039e33e893
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7979
diff
changeset
|
2569 |
TerraformTile_Town, /* terraform_tile_proc */ |
0 | 2570 |
}; |
2571 |
||
2572 |
||
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2573 |
/** Save and load of towns. */ |
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2574 |
static const SaveLoad _town_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2575 |
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
|
2576 |
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
|
2577 |
|
9203
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
2578 |
SLE_CONDNULL(2, 0, 2), ///< population, no longer in use |
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
2579 |
SLE_CONDNULL(4, 3, 84), ///< population, no longer in use |
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
2580 |
SLE_CONDNULL(2, 0, 91), ///< num_houses, no longer in use |
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
2581 |
|
7452
f6fd23727af0
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
7446
diff
changeset
|
2582 |
SLE_CONDVAR(Town, townnamegrfid, SLE_UINT32, 66, SL_MAX_VERSION), |
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
|
2583 |
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
|
2584 |
SLE_VAR(Town, townnameparts, SLE_UINT32), |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
2585 |
SLE_CONDSTR(Town, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 2586 |
|
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
|
2587 |
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
|
2588 |
SLE_VAR(Town, statues, SLE_UINT8), |
0 | 2589 |
|
9203
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
2590 |
SLE_CONDNULL(1, 0, 1), ///< sort_index, no longer in use |
0 | 2591 |
|
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
|
2592 |
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
|
2593 |
SLE_ARR(Town, ratings, SLE_INT16, 8), |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2594 |
/* failed bribe attempts are stored since savegame format 4 */ |
9203
55b0289562a8
(svn r12381) -Fix [FS1835] [FS1535] (r11855): The number of houses wasn't computed right. A few other things regaring the updating had to be changed. Big thanks for support to frosch123 and SmatZ, to name just a few. (Inspired by a patch of bilbo)
skidd13
parents:
9114
diff
changeset
|
2595 |
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
|
2596 |
|
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
|
2597 |
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
|
2598 |
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
|
2599 |
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
|
2600 |
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
|
2601 |
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
|
2602 |
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
|
2603 |
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
|
2604 |
SLE_CONDVAR(Town, new_act_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
0 | 2605 |
|
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
|
2606 |
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
|
2607 |
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
|
2608 |
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
|
2609 |
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
|
2610 |
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
|
2611 |
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
|
2612 |
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
|
2613 |
SLE_CONDVAR(Town, new_act_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
0 | 2614 |
|
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
|
2615 |
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
|
2616 |
SLE_VAR(Town, pct_mail_transported, SLE_UINT8), |
0 | 2617 |
|
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
|
2618 |
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
|
2619 |
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
|
2620 |
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
|
2621 |
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
|
2622 |
|
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2623 |
SLE_CONDVAR(Town, time_until_rebuild, SLE_UINT8, 0, 53), |
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2624 |
SLE_CONDVAR(Town, grow_counter, SLE_UINT8, 0, 53), |
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2625 |
SLE_CONDVAR(Town, growth_rate, SLE_UINT8, 0, 53), |
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2626 |
|
8855
e7a6bbce5400
(svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents:
8804
diff
changeset
|
2627 |
SLE_CONDVAR(Town, time_until_rebuild, SLE_UINT16, 54, SL_MAX_VERSION), |
e7a6bbce5400
(svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents:
8804
diff
changeset
|
2628 |
SLE_CONDVAR(Town, grow_counter, SLE_UINT16, 54, SL_MAX_VERSION), |
e7a6bbce5400
(svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents:
8804
diff
changeset
|
2629 |
SLE_CONDVAR(Town, growth_rate, SLE_INT16, 54, SL_MAX_VERSION), |
6950
c572b218bf2f
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6923
diff
changeset
|
2630 |
|
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
|
2631 |
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
|
2632 |
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
|
2633 |
|
8855
e7a6bbce5400
(svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents:
8804
diff
changeset
|
2634 |
SLE_CONDVAR(Town, exclusivity, SLE_UINT8, 2, SL_MAX_VERSION), |
e7a6bbce5400
(svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents:
8804
diff
changeset
|
2635 |
SLE_CONDVAR(Town, exclusive_counter, SLE_UINT8, 2, SL_MAX_VERSION), |
6982
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
2636 |
|
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
2637 |
SLE_CONDVAR(Town, larger_town, SLE_BOOL, 56, SL_MAX_VERSION), |
c414fad6c440
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6980
diff
changeset
|
2638 |
|
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6683
diff
changeset
|
2639 |
/* 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
|
2640 |
SLE_CONDNULL(30, 2, SL_MAX_VERSION), |
0 | 2641 |
|
2642 |
SLE_END() |
|
2643 |
}; |
|
2644 |
||
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2645 |
/* Save and load the mapping between the house id on the map, and the grf file |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2646 |
* it came from. */ |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2647 |
static const SaveLoad _house_id_mapping_desc[] = { |
7125
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2648 |
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32), |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2649 |
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8), |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2650 |
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8), |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2651 |
SLE_END() |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2652 |
}; |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2653 |
|
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2654 |
static void Save_HOUSEIDS() |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2655 |
{ |
7125
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2656 |
uint j = _house_mngr.GetMaxMapping(); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2657 |
|
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2658 |
for (uint i = 0; i < j; i++) { |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2659 |
SlSetArrayIndex(i); |
7125
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2660 |
SlObject(&_house_mngr.mapping_ID[i], _house_id_mapping_desc); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2661 |
} |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2662 |
} |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2663 |
|
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2664 |
static void Load_HOUSEIDS() |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2665 |
{ |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2666 |
int index; |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2667 |
|
7125
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2668 |
_house_mngr.ResetMapping(); |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2669 |
uint max_id = _house_mngr.GetMaxMapping(); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2670 |
|
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2671 |
while ((index = SlIterateArray()) != -1) { |
7125
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2672 |
if ((uint)index >= max_id) break; |
4ce0c7a12a3f
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
7106
diff
changeset
|
2673 |
SlObject(&_house_mngr.mapping_ID[index], _house_id_mapping_desc); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2674 |
} |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2675 |
} |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2676 |
|
6573 | 2677 |
static void Save_TOWN() |
0 | 2678 |
{ |
2679 |
Town *t; |
|
2680 |
||
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2681 |
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
|
2682 |
SlSetArrayIndex(t->index); |
3f00094f2670
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2683 |
SlObject(t, _town_desc); |
0 | 2684 |
} |
2685 |
} |
|
2686 |
||
6573 | 2687 |
static void Load_TOWN() |
0 | 2688 |
{ |
2689 |
int index; |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2690 |
|
1261
d7c7447dd22d
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
2691 |
_total_towns = 0; |
d7c7447dd22d
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
2692 |
|
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2693 |
while ((index = SlIterateArray()) != -1) { |
7882
64cdb1d52f16
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7866
diff
changeset
|
2694 |
Town *t = new (index) Town(); |
0 | 2695 |
SlObject(t, _town_desc); |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2696 |
|
5298
6d4c150bdd94
(svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents:
5247
diff
changeset
|
2697 |
_total_towns++; |
0 | 2698 |
} |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2699 |
|
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2700 |
/* 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
|
2701 |
* 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
|
2702 |
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
|
2703 |
_cur_town_ctr = 0; |
0 | 2704 |
} |
2705 |
||
6573 | 2706 |
void AfterLoadTown() |
0 | 2707 |
{ |
2708 |
_town_sort_dirty = true; |
|
9292
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
2709 |
|
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
2710 |
Town *t; |
4f5612017238
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13
parents:
9287
diff
changeset
|
2711 |
FOR_ALL_TOWNS(t) t->InitializeLayout(); |
0 | 2712 |
} |
2713 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
2714 |
extern const ChunkHandler _town_chunk_handlers[] = { |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2715 |
{ 'HIDS', Save_HOUSEIDS, Load_HOUSEIDS, CH_ARRAY }, |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2716 |
{ 'CITY', Save_TOWN, Load_TOWN, CH_ARRAY | CH_LAST}, |
0 | 2717 |
}; |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2718 |
|
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2719 |
void ResetHouses() |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2720 |
{ |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2721 |
memset(&_house_specs, 0, sizeof(_house_specs)); |
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2722 |
memcpy(&_house_specs, &_original_house_specs, sizeof(_original_house_specs)); |
8162
8e15b94334b5
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
8153
diff
changeset
|
2723 |
|
8e15b94334b5
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
8153
diff
changeset
|
2724 |
/* Reset any overrides that have been set. */ |
8e15b94334b5
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
8153
diff
changeset
|
2725 |
_house_mngr.ResetOverride(); |
6658
59048224be55
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6583
diff
changeset
|
2726 |
} |