Mercurial > hg > openttd
annotate src/town_cmd.cpp @ 11997:e2187548a5e4 draft
(svn r16403) -Codechange: move code related to subsidies to separate file
author | smatz <smatz@openttd.org> |
---|---|
date | Sat, 23 May 2009 15:46:00 +0000 |
parents | e17a54c88806 |
children | d0bf08a7c260 |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
9071
diff
changeset
|
3 /** @file town_cmd.cpp Handling of town tiles. */ |
6201
3b141366478a
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents:
6133
diff
changeset
|
4 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
5 #include "stdafx.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
6 #include "openttd.h" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10855
diff
changeset
|
7 #include "road_type.h" |
8102
afb4c7da91df
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium <rubidium@openttd.org>
parents:
8088
diff
changeset
|
8 #include "road_internal.h" /* Cleaning up road bits */ |
10289
5f3f0d0a6e07
(svn r14528) -Codechange: cache the closest town for all road tiles instead of only roads owned by tiles. This replaces a O(n) search over all towns from the road's tileloop with a O(1) lookup (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10269
diff
changeset
|
9 #include "road_cmd.h" |
6343
f75b72d9fc98
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros <maedhros@openttd.org>
parents:
6342
diff
changeset
|
10 #include "landscape.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
11 #include "town_map.h" |
8224
c45446125bf0
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents:
8214
diff
changeset
|
12 #include "viewport_func.h" |
8116
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8114
diff
changeset
|
13 #include "command_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
14 #include "industry.h" |
8785
2a8950a812dc
(svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium <rubidium@openttd.org>
parents:
8763
diff
changeset
|
15 #include "station_base.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
16 #include "company_base.h" |
8763
d6e363672edb
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium <rubidium@openttd.org>
parents:
8707
diff
changeset
|
17 #include "news_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
18 #include "gui.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
19 #include "unmovable_map.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
20 #include "water_map.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
21 #include "variables.h" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10855
diff
changeset
|
22 #include "slope_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
23 #include "genworld.h" |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
24 #include "newgrf.h" |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
25 #include "newgrf_house.h" |
6629
188437dffcff
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents:
6610
diff
changeset
|
26 #include "newgrf_commons.h" |
6956
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
27 #include "newgrf_townname.h" |
10837
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
28 #include "newgrf_text.h" |
7582
e77bd387f449
(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 <rubidium@openttd.org>
parents:
7577
diff
changeset
|
29 #include "autoslope.h" |
7709
1859cffc251e
(svn r11243) -Fix: update waypoint signs when renaming a town
glx <glx@openttd.org>
parents:
7684
diff
changeset
|
30 #include "waypoint.h" |
7849
e6ee8bfd9045
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas <belugas@openttd.org>
parents:
7847
diff
changeset
|
31 #include "transparency.h" |
8083
e02014b06c7f
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz <smatz@openttd.org>
parents:
7969
diff
changeset
|
32 #include "tunnelbridge_map.h" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
8108
diff
changeset
|
33 #include "strings_func.h" |
8131
e300ac8001ae
(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 <rubidium@openttd.org>
parents:
8124
diff
changeset
|
34 #include "window_func.h" |
8214
6385dffc0b37
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium <rubidium@openttd.org>
parents:
8197
diff
changeset
|
35 #include "string_func.h" |
8787
ff327b646d49
(svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium <rubidium@openttd.org>
parents:
8785
diff
changeset
|
36 #include "newgrf_cargo.h" |
8962
322e2779f67a
(svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium <rubidium@openttd.org>
parents:
8944
diff
changeset
|
37 #include "economy_func.h" |
322e2779f67a
(svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium <rubidium@openttd.org>
parents:
8944
diff
changeset
|
38 #include "station_func.h" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10855
diff
changeset
|
39 #include "cheat_type.h" |
9006
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
40 #include "functions.h" |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
41 #include "animated_tile_func.h" |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
42 #include "date_func.h" |
11997
e2187548a5e4
(svn r16403) -Codechange: move code related to subsidies to separate file
smatz <smatz@openttd.org>
parents:
11973
diff
changeset
|
43 #include "subsidy_func.h" |
10487
75d47d3e0644
(svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents:
10480
diff
changeset
|
44 #include "core/smallmap_type.hpp" |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
45 #include "core/pool_func.hpp" |
8083
e02014b06c7f
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz <smatz@openttd.org>
parents:
7969
diff
changeset
|
46 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8258
diff
changeset
|
47 #include "table/strings.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8258
diff
changeset
|
48 #include "table/town_land.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
49 |
8268
ab53b3bf7100
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
50 HouseSpec _house_specs[HOUSE_MAX]; |
ab53b3bf7100
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
51 |
ab53b3bf7100
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
52 Town *_cleared_town; |
ab53b3bf7100
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
53 int _cleared_town_rating; |
ab53b3bf7100
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
54 |
11230
4864c1e8957a
(svn r15584) -Codechange: Move several variables from variables.h to more appropriate headers.
yexo <yexo@openttd.org>
parents:
11219
diff
changeset
|
55 uint32 _cur_town_ctr; ///< iterator through all towns in OnTick_Town |
4864c1e8957a
(svn r15584) -Codechange: Move several variables from variables.h to more appropriate headers.
yexo <yexo@openttd.org>
parents:
11219
diff
changeset
|
56 uint32 _cur_town_iter; ///< frequency iterator at the same place |
4864c1e8957a
(svn r15584) -Codechange: Move several variables from variables.h to more appropriate headers.
yexo <yexo@openttd.org>
parents:
11219
diff
changeset
|
57 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
58 /* Initialize the town-pool */ |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
59 TownPool _town_pool("Town"); |
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
60 INSTANTIATE_POOL_METHODS(Town) |
7386
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
61 |
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
62 Town::~Town() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
63 { |
8258
6017c5ebeb7e
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138 <peter1138@openttd.org>
parents:
8254
diff
changeset
|
64 free(this->name); |
7413
571c87eed06c
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium <rubidium@openttd.org>
parents:
7410
diff
changeset
|
65 |
571c87eed06c
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium <rubidium@openttd.org>
parents:
7410
diff
changeset
|
66 if (CleaningPool()) return; |
571c87eed06c
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium <rubidium@openttd.org>
parents:
7410
diff
changeset
|
67 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
68 Industry *i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
69 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
70 /* Delete town authority window |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
71 * and remove from list of sorted towns */ |
7386
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
72 DeleteWindowById(WC_TOWN_VIEW, this->index); |
9387
a240dd49a2e8
(svn r13297) -Codechange: Use GUIList for the town directory window
peter1138 <peter1138@openttd.org>
parents:
9358
diff
changeset
|
73 InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
74 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
75 /* Delete all industries belonging to the town */ |
7390
9ae410265dce
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7386
diff
changeset
|
76 FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
77 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
78 /* Go through all tiles and delete those belonging to the town */ |
7386
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
79 for (TileIndex tile = 0; tile < MapSize(); ++tile) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 switch (GetTileType(tile)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 case MP_HOUSE: |
7386
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
82 if (GetTownByTile(tile) == this) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
83 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
84 |
7370
fba35a9abf79
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium <rubidium@openttd.org>
parents:
7335
diff
changeset
|
85 case MP_ROAD: |
10340
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
86 /* Cached nearest town is updated later (after this town has been deleted) */ |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
87 if (HasTownOwnedRoad(tile) && GetTownIndex(tile) == this->index) { |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
88 DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
10289
5f3f0d0a6e07
(svn r14528) -Codechange: cache the closest town for all road tiles instead of only roads owned by tiles. This replaces a O(n) search over all towns from the road's tileloop with a O(1) lookup (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10269
diff
changeset
|
89 } |
10340
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
90 break; |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
91 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
92 case MP_TUNNELBRIDGE: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
93 if (IsTileOwner(tile, OWNER_TOWN) && |
10236
59398a628f10
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10208
diff
changeset
|
94 ClosestTownFromTile(tile, UINT_MAX) == this) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
95 DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
96 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
97 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
99 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
100 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
101 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
102 |
7386
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
103 DeleteSubsidyWithTown(this->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
104 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
105 MarkWholeScreenDirty(); |
7386
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
106 |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
107 UpdateNearestTownForRoadTiles(false, this); |
7386
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
108 } |
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
109 |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
110 /** |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
111 * Assigns town layout. If Random, generates one based on TileHash. |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
112 */ |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
113 void Town::InitializeLayout(TownLayout layout) |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
114 { |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
115 if (layout != TL_RANDOM) { |
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
116 this->layout = layout; |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
117 return; |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
118 } |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
119 |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
120 this->layout = TileHash(TileX(this->xy), TileY(this->xy)) % (NUM_TLS - 1); |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
121 } |
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
122 |
9463
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
123 Money HouseSpec::GetRemovalCost() const |
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
124 { |
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
125 return (_price.remove_house * this->removal_cost) >> 8; |
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
126 } |
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
127 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
128 // Local |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
129 static int _grow_town_result; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
130 |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
131 /* Describe the possible states */ |
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
132 enum TownGrowthResult { |
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
133 GROWTH_SUCCEED = -1, |
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
134 GROWTH_SEARCH_STOPPED = 0 |
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
135 // GROWTH_SEARCH_RUNNING >= 1 |
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
136 }; |
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
137 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
138 static bool BuildTownHouse(Town *t, TileIndex tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
139 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
140 static void TownDrawHouseLift(const TileInfo *ti) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
141 { |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5587
diff
changeset
|
142 AddChildSpriteScreen(SPR_LIFT, PAL_NONE, 14, 60 - GetLiftPosition(ti->tile)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
143 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
144 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
145 typedef void TownDrawTileProc(const TileInfo *ti); |
11376
b9b2391afd1a
(svn r15726) -Codechange: unify coding style for const pointers
smatz <smatz@openttd.org>
parents:
11368
diff
changeset
|
146 static TownDrawTileProc * const _town_draw_tile_procs[1] = { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
147 TownDrawHouseLift |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 |
8791
2693434c1f4c
(svn r12513) -Codechange: rename OriginalTileRandomiser something more descriptive
skidd13 <skidd13@openttd.org>
parents:
8787
diff
changeset
|
150 /** |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
151 * Return a random direction |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
152 * |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
153 * @return a random direction |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
154 */ |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
155 static inline DiagDirection RandomDiagDir() |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
156 { |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
157 return (DiagDirection)(3 & Random()); |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
158 } |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
159 |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
160 /** |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
161 * House Tile drawing handler. |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
162 * Part of the tile loop process |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
163 * @param ti TileInfo of the tile to draw |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
164 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
165 static void DrawTile_Town(TileInfo *ti) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
166 { |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
167 HouseID house_id = GetHouseType(ti->tile); |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
168 |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
169 if (house_id >= NEW_HOUSE_OFFSET) { |
6342
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
170 /* Houses don't necessarily need new graphics. If they don't have a |
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
171 * spritegroup associated with them, then the sprite for the substitute |
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
172 * house id is drawn instead. */ |
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
173 if (GetHouseSpecs(house_id)->spritegroup != NULL) { |
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
174 DrawNewHouseTile(ti, house_id); |
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
175 return; |
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
176 } else { |
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
177 house_id = GetHouseSpecs(house_id)->substitute_id; |
02bfc4a81378
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents:
6341
diff
changeset
|
178 } |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
179 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
180 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
181 /* Retrieve pointer to the draw town tile struct */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
182 const DrawBuildingsTileStruct *dcts = &_town_draw_tile_data[house_id << 4 | TileHash2Bit(ti->x, ti->y) << 2 | GetHouseBuildingStage(ti->tile)]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
183 |
7335
0090d1c6b978
(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 <rubidium@openttd.org>
parents:
7333
diff
changeset
|
184 if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5587
diff
changeset
|
185 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
186 DrawGroundSprite(dcts->ground.sprite, dcts->ground.pal); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
187 |
8806
104bbcae351d
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz <smatz@openttd.org>
parents:
8796
diff
changeset
|
188 /* If houses are invisible, do not draw the upper part */ |
104bbcae351d
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz <smatz@openttd.org>
parents:
8796
diff
changeset
|
189 if (IsInvisibilitySet(TO_HOUSES)) return; |
104bbcae351d
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz <smatz@openttd.org>
parents:
8796
diff
changeset
|
190 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
191 /* Add a house on top of the ground? */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
192 SpriteID image = dcts->building.sprite; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
193 if (image != 0) { |
7333
7110c41ab174
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents:
7226
diff
changeset
|
194 AddSortableSpriteToDraw(image, dcts->building.pal, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
195 ti->x + dcts->subtile_x, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
196 ti->y + dcts->subtile_y, |
7577
a9acd5d86f94
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium <rubidium@openttd.org>
parents:
7566
diff
changeset
|
197 dcts->width, |
a9acd5d86f94
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium <rubidium@openttd.org>
parents:
7566
diff
changeset
|
198 dcts->height, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
199 dcts->dz, |
7333
7110c41ab174
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents:
7226
diff
changeset
|
200 ti->z, |
7849
e6ee8bfd9045
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas <belugas@openttd.org>
parents:
7847
diff
changeset
|
201 IsTransparencySet(TO_HOUSES) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
202 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
203 |
7849
e6ee8bfd9045
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas <belugas@openttd.org>
parents:
7847
diff
changeset
|
204 if (IsTransparencySet(TO_HOUSES)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
205 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
206 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
207 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
208 int proc = dcts->draw_proc - 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
209 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
210 if (proc >= 0) _town_draw_tile_procs[proc](ti); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
211 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
212 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
213 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
214 static uint GetSlopeZ_Town(TileIndex tile, uint x, uint y) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
215 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
216 return GetTileMaxZ(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
217 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
218 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
219 /** Tile callback routine */ |
7335
0090d1c6b978
(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 <rubidium@openttd.org>
parents:
7333
diff
changeset
|
220 static Foundation GetFoundation_Town(TileIndex tile, Slope tileh) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
221 { |
7335
0090d1c6b978
(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 <rubidium@openttd.org>
parents:
7333
diff
changeset
|
222 return FlatteningFoundation(tileh); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
223 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
224 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
225 /** |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
226 * Animate a tile for a town |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
227 * Only certain houses can be animated |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
228 * The newhouses animation superseeds regular ones |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
229 * @param tile TileIndex of the house to animate |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
230 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
231 static void AnimateTile_Town(TileIndex tile) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
232 { |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
233 if (GetHouseType(tile) >= NEW_HOUSE_OFFSET) { |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
234 AnimateNewHouseTile(tile); |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
235 return; |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
236 } |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
237 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
238 if (_tick_counter & 3) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
239 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
240 /* If the house is not one with a lift anymore, then stop this animating. |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
241 * Not exactly sure when this happens, but probably when a house changes. |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
242 * Before this was just a return...so it'd leak animated tiles.. |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
243 * That bug seems to have been here since day 1?? */ |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
244 if (!(GetHouseSpecs(GetHouseType(tile))->building_flags & BUILDING_IS_ANIMATED)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
245 DeleteAnimatedTile(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
246 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
247 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
248 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
249 if (!LiftHasDestination(tile)) { |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
250 uint i; |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
251 |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
252 /* Building has 6 floors, number 0 .. 6, where 1 is illegal. |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
253 * This is due to the fact that the first floor is, in the graphics, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
254 * the height of 2 'normal' floors. |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
255 * Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
256 do { |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
257 i = RandomRange(7); |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
258 } while (i == 1 || i * 6 == GetLiftPosition(tile)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
259 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 SetLiftDestination(tile, i); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
261 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
262 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
263 int pos = GetLiftPosition(tile); |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
264 int dest = GetLiftDestination(tile) * 6; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
265 pos += (pos < dest) ? 1 : -1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
266 SetLiftPosition(tile, pos); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
267 |
9006
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
268 if (pos == dest) { |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
269 HaltLift(tile); |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
270 DeleteAnimatedTile(tile); |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
271 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
272 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
273 MarkTileDirtyByTile(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
274 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
275 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
276 /** |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
277 * Determines if a town is close to a tile |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
278 * @param tile TileIndex of the tile to query |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
279 * @param dist maximum distance to be accepted |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
280 * @returns true if the tile correspond to the distance criteria |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
281 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
282 static bool IsCloseToTown(TileIndex tile, uint dist) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
283 { |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
284 const Town *t; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
285 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
286 FOR_ALL_TOWNS(t) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
287 if (DistanceManhattan(tile, t->xy) < dist) return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
288 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
289 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
290 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
291 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
292 /** |
7545
a84d70ad7876
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents:
7500
diff
changeset
|
293 * Marks the town sign as needing a repaint. |
a84d70ad7876
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents:
7500
diff
changeset
|
294 * |
a84d70ad7876
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents:
7500
diff
changeset
|
295 * This function marks the area of the sign of a town as dirty for repaint. |
a84d70ad7876
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents:
7500
diff
changeset
|
296 * |
a84d70ad7876
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents:
7500
diff
changeset
|
297 * @param t Town requesting town sign for repaint |
a84d70ad7876
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents:
7500
diff
changeset
|
298 * @ingroup dirty |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
299 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
300 static void MarkTownSignDirty(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
301 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
302 MarkAllViewportsDirty( |
6491
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6486
diff
changeset
|
303 t->sign.left - 6, |
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6486
diff
changeset
|
304 t->sign.top - 3, |
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6486
diff
changeset
|
305 t->sign.left + t->sign.width_1 * 4 + 12, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
306 t->sign.top + 45 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
307 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
308 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
309 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
310 /** |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
311 * Resize the sign(label) of the town after changes in |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
312 * population (creation or growth or else) |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
313 * @param t Town to update |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
314 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
315 void UpdateTownVirtCoord(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
316 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
317 MarkTownSignDirty(t); |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
318 Point pt = RemapCoords2(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
319 SetDParam(0, t->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
320 SetDParam(1, t->population); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
321 UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24, |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
322 _settings_client.gui.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
323 MarkTownSignDirty(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
324 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
325 |
7969
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
326 /** Update the virtual coords needed to draw the town sign for all towns. */ |
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
327 void UpdateAllTownVirtCoords() |
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
328 { |
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
329 Town *t; |
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
330 FOR_ALL_TOWNS(t) { |
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
331 UpdateTownVirtCoord(t); |
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
332 } |
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
333 } |
3f7b82356f85
(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 <rubidium@openttd.org>
parents:
7967
diff
changeset
|
334 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
335 /** |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
336 * Change the towns population |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
337 * @param t Town which polulation has changed |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
338 * @param mod polulation change (can be positive or negative) |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
339 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
340 static void ChangePopulation(Town *t, int mod) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
341 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
342 t->population += mod; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
343 InvalidateWindow(WC_TOWN_VIEW, t->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
344 UpdateTownVirtCoord(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
345 |
9387
a240dd49a2e8
(svn r13297) -Codechange: Use GUIList for the town directory window
peter1138 <peter1138@openttd.org>
parents:
9358
diff
changeset
|
346 InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
347 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
348 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
349 /** |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
350 * Determines the world population |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
351 * Basically, count population of all towns, one by one |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
352 * @return uint32 the calculated population of the world |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
353 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
354 uint32 GetWorldPopulation() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
355 { |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
356 uint32 pop = 0; |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
357 const Town *t; |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
358 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
359 FOR_ALL_TOWNS(t) pop += t->population; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
360 return pop; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
361 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
362 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
363 /** |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
364 * Helper function for house completion stages progression |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
365 * @param tile TileIndex of the house (or parts of it) to "grow" |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
366 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
367 static void MakeSingleHouseBigger(TileIndex tile) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
368 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
369 assert(IsTileType(tile, MP_HOUSE)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
370 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
371 /* means it is completed, get out. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
372 if (LiftHasDestination(tile)) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
373 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
374 /* progress in construction stages */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
375 IncHouseConstructionTick(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
376 if (GetHouseConstructionTick(tile) != 0) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
377 |
9018
9dcf32675eb5
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents:
9006
diff
changeset
|
378 const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
9dcf32675eb5
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents:
9006
diff
changeset
|
379 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
380 /* Check and/or */ |
9018
9dcf32675eb5
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents:
9006
diff
changeset
|
381 if (HasBit(hs->callback_mask, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE)) { |
7215
ba8faf180ec2
(svn r10493) -Codechange: update some callback ID enums to reflect their changed usage, add a few and update the comments.
rubidium <rubidium@openttd.org>
parents:
7139
diff
changeset
|
382 uint16 callback_res = GetHouseCallback(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
9018
9dcf32675eb5
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents:
9006
diff
changeset
|
383 if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(hs->grffile, tile, callback_res); |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
384 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
386 if (IsHouseCompleted(tile)) { |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
387 /* Now that construction is complete, we can add the population of the |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
388 * building to the town. */ |
9018
9dcf32675eb5
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium <rubidium@openttd.org>
parents:
9006
diff
changeset
|
389 ChangePopulation(GetTownByTile(tile), hs->population); |
10360
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
390 ResetHouseAge(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
391 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
392 MarkTileDirtyByTile(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
393 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
394 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
395 /** Make the house advance in its construction stages until completion |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
396 * @param tile TileIndex of house |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
397 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
398 static void MakeTownHouseBigger(TileIndex tile) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
399 { |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
400 uint flags = GetHouseSpecs(GetHouseType(tile))->building_flags; |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
401 if (flags & BUILDING_HAS_1_TILE) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0)); |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
402 if (flags & BUILDING_2_TILES_Y) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1)); |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
403 if (flags & BUILDING_2_TILES_X) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0)); |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
404 if (flags & BUILDING_HAS_4_TILES) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
405 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
406 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
407 /** |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
408 * Tile callback function. |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
409 * |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
410 * Periodic tic handler for houses and town |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
411 * @param tile been asked to do its stuff |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
412 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
413 static void TileLoop_Town(TileIndex tile) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
414 { |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
415 HouseID house_id = GetHouseType(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
416 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
417 /* NewHouseTileLoop returns false if Callback 21 succeeded, i.e. the house |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
418 * doesn't exist any more, so don't continue here. */ |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
419 if (house_id >= NEW_HOUSE_OFFSET && !NewHouseTileLoop(tile)) return; |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
420 |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
421 if (!IsHouseCompleted(tile)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
422 /* Construction is not completed. See if we can go further in construction*/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 MakeTownHouseBigger(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
424 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
425 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
426 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
427 const HouseSpec *hs = GetHouseSpecs(house_id); |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
428 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
429 /* If the lift has a destination, it is already an animated tile. */ |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
430 if ((hs->building_flags & BUILDING_IS_ANIMATED) && |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
431 house_id < NEW_HOUSE_OFFSET && |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
432 !LiftHasDestination(tile) && |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
433 Chance16(1, 2)) { |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
434 AddAnimatedTile(tile); |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
435 } |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
436 |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
437 Town *t = GetTownByTile(tile); |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
438 uint32 r = Random(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
439 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7903
diff
changeset
|
440 if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) { |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
441 for (uint i = 0; i < 256; i++) { |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
442 uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, r, house_id, t, tile); |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
443 |
8287
988d9721ef31
(svn r11851) -Codechange: A few magic numbers removal, plus a little code style
belugas <belugas@openttd.org>
parents:
8268
diff
changeset
|
444 if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break; |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
445 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
446 CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grffile); |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
447 if (cargo == CT_INVALID) continue; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
448 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
449 uint amt = GB(callback, 0, 8); |
11874
1091625b3d21
(svn r16268) -Fix (r9876): When callback 2E returns an amount of 0, do not transport 1 unit to the station.
frosch <frosch@openttd.org>
parents:
11757
diff
changeset
|
450 if (amt == 0) continue; |
1091625b3d21
(svn r16268) -Fix (r9876): When callback 2E returns an amount of 0, do not transport 1 unit to the station.
frosch <frosch@openttd.org>
parents:
11757
diff
changeset
|
451 |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
452 uint moved = MoveGoodsToStation(tile, 1, 1, cargo, amt); |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
453 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
454 const CargoSpec *cs = GetCargo(cargo); |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
455 switch (cs->town_effect) { |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
456 case TE_PASSENGERS: |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
457 t->new_max_pass += amt; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
458 t->new_act_pass += moved; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
459 break; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
460 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
461 case TE_MAIL: |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
462 t->new_max_mail += amt; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
463 t->new_act_mail += moved; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
464 break; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
465 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
466 default: |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
467 break; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
468 } |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
469 } |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
470 } else { |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
471 if (GB(r, 0, 8) < hs->population) { |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
472 uint amt = GB(r, 0, 8) / 8 + 1; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
473 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
474 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
475 t->new_max_pass += amt; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
476 t->new_act_pass += MoveGoodsToStation(tile, 1, 1, CT_PASSENGERS, amt); |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
477 } |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
478 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
479 if (GB(r, 8, 8) < hs->mail_generation) { |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
480 uint amt = GB(r, 8, 8) / 8 + 1; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
481 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
482 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
483 t->new_max_mail += amt; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
484 t->new_act_mail += MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt); |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
485 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
486 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
487 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
488 _current_company = OWNER_TOWN; |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
489 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
490 if (hs->building_flags & BUILDING_HAS_1_TILE && |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7903
diff
changeset
|
491 HasBit(t->flags12, TOWN_IS_FUNDED) && |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
492 CanDeleteHouse(tile) && |
10360
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
493 GetHouseAge(tile) >= hs->minimum_life && |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
494 --t->time_until_rebuild == 0) { |
6454
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
495 t->time_until_rebuild = GB(r, 16, 8) + 192; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
496 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
497 ClearTownHouse(t, tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
498 |
6454
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
499 /* Rebuild with another house? */ |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
500 if (GB(r, 24, 8) >= 12) BuildTownHouse(t, tile); |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
501 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
502 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
503 _current_company = OWNER_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
504 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
505 |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
506 /** |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
507 * Dummy tile callback function for handling tile clicks in towns |
6534
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
508 * @param tile unused |
6cfb1cd027f8
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents:
6525
diff
changeset
|
509 */ |
10532
d33755b6159a
(svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
510 static bool ClickTile_Town(TileIndex tile) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
511 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
512 /* not used */ |
10532
d33755b6159a
(svn r14789) -Feature: allow scrolling with the left mouse button pressed (if enabled). Primarily useful for systems with touch screen (aapo)
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
513 return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
514 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
515 |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
516 static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
517 { |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
518 if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED); |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
519 if (!CanDeleteHouse(tile)) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
520 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
521 const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
522 |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
523 CommandCost cost(EXPENSES_CONSTRUCTION); |
9463
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
524 cost.AddCost(hs->GetRemovalCost()); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
525 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
526 int rating = hs->remove_rating_decrease; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
527 _cleared_town_rating += rating; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
528 Town *t = _cleared_town = GetTownByTile(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
529 |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
530 if (Company::IsValidID(_current_company)) { |
11103
5980315ec1f3
(svn r15449) -Codechange: Rename DC_NO_TOWN_RATING to DC_NO_TEST_TOWN_RATING as that is what it does.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
531 if (rating > t->ratings[_current_company] && !(flags & DC_NO_TEST_TOWN_RATING) && !_cheats.magic_bulldozer.value) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
532 SetDParam(0, t->index); |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
533 return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
534 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
535 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
536 |
11106
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
537 ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM, flags); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
538 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
539 ClearTownHouse(t, tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
540 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
541 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
542 return cost; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
543 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
544 |
8846
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
545 static void GetProducedCargo_Town(TileIndex tile, CargoID *b) |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
546 { |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
547 HouseID house_id = GetHouseType(tile); |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
548 const HouseSpec *hs = GetHouseSpecs(house_id); |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
549 Town *t = GetTownByTile(tile); |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
550 |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
551 if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) { |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
552 for (uint i = 0; i < 256; i++) { |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
553 uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, 0, house_id, t, tile); |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
554 |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
555 if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break; |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
556 |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
557 CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grffile); |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
558 |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
559 if (cargo == CT_INVALID) continue; |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
560 *(b++) = cargo; |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
561 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
562 } else { |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
563 if (hs->population > 0) { |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
564 *(b++) = CT_PASSENGERS; |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
565 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
566 if (hs->mail_generation > 0) { |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
567 *(b++) = CT_MAIL; |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
568 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
569 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
570 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
571 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
572 static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
573 { |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
574 const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
6525
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
575 CargoID accepts[3]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
576 |
6525
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
577 /* Set the initial accepted cargo types */ |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
578 for (uint8 i = 0; i < lengthof(accepts); i++) { |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
579 accepts[i] = hs->accepts_cargo[i]; |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
580 } |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
581 |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
582 /* Check for custom accepted cargo types */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7903
diff
changeset
|
583 if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) { |
6642
1e9b34ce8000
(svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138 <peter1138@openttd.org>
parents:
6629
diff
changeset
|
584 uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
6525
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
585 if (callback != CALLBACK_FAILED) { |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
586 /* Replace accepted cargo types with translated values from callback */ |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
587 accepts[0] = GetCargoTranslation(GB(callback, 0, 5), hs->grffile); |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
588 accepts[1] = GetCargoTranslation(GB(callback, 5, 5), hs->grffile); |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
589 accepts[2] = GetCargoTranslation(GB(callback, 10, 5), hs->grffile); |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
590 } |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
591 } |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
592 |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
593 /* Check for custom cargo acceptance */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7903
diff
changeset
|
594 if (HasBit(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) { |
6642
1e9b34ce8000
(svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138 <peter1138@openttd.org>
parents:
6629
diff
changeset
|
595 uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
6525
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
596 if (callback != CALLBACK_FAILED) { |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
597 if (accepts[0] != CT_INVALID) ac[accepts[0]] = GB(callback, 0, 4); |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
598 if (accepts[1] != CT_INVALID) ac[accepts[1]] = GB(callback, 4, 4); |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
599 if (_settings_game.game_creation.landscape != LT_TEMPERATE && HasBit(callback, 12)) { |
6525
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
600 /* The 'S' bit indicates food instead of goods */ |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
601 ac[CT_FOOD] = GB(callback, 8, 4); |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
602 } else { |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
603 if (accepts[2] != CT_INVALID) ac[accepts[2]] = GB(callback, 8, 4); |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
604 } |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
605 return; |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
606 } |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
607 } |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
608 |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
609 /* No custom acceptance, so fill in with the default values */ |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
610 for (uint8 i = 0; i < lengthof(accepts); i++) { |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
611 if (accepts[i] != CT_INVALID) ac[accepts[i]] = hs->cargo_acceptance[i]; |
309fb9068af9
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents:
6491
diff
changeset
|
612 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
613 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
614 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
615 static void GetTileDesc_Town(TileIndex tile, TileDesc *td) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
616 { |
10837
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
617 const HouseID house = GetHouseType(tile); |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
618 const HouseSpec *hs = GetHouseSpecs(house); |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
619 bool house_completed = IsHouseCompleted(tile); |
9714
cb9766ae1255
(svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz <smatz@openttd.org>
parents:
9659
diff
changeset
|
620 |
cb9766ae1255
(svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz <smatz@openttd.org>
parents:
9659
diff
changeset
|
621 td->str = hs->building_name; |
10837
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
622 |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
623 uint16 callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, GetTownByTile(tile), tile); |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
624 if (callback_res != CALLBACK_FAILED) { |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
625 StringID new_name = GetGRFStringID(hs->grffile->grfid, 0xD000 + callback_res); |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
626 if (new_name != STR_NULL && new_name != STR_UNDEFINED) { |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
627 td->str = new_name; |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
628 } |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
629 } |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
630 |
191f10c27915
(svn r15172) -Feature: Allow a grf to customize house name via callback 0x14D, during Tile Inquiry process
belugas <belugas@openttd.org>
parents:
10814
diff
changeset
|
631 if (!house_completed) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
632 SetDParamX(td->dparam, 0, td->str); |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
633 td->str = STR_TOWN_DESCRIPTION_UNDER_CONSTRUCTION; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
634 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
635 |
9714
cb9766ae1255
(svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz <smatz@openttd.org>
parents:
9659
diff
changeset
|
636 if (hs->grffile != NULL) { |
cb9766ae1255
(svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz <smatz@openttd.org>
parents:
9659
diff
changeset
|
637 const GRFConfig *gc = GetGRFConfig(hs->grffile->grfid); |
cb9766ae1255
(svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz <smatz@openttd.org>
parents:
9659
diff
changeset
|
638 td->grf = gc->name; |
cb9766ae1255
(svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz <smatz@openttd.org>
parents:
9659
diff
changeset
|
639 } |
cb9766ae1255
(svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz <smatz@openttd.org>
parents:
9659
diff
changeset
|
640 |
9322
258ab31489e0
(svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch <frosch@openttd.org>
parents:
9234
diff
changeset
|
641 td->owner[0] = OWNER_TOWN; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
642 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
643 |
8616
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8596
diff
changeset
|
644 static TrackStatus GetTileTrackStatus_Town(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
645 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
646 /* not used */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
647 return 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
648 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
649 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
650 static void ChangeTileOwner_Town(TileIndex tile, Owner old_owner, Owner new_owner) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
651 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
652 /* not used */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
653 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
654 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
655 static bool GrowTown(Town *t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
656 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
657 static void TownTickHandler(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
658 { |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7903
diff
changeset
|
659 if (HasBit(t->flags12, TOWN_IS_FUNDED)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
660 int i = t->grow_counter - 1; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
661 if (i < 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
662 if (GrowTown(t)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
663 i = t->growth_rate; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
664 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
665 i = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
666 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
667 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
668 t->grow_counter = i; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
669 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
670 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
671 UpdateTownRadius(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
672 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
673 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
674 void OnTick_Town() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
675 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
676 if (_game_mode == GM_EDITOR) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
677 |
11926
dd6202262c94
(svn r16329) -Fix: possible desync when removing lots of towns in-game (not that we allow removing towns now, but better not have desync prone code lingering around)
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
678 Town *t; |
dd6202262c94
(svn r16329) -Fix: possible desync when removing lots of towns in-game (not that we allow removing towns now, but better not have desync prone code lingering around)
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
679 FOR_ALL_TOWNS(t) { |
dd6202262c94
(svn r16329) -Fix: possible desync when removing lots of towns in-game (not that we allow removing towns now, but better not have desync prone code lingering around)
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
680 /* Run town tick at regular intervals, but not all at once. */ |
dd6202262c94
(svn r16329) -Fix: possible desync when removing lots of towns in-game (not that we allow removing towns now, but better not have desync prone code lingering around)
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
681 if ((_tick_counter + t->index) % TOWN_GROWTH_FREQUENCY == 0) { |
dd6202262c94
(svn r16329) -Fix: possible desync when removing lots of towns in-game (not that we allow removing towns now, but better not have desync prone code lingering around)
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
682 TownTickHandler(t); |
dd6202262c94
(svn r16329) -Fix: possible desync when removing lots of towns in-game (not that we allow removing towns now, but better not have desync prone code lingering around)
rubidium <rubidium@openttd.org>
parents:
11924
diff
changeset
|
683 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
684 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
685 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
686 |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
687 /** |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
688 * Return the RoadBits of a tile |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
689 * |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
690 * @note There are many other functions doing things like that. |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
691 * @note Needs to be checked for needlessness. |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
692 * @param tile The tile we want to analyse |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
693 * @return The roadbits of the given tile |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
694 */ |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
695 static RoadBits GetTownRoadBits(TileIndex tile) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
696 { |
6661
5850ac8865e8
(svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium <rubidium@openttd.org>
parents:
6645
diff
changeset
|
697 TrackBits b = GetAnyRoadTrackBits(tile, ROADTYPE_ROAD); |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
698 RoadBits r = ROAD_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
699 |
7225
2d9785c79784
(svn r10504) -Codechange: Shorten the test if no track bit has been found
belugas <belugas@openttd.org>
parents:
7215
diff
changeset
|
700 if (b == TRACK_BIT_NONE) return r; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
701 if (b & TRACK_BIT_X) r |= ROAD_X; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
702 if (b & TRACK_BIT_Y) r |= ROAD_Y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
703 if (b & TRACK_BIT_UPPER) r |= ROAD_NE | ROAD_NW; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
704 if (b & TRACK_BIT_LOWER) r |= ROAD_SE | ROAD_SW; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
705 if (b & TRACK_BIT_LEFT) r |= ROAD_NW | ROAD_SW; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
706 if (b & TRACK_BIT_RIGHT) r |= ROAD_NE | ROAD_SE; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
707 return r; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
708 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
709 |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
710 /** |
11041
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
711 * Check for parallel road inside a given distance. |
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
712 * Assuming a road from (tile - TileOffsByDiagDir(dir)) to tile, |
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
713 * is there a parallel road left or right of it within distance dist_multi? |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
714 * |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
715 * @param tile curent tile |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
716 * @param dir target direction |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
717 * @param dist_multi distance multiplyer |
11041
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
718 * @return true if there is a parallel road |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
719 */ |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
720 static bool IsNeighborRoadTile(TileIndex tile, const DiagDirection dir, uint dist_multi) |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
721 { |
11040
d2bb0a7656eb
(svn r15380) -Fix (r15190)[FS#2603]: Do not use TileY() on negative TileIndexDiffs. But the test was not needed anyway, as those tiles were already tested in previous iterations.
frosch <frosch@openttd.org>
parents:
11012
diff
changeset
|
722 if (!IsValidTile(tile)) return false; |
d2bb0a7656eb
(svn r15380) -Fix (r15190)[FS#2603]: Do not use TileY() on negative TileIndexDiffs. But the test was not needed anyway, as those tiles were already tested in previous iterations.
frosch <frosch@openttd.org>
parents:
11012
diff
changeset
|
723 |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
724 /* Lookup table for the used diff values */ |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
725 const TileIndexDiff tid_lt[3] = { |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
726 TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT)), |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
727 TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT)), |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
728 TileOffsByDiagDir(ReverseDiagDir(dir)), |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
729 }; |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
730 |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
731 dist_multi = (dist_multi + 1) * 4; |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
732 for (uint pos = 4; pos < dist_multi; pos++) { |
11041
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
733 /* Go (pos / 4) tiles to the left or the right */ |
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
734 TileIndexDiff cur = tid_lt[(pos & 1) ? 0 : 1] * (pos / 4); |
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
735 |
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
736 /* Use the current tile as origin, or go one tile backwards */ |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
737 if (pos & 2) cur += tid_lt[2]; |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
738 |
11041
87ec8ab495b0
(svn r15381) -Fix (r11091): When testing for parallel road two tiles away, do not move more than one tile along the road.
frosch <frosch@openttd.org>
parents:
11040
diff
changeset
|
739 /* Test for roadbit parallel to dir and facing towards the middle axis */ |
11040
d2bb0a7656eb
(svn r15380) -Fix (r15190)[FS#2603]: Do not use TileY() on negative TileIndexDiffs. But the test was not needed anyway, as those tiles were already tested in previous iterations.
frosch <frosch@openttd.org>
parents:
11012
diff
changeset
|
740 if (IsValidTile(tile + cur) && |
d2bb0a7656eb
(svn r15380) -Fix (r15190)[FS#2603]: Do not use TileY() on negative TileIndexDiffs. But the test was not needed anyway, as those tiles were already tested in previous iterations.
frosch <frosch@openttd.org>
parents:
11012
diff
changeset
|
741 GetTownRoadBits(TILE_ADD(tile, cur)) & DiagDirToRoadBits((pos & 2) ? dir : ReverseDiagDir(dir))) return true; |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
742 } |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
743 return false; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
744 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
745 |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
746 /** |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
747 * Check if a Road is allowed on a given tile |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
748 * |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
749 * @param t The current town |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
750 * @param tile The target tile |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
751 * @param dir The direction in which we want to extend the town |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
752 * @return true if it is allowed else false |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
753 */ |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
754 static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
755 { |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
756 if (TileX(tile) < 2 || TileX(tile) >= MapMaxX() || TileY(tile) < 2 || TileY(tile) >= MapMaxY()) return false; |
6993
1e527dc3c219
(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 <rubidium@openttd.org>
parents:
6956
diff
changeset
|
757 |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
758 Slope cur_slope, desired_slope; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
759 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
760 for (;;) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
761 /* Check if there already is a road at this point? */ |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
762 if (GetTownRoadBits(tile) == ROAD_NONE) { |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
763 /* No, try if we are able to build a road piece there. |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
764 * If that fails clear the land, and if that fails exit. |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
765 * This is to make sure that we can build a road here later. */ |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
766 if (CmdFailed(DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) && |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
767 CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
768 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
769 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
770 |
11108
bbb79ca77fce
(svn r15454) -Fix [FS#2614]: towns did not know about build_on_slopes in some cases, or made decisions on the 'original' slope instead the slope after applying the foundation..
rubidium <rubidium@openttd.org>
parents:
11106
diff
changeset
|
771 cur_slope = _settings_game.construction.build_on_slopes ? GetFoundationSlope(tile, NULL) : GetTileSlope(tile, NULL); |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
772 if (cur_slope == SLOPE_FLAT) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
773 no_slope: |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
774 /* Tile has no slope */ |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
775 switch (t->layout) { |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
776 default: NOT_REACHED(); |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
777 |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
778 case TL_ORIGINAL: // Disallow the road if any neighboring tile has a road (distance: 1) |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
779 return !IsNeighborRoadTile(tile, dir, 1); |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
780 |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
781 case TL_BETTER_ROADS: // Disallow the road if any neighboring tile has a road (distance: 1 and 2). |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
782 return !IsNeighborRoadTile(tile, dir, 2); |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
783 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
784 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
785 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
786 /* If the tile is not a slope in the right direction, then |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
787 * maybe terraform some. */ |
7885
db330f75b899
(svn r11436) -Fix [FS#1439]: Towns would not build roads on slopes. Patch by divide.
rubidium <rubidium@openttd.org>
parents:
7880
diff
changeset
|
788 desired_slope = (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? SLOPE_NW : SLOPE_NE; |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
789 if (desired_slope != cur_slope && ComplementSlope(desired_slope) != cur_slope) { |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
790 if (Chance16(1, 8)) { |
7766
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
791 CommandCost res = CMD_ERROR; |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
792 if (!_generating_world && Chance16(1, 10)) { |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
793 /* Note: Do not replace "^ SLOPE_ELEVATED" with ComplementSlope(). The slope might be steep. */ |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
794 res = DoCommand(tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0, |
7766
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
795 DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
796 } |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
797 if (CmdFailed(res) && Chance16(1, 3)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
798 /* We can consider building on the slope, though. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
799 goto no_slope; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
800 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
801 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
802 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
803 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
804 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
805 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
806 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
807 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
808 static bool TerraformTownTile(TileIndex tile, int edges, int dir) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
809 { |
11231
1b7daea82ad7
(svn r15585) -Codechange: Remove TILE_ASSERT and replace all instances with assert(tile < MapSize()).
yexo <yexo@openttd.org>
parents:
11230
diff
changeset
|
810 assert(tile < MapSize()); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
811 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
812 CommandCost r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
8818
57a0d6670e05
(svn r12564) -Fix: towns couldn't terraform when inflation rised terraform prices enough
smatz <smatz@openttd.org>
parents:
8816
diff
changeset
|
813 if (CmdFailed(r) || r.GetCost() >= (_price.terraform + 2) * 8) return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
814 DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
815 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
816 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
817 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
818 static void LevelTownLand(TileIndex tile) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
819 { |
11231
1b7daea82ad7
(svn r15585) -Codechange: Remove TILE_ASSERT and replace all instances with assert(tile < MapSize()).
yexo <yexo@openttd.org>
parents:
11230
diff
changeset
|
820 assert(tile < MapSize()); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
821 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
822 /* Don't terraform if land is plain or if there's a house there. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
823 if (IsTileType(tile, MP_HOUSE)) return; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
824 Slope tileh = GetTileSlope(tile, NULL); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
825 if (tileh == SLOPE_FLAT) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
826 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
827 /* First try up, then down */ |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
828 if (!TerraformTownTile(tile, ~tileh & SLOPE_ELEVATED, 1)) { |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
829 TerraformTownTile(tile, tileh & SLOPE_ELEVATED, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
830 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
831 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
832 |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
833 /** |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
834 * Generate the RoadBits of a grid tile |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
835 * |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
836 * @param t current town |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
837 * @param tile tile in reference to the town |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
838 * @param dir The direction to which we are growing ATM |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
839 * @return the RoadBit of the current tile regarding |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
840 * the selected town layout |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
841 */ |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
842 static RoadBits GetTownRoadGridElement(Town *t, TileIndex tile, DiagDirection dir) |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
843 { |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
844 /* align the grid to the downtown */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
845 TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile); // Vector from downtown to the tile |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
846 RoadBits rcmd = ROAD_NONE; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
847 |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
848 switch (t->layout) { |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
849 default: NOT_REACHED(); |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
850 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
851 case TL_2X2_GRID: |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
852 if ((grid_pos.x % 3) == 0) rcmd |= ROAD_Y; |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
853 if ((grid_pos.y % 3) == 0) rcmd |= ROAD_X; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
854 break; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
855 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
856 case TL_3X3_GRID: |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
857 if ((grid_pos.x % 4) == 0) rcmd |= ROAD_Y; |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
858 if ((grid_pos.y % 4) == 0) rcmd |= ROAD_X; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
859 break; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
860 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
861 |
7603
52839687a631
(svn r11130) -Fix [FS#1207]: towns build roads that weren't connected to any other road.
rubidium <rubidium@openttd.org>
parents:
7582
diff
changeset
|
862 /* Optimise only X-junctions */ |
7766
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
863 if (rcmd != ROAD_ALL) return rcmd; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
864 |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
865 RoadBits rb_template; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
866 |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
867 switch (GetTileSlope(tile, NULL)) { |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
868 default: rb_template = ROAD_ALL; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
869 case SLOPE_W: rb_template = ROAD_NW | ROAD_SW; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
870 case SLOPE_SW: rb_template = ROAD_Y | ROAD_SW; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
871 case SLOPE_S: rb_template = ROAD_SW | ROAD_SE; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
872 case SLOPE_SE: rb_template = ROAD_X | ROAD_SE; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
873 case SLOPE_E: rb_template = ROAD_SE | ROAD_NE; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
874 case SLOPE_NE: rb_template = ROAD_Y | ROAD_NE; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
875 case SLOPE_N: rb_template = ROAD_NE | ROAD_NW; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
876 case SLOPE_NW: rb_template = ROAD_X | ROAD_NW; break; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
877 case SLOPE_STEEP_W: |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
878 case SLOPE_STEEP_S: |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
879 case SLOPE_STEEP_E: |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
880 case SLOPE_STEEP_N: |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
881 rb_template = ROAD_NONE; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
882 break; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
883 } |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
884 |
7766
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
885 /* Stop if the template is compatible to the growth dir */ |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
886 if (DiagDirToRoadBits(ReverseDiagDir(dir)) & rb_template) return rb_template; |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
887 /* If not generate a straight road in the direction of the growth */ |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
888 return DiagDirToRoadBits(dir) | DiagDirToRoadBits(ReverseDiagDir(dir)); |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
889 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
890 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
891 /** |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
892 * Grows the town with an extra house. |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
893 * Check if there are enough neighbor house tiles |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
894 * next to the current tile. If there are enough |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
895 * add another house. |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
896 * |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
897 * @param t The current town |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
898 * @param tile The target tile for the extra house |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
899 * @return true if an extra house has been added |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
900 */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
901 static bool GrowTownWithExtraHouse(Town *t, TileIndex tile) |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
902 { |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
903 /* We can't look further than that. */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
904 if (TileX(tile) < 2 || TileY(tile) < 2 || MapMaxX() <= TileX(tile) || MapMaxY() <= TileY(tile)) return false; |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
905 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
906 uint counter = 0; // counts the house neighbor tiles |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
907 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
908 /* Check the tiles E,N,W and S of the current tile for houses */ |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
909 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
910 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
911 if (IsTileType(TileAddByDiagDir(tile, dir), MP_HOUSE)) counter++; |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
912 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
913 /* If there are enough neighbors stop here */ |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
914 if (counter >= 3) { |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
915 if (BuildTownHouse(t, tile)) { |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
916 _grow_town_result = GROWTH_SUCCEED; |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
917 return true; |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
918 } |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
919 return false; |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
920 } |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
921 } |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
922 return false; |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
923 } |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
924 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
925 /** |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
926 * Grows the town with a road piece. |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
927 * |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
928 * @param t The current town |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
929 * @param tile The current tile |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
930 * @param rcmd The RoadBits we want to build on the tile |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
931 * @return true if the RoadBits have been added else false |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
932 */ |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
933 static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd) |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
934 { |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
935 if (CmdSucceeded(DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) { |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
936 _grow_town_result = GROWTH_SUCCEED; |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
937 return true; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
938 } |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
939 return false; |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
940 } |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
941 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
942 /** |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
943 * Grows the town with a bridge. |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
944 * At first we check if a bridge is reasonable. |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
945 * If so we check if we are able to build it. |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
946 * |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
947 * @param t The current town |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
948 * @param tile The current tile |
7845
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
949 * @param bridge_dir The valid direction in which to grow a bridge |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
950 * @return true if a bridge has been build else false |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
951 */ |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
952 static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDirection bridge_dir) |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
953 { |
7845
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
954 assert(bridge_dir < DIAGDIR_END); |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
955 |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
956 const Slope slope = GetTileSlope(tile, NULL); |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
957 if (slope == SLOPE_FLAT) return false; // no slope, no bridge |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
958 |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
959 /* Make sure the direction is compatible with the slope. |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
960 * Well we check if the slope has an up bit set in the |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
961 * reverse direction. */ |
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
962 if (HASBITS(slope, InclinedSlope(bridge_dir))) return false; |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
963 |
7847
066ed17e3036
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight <truelight@openttd.org>
parents:
7845
diff
changeset
|
964 /* Assure that the bridge is connectable to the start side */ |
066ed17e3036
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight <truelight@openttd.org>
parents:
7845
diff
changeset
|
965 if (!(GetTownRoadBits(TileAddByDiagDir(tile, ReverseDiagDir(bridge_dir))) & DiagDirToRoadBits(bridge_dir))) return false; |
066ed17e3036
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight <truelight@openttd.org>
parents:
7845
diff
changeset
|
966 |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
967 /* We are in the right direction */ |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
968 uint8 bridge_length = 0; // This value stores the length of the possible bridge |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
969 TileIndex bridge_tile = tile; // Used to store the other waterside |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
970 |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
971 const int delta = TileOffsByDiagDir(bridge_dir); |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
972 do { |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
973 if (bridge_length++ >= 11) { |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
974 /* Max 11 tile long bridges */ |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
975 return false; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
976 } |
7871
8dad3ff6a7a7
(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 <rubidium@openttd.org>
parents:
7849
diff
changeset
|
977 bridge_tile += delta; |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
978 } while (TileX(bridge_tile) != 0 && TileY(bridge_tile) != 0 && IsWaterTile(bridge_tile)); |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
979 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
980 /* no water tiles in between? */ |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
981 if (bridge_length == 1) return false; |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
982 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
983 for (uint8 times = 0; times <= 22; times++) { |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
984 byte bridge_type = RandomRange(MAX_BRIDGES - 1); |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
985 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
986 /* Can we actually build the bridge? */ |
10149
a2f36a7cdcf4
(svn r14335) -Codechange: Remove some magic numbers.
frosch <frosch@openttd.org>
parents:
10148
diff
changeset
|
987 if (CmdSucceeded(DoCommand(tile, bridge_tile, bridge_type | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, DC_AUTO, CMD_BUILD_BRIDGE))) { |
a2f36a7cdcf4
(svn r14335) -Codechange: Remove some magic numbers.
frosch <frosch@openttd.org>
parents:
10148
diff
changeset
|
988 DoCommand(tile, bridge_tile, bridge_type | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE); |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
989 _grow_town_result = GROWTH_SUCCEED; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
990 return true; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
991 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
992 } |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
993 /* Quit if it selecting an appropiate bridge type fails a large number of times. */ |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
994 return false; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
995 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
996 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
997 /** |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
998 * Grows the given town. |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
999 * There are at the moment 3 possible way's for |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1000 * the town expansion: |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1001 * @li Generate a random tile and check if there is a road allowed |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1002 * @li TL_ORIGINAL |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1003 * @li TL_BETTER_ROADS |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1004 * @li Check if the town geometry allows a road and which one |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1005 * @li TL_2X2_GRID |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1006 * @li TL_3X3_GRID |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1007 * @li Forbid roads, only build houses |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1008 * |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1009 * @param tile_ptr The current tile |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1010 * @param cur_rb The current tiles RoadBits |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1011 * @param target_dir The target road dir |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1012 * @param t1 The current town |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1013 */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1014 static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1015 { |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1016 RoadBits rcmd = ROAD_NONE; // RoadBits for the road construction command |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1017 TileIndex tile = *tile_ptr; // The main tile on which we base our growth |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1018 |
11231
1b7daea82ad7
(svn r15585) -Codechange: Remove TILE_ASSERT and replace all instances with assert(tile < MapSize()).
yexo <yexo@openttd.org>
parents:
11230
diff
changeset
|
1019 assert(tile < MapSize()); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1020 |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1021 if (cur_rb == ROAD_NONE) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1022 /* Tile has no road. First reset the status counter |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1023 * to say that this is the last iteration. */ |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
1024 _grow_town_result = GROWTH_SEARCH_STOPPED; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1025 |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1026 if (!_settings_game.economy.allow_town_roads && !_generating_world) return; |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1027 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1028 /* Remove hills etc */ |
10191
078112d3e7d9
(svn r14404) -Change [FS#2176]: don't make the town flatten land unconditionally when build on slopes is turned on. Based on a patch by Eddi.
rubidium <rubidium@openttd.org>
parents:
10149
diff
changeset
|
1029 if (!_settings_game.construction.build_on_slopes || Chance16(1, 6)) LevelTownLand(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1030 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1031 /* Is a road allowed here? */ |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1032 switch (t1->layout) { |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1033 default: NOT_REACHED(); |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1034 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1035 case TL_3X3_GRID: |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1036 case TL_2X2_GRID: |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1037 rcmd = GetTownRoadGridElement(t1, tile, target_dir); |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1038 if (rcmd == ROAD_NONE) return; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1039 break; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1040 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1041 case TL_BETTER_ROADS: |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1042 case TL_ORIGINAL: |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
1043 if (!IsRoadAllowedHere(t1, tile, target_dir)) return; |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1044 |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1045 DiagDirection source_dir = ReverseDiagDir(target_dir); |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1046 |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
1047 if (Chance16(1, 4)) { |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1048 /* Randomize a new target dir */ |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1049 do target_dir = RandomDiagDir(); while (target_dir == source_dir); |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1050 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1051 |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
1052 if (!IsRoadAllowedHere(t1, TileAddByDiagDir(tile, target_dir), target_dir)) { |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1053 /* A road is not allowed to continue the randomized road, |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1054 * return if the road we're trying to build is curved. */ |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1055 if (target_dir != ReverseDiagDir(source_dir)) return; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1056 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1057 /* Return if neither side of the new road is a house */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1058 if (!IsTileType(TileAddByDiagDir(tile, ChangeDiagDir(target_dir, DIAGDIRDIFF_90RIGHT)), MP_HOUSE) && |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1059 !IsTileType(TileAddByDiagDir(tile, ChangeDiagDir(target_dir, DIAGDIRDIFF_90LEFT)), MP_HOUSE)) { |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1060 return; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1061 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1062 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1063 /* That means that the road is only allowed if there is a house |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1064 * at any side of the new road. */ |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1065 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1066 |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1067 rcmd = DiagDirToRoadBits(target_dir) | DiagDirToRoadBits(source_dir); |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1068 break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1069 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1070 |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1071 } else if (target_dir < DIAGDIR_END && !(cur_rb & DiagDirToRoadBits(ReverseDiagDir(target_dir)))) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1072 /* Continue building on a partial road. |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1073 * Should be allways OK, so we only generate |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1074 * the fitting RoadBits */ |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
1075 _grow_town_result = GROWTH_SEARCH_STOPPED; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1076 |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1077 if (!_settings_game.economy.allow_town_roads && !_generating_world) return; |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1078 |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1079 switch (t1->layout) { |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1080 default: NOT_REACHED(); |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1081 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1082 case TL_3X3_GRID: |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1083 case TL_2X2_GRID: |
8970
3667cbc7dc1d
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium <rubidium@openttd.org>
parents:
8969
diff
changeset
|
1084 rcmd = GetTownRoadGridElement(t1, tile, target_dir); |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1085 break; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1086 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1087 case TL_BETTER_ROADS: |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1088 case TL_ORIGINAL: |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1089 rcmd = DiagDirToRoadBits(ReverseDiagDir(target_dir)); |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1090 break; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1091 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1092 } else { |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1093 bool allow_house = true; // Value which decides if we want to construct a house |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1094 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1095 /* Reached a tunnel/bridge? Then continue at the other side of it. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1096 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
8088
5d7c61206209
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz <smatz@openttd.org>
parents:
8083
diff
changeset
|
1097 if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) { |
8197
bdb186c8fe93
(svn r11760) -Codechange: unify the way how other end of a tunnel/bridge is determined at some places
smatz <smatz@openttd.org>
parents:
8187
diff
changeset
|
1098 *tile_ptr = GetOtherTunnelBridgeEnd(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1099 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1100 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1101 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1102 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1103 /* Possibly extend the road in a direction. |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1104 * Randomize a direction and if it has a road, bail out. */ |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1105 target_dir = RandomDiagDir(); |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1106 if (cur_rb & DiagDirToRoadBits(target_dir)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1107 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1108 /* This is the tile we will reach if we extend to this direction. */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1109 TileIndex house_tile = TileAddByDiagDir(tile, target_dir); // position of a possible house |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1110 |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1111 /* Don't walk into water. */ |
7739
3387a53e113f
(svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium <rubidium@openttd.org>
parents:
7709
diff
changeset
|
1112 if (IsWaterTile(house_tile)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1113 |
10855
7881d9cd55ab
(svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents:
10837
diff
changeset
|
1114 if (!IsValidTile(house_tile) || !IsValidTile(house_tile + TileOffsByDiagDir(target_dir))) return; |
7881d9cd55ab
(svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents:
10837
diff
changeset
|
1115 |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1116 if (_settings_game.economy.allow_town_roads || _generating_world) { |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1117 switch (t1->layout) { |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1118 default: NOT_REACHED(); |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1119 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11347
diff
changeset
|
1120 case TL_3X3_GRID: // Use 2x2 grid afterwards! |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1121 GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir)); |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1122 /* FALL THROUGH */ |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1123 |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1124 case TL_2X2_GRID: |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1125 rcmd = GetTownRoadGridElement(t1, house_tile, target_dir); |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1126 allow_house = (rcmd == ROAD_NONE); |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1127 break; |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1128 |
11368
82c90cd591ab
(svn r15718) -Cleanup: apply some comment coding style on the rest of the sources too
rubidium <rubidium@openttd.org>
parents:
11347
diff
changeset
|
1129 case TL_BETTER_ROADS: // Use original afterwards! |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1130 GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir)); |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1131 /* FALL THROUGH */ |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1132 |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1133 case TL_ORIGINAL: |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1134 /* Allow a house at the edge. 60% chance or |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1135 * always ok if no road allowed. */ |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1136 rcmd = DiagDirToRoadBits(target_dir); |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1137 allow_house = (!IsRoadAllowedHere(t1, house_tile, target_dir) || Chance16(6, 10)); |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1138 break; |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1139 } |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1140 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1141 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1142 if (allow_house) { |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1143 /* Build a house, but not if there already is a house there. */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1144 if (!IsTileType(house_tile, MP_HOUSE)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1145 /* Level the land if possible */ |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
1146 if (Chance16(1, 6)) LevelTownLand(house_tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1147 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1148 /* And build a house. |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1149 * Set result to -1 if we managed to build it. */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1150 if (BuildTownHouse(t1, house_tile)) { |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
1151 _grow_town_result = GROWTH_SUCCEED; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1152 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1153 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1154 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1155 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1156 |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
1157 _grow_town_result = GROWTH_SEARCH_STOPPED; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1158 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1159 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1160 /* Return if a water tile */ |
7739
3387a53e113f
(svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium <rubidium@openttd.org>
parents:
7709
diff
changeset
|
1161 if (IsWaterTile(tile)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1162 |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1163 /* Make the roads look nicer */ |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1164 rcmd = CleanUpRoadBits(tile, rcmd); |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1165 if (rcmd == ROAD_NONE) return; |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1166 |
7845
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
1167 /* Only use the target direction for bridges to ensure they're connected. |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
1168 * The target_dir is as computed previously according to town layout, so |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
1169 * it will match it perfectly. */ |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
1170 if (GrowTownWithBridge(t1, tile, target_dir)) return; |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1171 |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1172 GrowTownWithRoad(t1, tile, rcmd); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1173 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1174 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1175 /** Returns "growth" if a house was built, or no if the build failed. |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1176 * @param t town to inquiry |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1177 * @param tile to inquiry |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1178 * @return something other than zero(0)if town expansion was possible |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1179 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1180 static int GrowTownAtRoad(Town *t, TileIndex tile) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1181 { |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1182 /* Special case. |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1183 * @see GrowTownInTile Check the else if |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1184 */ |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1185 DiagDirection target_dir = DIAGDIR_END; // The direction in which we want to extend the town |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1186 |
11231
1b7daea82ad7
(svn r15585) -Codechange: Remove TILE_ASSERT and replace all instances with assert(tile < MapSize()).
yexo <yexo@openttd.org>
parents:
11230
diff
changeset
|
1187 assert(tile < MapSize()); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1188 |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1189 /* Number of times to search. |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1190 * Better roads, 2X2 and 3X3 grid grow quite fast so we give |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1191 * them a little handicap. */ |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1192 switch (t->layout) { |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1193 case TL_BETTER_ROADS: |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1194 _grow_town_result = 10 + t->num_houses * 2 / 9; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1195 break; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1196 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1197 case TL_3X3_GRID: |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1198 case TL_2X2_GRID: |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1199 _grow_town_result = 10 + t->num_houses * 1 / 9; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1200 break; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1201 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1202 default: |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1203 _grow_town_result = 10 + t->num_houses * 4 / 9; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1204 break; |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1205 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1206 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1207 do { |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1208 RoadBits cur_rb = GetTownRoadBits(tile); // The RoadBits of the current tile |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1209 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1210 /* Try to grow the town from this point */ |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1211 GrowTownInTile(&tile, cur_rb, target_dir, t); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1212 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1213 /* Exclude the source position from the bitmask |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1214 * and return if no more road blocks available */ |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1215 cur_rb &= ~DiagDirToRoadBits(ReverseDiagDir(target_dir)); |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1216 if (cur_rb == ROAD_NONE) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1217 return _grow_town_result; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1218 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1219 /* Select a random bit from the blockmask, walk a step |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1220 * and continue the search from there. */ |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1221 do target_dir = RandomDiagDir(); while (!(cur_rb & DiagDirToRoadBits(target_dir))); |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1222 tile = TileAddByDiagDir(tile, target_dir); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1223 |
9341
98ef22a4841d
(svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch <frosch@openttd.org>
parents:
9334
diff
changeset
|
1224 if (IsTileType(tile, MP_ROAD) && !IsRoadDepot(tile) && HasTileRoadType(tile, ROADTYPE_ROAD)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1225 /* Don't allow building over roads of other cities */ |
9341
98ef22a4841d
(svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch <frosch@openttd.org>
parents:
9334
diff
changeset
|
1226 if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN) && GetTownByTile(tile) != t) { |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
1227 _grow_town_result = GROWTH_SUCCEED; |
9341
98ef22a4841d
(svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch <frosch@openttd.org>
parents:
9334
diff
changeset
|
1228 } else if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_NONE) && _game_mode == GM_EDITOR) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1229 /* If we are in the SE, and this road-piece has no town owner yet, it just found an |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1230 * owner :) (happy happy happy road now) */ |
9341
98ef22a4841d
(svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch <frosch@openttd.org>
parents:
9334
diff
changeset
|
1231 SetRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1232 SetTownIndex(tile, t->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1233 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1234 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1235 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1236 /* Max number of times is checked. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1237 } while (--_grow_town_result >= 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1238 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1239 return (_grow_town_result == -2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1240 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1241 |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1242 /** |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1243 * Generate a random road block. |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1244 * The probability of a straight road |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1245 * is somewhat higher than a curved. |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1246 * |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1247 * @return A RoadBits value with 2 bits set |
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1248 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
1249 static RoadBits GenRandomRoadBits() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1250 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1251 uint32 r = Random(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1252 uint a = GB(r, 0, 2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1253 uint b = GB(r, 8, 2); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1254 if (a == b) b ^= 2; |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1255 return (RoadBits)((ROAD_NW << a) + (ROAD_NW << b)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1256 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1257 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1258 /** Grow the town |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1259 * @param t town to grow |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1260 * @return true iff a house was built |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1261 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1262 static bool GrowTown(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1263 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1264 static const TileIndexDiffC _town_coord_mod[] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1265 {-1, 0}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1266 { 1, 1}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1267 { 1, -1}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1268 {-1, -1}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1269 {-1, 0}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1270 { 0, 2}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1271 { 2, 0}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1272 { 0, -2}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1273 {-1, -1}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1274 {-2, 2}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1275 { 2, 2}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1276 { 2, -2}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1277 { 0, 0} |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1278 }; |
6571
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1279 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
1280 /* Current "company" is a town */ |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
1281 CompanyID old_company = _current_company; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
1282 _current_company = OWNER_TOWN; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1283 |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
1284 TileIndex tile = t->xy; // The tile we are working with ATM |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1285 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1286 /* Find a road that we can base the construction on. */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1287 const TileIndexDiffC *ptr; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1288 for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
7566
9da968584674
(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 <belugas@openttd.org>
parents:
7549
diff
changeset
|
1289 if (GetTownRoadBits(tile) != ROAD_NONE) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1290 int r = GrowTownAtRoad(t, tile); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
1291 _current_company = old_company; |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
1292 return r != 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1293 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1294 tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1295 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1296 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1297 /* No road available, try to build a random road block by |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1298 * clearing some land and then building a road there. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1299 tile = t->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1300 for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1301 /* Only work with plain land that not already has a house */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1302 if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) { |
6946
803e29b0584e
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1303 if (CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1304 DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
1305 _current_company = old_company; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1306 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1307 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1308 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1309 tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1310 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1311 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
1312 _current_company = old_company; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1313 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1314 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1315 |
8707
64bd5cfc6426
(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 <skidd13@openttd.org>
parents:
8618
diff
changeset
|
1316 void UpdateTownRadius(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1317 { |
8944
24302d526047
(svn r12731) -Fix (r12726): copying a 16bit array into 32bit wouldn't work
smatz <smatz@openttd.org>
parents:
8943
diff
changeset
|
1318 static const uint32 _town_squared_town_zone_radius_data[23][5] = { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1319 { 4, 0, 0, 0, 0}, // 0 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1320 { 16, 0, 0, 0, 0}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1321 { 25, 0, 0, 0, 0}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1322 { 36, 0, 0, 0, 0}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1323 { 49, 0, 4, 0, 0}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1324 { 64, 0, 4, 0, 0}, // 20 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1325 { 64, 0, 9, 0, 1}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1326 { 64, 0, 9, 0, 4}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1327 { 64, 0, 16, 0, 4}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1328 { 81, 0, 16, 0, 4}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1329 { 81, 0, 16, 0, 4}, // 40 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1330 { 81, 0, 25, 0, 9}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1331 { 81, 36, 25, 0, 9}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1332 { 81, 36, 25, 16, 9}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1333 { 81, 49, 0, 25, 9}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1334 { 81, 64, 0, 25, 9}, // 60 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1335 { 81, 64, 0, 36, 9}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1336 { 81, 64, 0, 36, 16}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1337 {100, 81, 0, 49, 16}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1338 {100, 81, 0, 49, 25}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1339 {121, 81, 0, 49, 25}, // 80 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1340 {121, 81, 0, 49, 25}, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1341 {121, 81, 0, 49, 36}, // 88 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1342 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1343 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1344 if (t->num_houses < 92) { |
8943
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1345 memcpy(t->squared_town_zone_radius, _town_squared_town_zone_radius_data[t->num_houses / 4], sizeof(t->squared_town_zone_radius)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1346 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1347 int mass = t->num_houses / 8; |
8943
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1348 /* Actually we are proportional to sqrt() but that's right because we are covering an area. |
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1349 * The offsets are to make sure the radii do not decrease in size when going from the table |
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1350 * to the calculated value.*/ |
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1351 t->squared_town_zone_radius[0] = mass * 15 - 40; |
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1352 t->squared_town_zone_radius[1] = mass * 9 - 15; |
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1353 t->squared_town_zone_radius[2] = 0; |
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1354 t->squared_town_zone_radius[3] = mass * 5 - 5; |
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1355 t->squared_town_zone_radius[4] = mass * 3 + 5; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1356 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1357 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1358 |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1359 extern int _nb_orig_names; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1360 |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1361 /** |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1362 * Struct holding a parameters used to generate town name. |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1363 * Speeds things up a bit because these values are computed only once per name generation. |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1364 */ |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1365 struct TownNameParams { |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1366 uint32 grfid; ///< newgrf ID |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1367 uint16 townnametype; ///< town name style |
11379
698ec69280ac
(svn r15729) -Fix: silence MSVC warning
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1368 bool grf; ///< true iff a newgrf is used to generate town name |
698ec69280ac
(svn r15729) -Fix: silence MSVC warning
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1369 |
698ec69280ac
(svn r15729) -Fix: silence MSVC warning
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1370 TownNameParams(byte town_name) |
698ec69280ac
(svn r15729) -Fix: silence MSVC warning
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1371 { |
698ec69280ac
(svn r15729) -Fix: silence MSVC warning
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1372 this->grf = town_name >= _nb_orig_names; |
698ec69280ac
(svn r15729) -Fix: silence MSVC warning
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1373 this->grfid = this->grf ? GetGRFTownNameId(town_name - _nb_orig_names) : 0; |
698ec69280ac
(svn r15729) -Fix: silence MSVC warning
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1374 this->townnametype = this->grf ? GetGRFTownNameType(town_name - _nb_orig_names) : SPECSTR_TOWNNAME_START + town_name; |
698ec69280ac
(svn r15729) -Fix: silence MSVC warning
rubidium <rubidium@openttd.org>
parents:
11376
diff
changeset
|
1375 } |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1376 }; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1377 |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1378 /** |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1379 * Verifies the town name is valid and unique. |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1380 * @param r random bits |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1381 * @param par town name parameters |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1382 * @return true iff name is valid and unique |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1383 */ |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1384 static bool VerifyTownName(uint32 r, const TownNameParams *par) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1385 { |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1386 /* reserve space for extra unicode character and terminating '\0' */ |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1387 char buf1[MAX_LENGTH_TOWN_NAME_BYTES + 4 + 1]; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1388 char buf2[MAX_LENGTH_TOWN_NAME_BYTES + 4 + 1]; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1389 |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1390 SetDParam(0, r); |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1391 if (par->grf && par->grfid != 0) { |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1392 GRFTownNameGenerate(buf1, par->grfid, par->townnametype, r, lastof(buf1)); |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1393 } else { |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1394 GetString(buf1, par->townnametype, lastof(buf1)); |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1395 } |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1396 |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1397 /* Check size and width */ |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1398 if (strlen(buf1) >= MAX_LENGTH_TOWN_NAME_BYTES) return false; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1399 |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1400 const Town *t; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1401 FOR_ALL_TOWNS(t) { |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1402 /* We can't just compare the numbers since |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1403 * several numbers may map to a single name. */ |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1404 SetDParam(0, t->index); |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1405 GetString(buf2, STR_TOWN, lastof(buf2)); |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1406 if (strcmp(buf1, buf2) == 0) return false; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1407 } |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1408 |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1409 return true; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1410 } |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1411 |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1412 /** |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1413 * Generates valid town name. |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1414 * @param townnameparts if a name is generated, it's stored there |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1415 * @return true iff a name was generated |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1416 */ |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1417 bool GenerateTownName(uint32 *townnameparts) |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1418 { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1419 /* Do not set too low tries, since when we run out of names, we loop |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1420 * for #tries only one time anyway - then we stop generating more |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1421 * towns. Do not show it too high neither, since looping through all |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1422 * the other towns may take considerable amount of time (10000 is |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1423 * too much). */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1424 int tries = 1000; |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1425 TownNameParams par(_settings_game.game_creation.town_name); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1426 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1427 assert(townnameparts != NULL); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1428 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1429 for (;;) { |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1430 uint32 r = InteractiveRandom(); |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1431 |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1432 if (!VerifyTownName(r, &par)) { |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1433 if (tries-- < 0) return false; |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1434 continue; |
6956
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
1435 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1436 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1437 *townnameparts = r; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1438 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1439 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1440 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1441 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1442 void UpdateTownMaxPass(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1443 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1444 t->max_pass = t->population >> 3; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1445 t->max_mail = t->population >> 4; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1446 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1447 |
6486
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1448 /** |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1449 * Does the actual town creation. |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1450 * |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1451 * @param t The town |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1452 * @param tile Where to put it |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1453 * @param townnameparts The town name |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1454 * @param size_mode How the size should be determined |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1455 * @param size Parameter for size determination |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1456 */ |
11012
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1457 static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1458 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1459 t->xy = tile; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1460 t->num_houses = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1461 t->time_until_rebuild = 10; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1462 UpdateTownRadius(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1463 t->flags12 = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1464 t->population = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1465 t->grow_counter = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1466 t->growth_rate = 250; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1467 t->new_max_pass = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1468 t->new_max_mail = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1469 t->new_act_pass = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1470 t->new_act_mail = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1471 t->max_pass = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1472 t->max_mail = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1473 t->act_pass = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1474 t->act_mail = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1475 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1476 t->pct_pass_transported = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1477 t->pct_mail_transported = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1478 t->fund_buildings_months = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1479 t->new_act_food = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1480 t->new_act_water = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1481 t->act_food = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1482 t->act_water = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1483 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
1484 for (uint i = 0; i != MAX_COMPANIES; i++) t->ratings[i] = RATING_INITIAL; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1485 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1486 t->have_ratings = 0; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
1487 t->exclusivity = INVALID_COMPANY; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1488 t->exclusive_counter = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1489 t->statues = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1490 |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
1491 if (_settings_game.game_creation.town_name < _nb_orig_names) { |
6956
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
1492 /* Original town name */ |
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
1493 t->townnamegrfid = 0; |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
1494 t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name; |
6956
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
1495 } else { |
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
1496 /* Newgrf town name */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
1497 t->townnamegrfid = GetGRFTownNameId(_settings_game.game_creation.town_name - _nb_orig_names); |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
1498 t->townnametype = GetGRFTownNameType(_settings_game.game_creation.town_name - _nb_orig_names); |
6956
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
1499 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1500 t->townnameparts = townnameparts; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1501 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1502 UpdateTownVirtCoord(t); |
9387
a240dd49a2e8
(svn r13297) -Codechange: Use GUIList for the town directory window
peter1138 <peter1138@openttd.org>
parents:
9358
diff
changeset
|
1503 InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1504 |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
1505 t->InitializeLayout(layout); |
8796
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
1506 |
11012
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1507 t->larger_town = city; |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1508 |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1509 int x = (int)size * 16 + 3; |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1510 if (size == TS_RANDOM) x = (Random() & 0xF) + 8; |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1511 if (city) x *= _settings_game.economy.initial_city_size; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1512 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1513 t->num_houses += x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1514 UpdateTownRadius(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1515 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1516 int i = x * 4; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1517 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1518 GrowTown(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1519 } while (--i); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1520 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1521 t->num_houses -= x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1522 UpdateTownRadius(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1523 UpdateTownMaxPass(t); |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1524 UpdateAirportsNoise(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1525 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1526 |
11529
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1527 /** |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1528 * Checks if it's possible to place a town at given tile |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1529 * @param tile tile to check |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1530 * @return error value or zero cost |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1531 */ |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1532 static CommandCost TownCanBePlacedHere(TileIndex tile) |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1533 { |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1534 /* Check if too close to the edge of map */ |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1535 if (DistanceFromEdge(tile) < 12) { |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
1536 return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); |
11529
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1537 } |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1538 |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1539 /* Check distance to all other towns. */ |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1540 if (IsCloseToTown(tile, 20)) { |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
1541 return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_TOWN); |
11529
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1542 } |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1543 |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1544 /* Can only build on clear flat areas, possibly with trees. */ |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1545 if ((!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES)) || GetTileSlope(tile, NULL) != SLOPE_FLAT) { |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
1546 return_cmd_error(STR_ERROR_SITE_UNSUITABLE); |
11529
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1547 } |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1548 |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1549 return CommandCost(); |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1550 } |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1551 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1552 /** Create a new town. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1553 * This obviously only works in the scenario editor. Function not removed |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1554 * as it might be possible in the future to fund your own town :) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1555 * @param tile coordinates where town is built |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1556 * @param flags type of operation |
11012
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1557 * @param p1 0..1 size of the town (@see TownSize) |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1558 * 2 true iff it should be a city |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1559 * 3..5 town road layout (@see TownLayout) |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1560 * @param p2 town name parts |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1561 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
1562 CommandCost CmdBuildTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1563 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1564 /* Only in the scenario editor */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1565 if (_game_mode != GM_EDITOR) return CMD_ERROR; |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
1566 |
11012
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1567 TownSize size = (TownSize)GB(p1, 0, 2); |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1568 bool city = HasBit(p1, 2); |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1569 TownLayout layout = (TownLayout)GB(p1, 3, 3); |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1570 TownNameParams par(_settings_game.game_creation.town_name); |
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1571 uint32 townnameparts = p2; |
11012
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1572 |
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1573 if (size > TS_RANDOM) return CMD_ERROR; |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
1574 if (layout > TL_RANDOM) return CMD_ERROR; |
11529
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1575 |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1576 if (!VerifyTownName(townnameparts, &par)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1577 |
11529
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1578 CommandCost cost = TownCanBePlacedHere(tile); |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1579 if (CmdFailed(cost)) return cost; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1580 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1581 /* Allocate town struct */ |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
1582 if (!Town::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_TOWNS); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1583 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1584 /* Create the town */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1585 if (flags & DC_EXEC) { |
9036
74210834ed21
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium <rubidium@openttd.org>
parents:
9020
diff
changeset
|
1586 Town *t = new Town(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1587 _generating_world = true; |
10340
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
1588 UpdateNearestTownForRoadTiles(true); |
11012
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1589 DoCreateTown(t, tile, townnameparts, size, city, layout); |
10340
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
1590 UpdateNearestTownForRoadTiles(false); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1591 _generating_world = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1592 } |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6946
diff
changeset
|
1593 return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1594 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1595 |
11757
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1596 /** |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1597 * Towns must all be placed on the same grid or when they eventually |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1598 * interpenetrate their road networks will not mesh nicely; this |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1599 * function adjusts a tile so that it aligns properly. |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1600 * |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1601 * @param tile the tile to start at |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1602 * @param layout which town layout algo is in effect |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1603 * @return the adjusted tile |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1604 */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1605 static TileIndex AlignTileToGrid(TileIndex tile, TownLayout layout) |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1606 { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1607 switch (layout) { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1608 case TL_2X2_GRID: return TileXY(TileX(tile) - TileX(tile) % 3, TileY(tile) - TileY(tile) % 3); |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1609 case TL_3X3_GRID: return TileXY(TileX(tile) & ~3, TileY(tile) & ~3); |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1610 default: return tile; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1611 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1612 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1613 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1614 /** |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1615 * Towns must all be placed on the same grid or when they eventually |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1616 * interpenetrate their road networks will not mesh nicely; this |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1617 * function tells you if a tile is properly aligned. |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1618 * |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1619 * @param tile the tile to start at |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1620 * @param layout which town layout algo is in effect |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1621 * @return true if the tile is in the correct location |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1622 */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1623 static bool IsTileAlignedToGrid(TileIndex tile, TownLayout layout) |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1624 { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1625 switch (layout) { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1626 case TL_2X2_GRID: return TileX(tile) % 3 == 0 && TileY(tile) % 3 == 0; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1627 case TL_3X3_GRID: return TileX(tile) % 4 == 0 && TileY(tile) % 4 == 0; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1628 default: return true; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1629 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1630 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1631 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1632 /** |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1633 * Used as the user_data for FindFurthestFromWater |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1634 */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1635 struct SpotData { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1636 TileIndex tile; ///< holds the tile that was found |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1637 uint max_dist; ///< holds the distance that tile is from the water |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1638 TownLayout layout; ///< tells us what kind of town we're building |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1639 }; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1640 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1641 /** |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1642 * CircularTileSearch callback; finds the tile furthest from any |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1643 * water. slightly bit tricky, since it has to do a search of it's own |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1644 * in order to find the distance to the water from each square in the |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1645 * radius. |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1646 * |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1647 * Also, this never returns true, because it needs to take into |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1648 * account all locations being searched before it knows which is the |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1649 * furthest. |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1650 * |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1651 * @param tile Start looking from this tile |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1652 * @param user_data Storage area for data that must last across calls; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1653 * must be a pointer to struct SpotData |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1654 * |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1655 * @return always false |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1656 */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1657 static bool FindFurthestFromWater(TileIndex tile, void *user_data) |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1658 { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1659 SpotData *sp = (SpotData*)user_data; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1660 uint dist = GetClosestWaterDistance(tile, true); |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1661 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1662 if (IsTileType(tile, MP_CLEAR) && |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1663 GetTileSlope(tile, NULL) == SLOPE_FLAT && |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1664 IsTileAlignedToGrid(tile, sp->layout) && |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1665 dist > sp->max_dist) { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1666 sp->tile = tile; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1667 sp->max_dist = dist; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1668 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1669 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1670 return false; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1671 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1672 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1673 /** |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1674 * CircularTileSearch callback; finds the nearest land tile |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1675 * |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1676 * @param tile Start looking from this tile |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1677 * @param user_data not used |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1678 */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1679 static bool FindNearestEmptyLand(TileIndex tile, void *user_data) |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1680 { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1681 return IsTileType(tile, MP_CLEAR); |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1682 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1683 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1684 /** |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1685 * Given a spot on the map (presumed to be a water tile), find a good |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1686 * coastal spot to build a city. We don't want to build too close to |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1687 * the edge if we can help it (since that retards city growth) hence |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1688 * the search within a search within a search. O(n*m^2), where n is |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1689 * how far to search for land, and m is how far inland to look for a |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1690 * flat spot. |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1691 * |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1692 * @param tile Start looking from this spot. |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1693 * @return tile that was found |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1694 */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1695 static TileIndex FindNearestGoodCoastalTownSpot(TileIndex tile, TownLayout layout) |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1696 { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1697 SpotData sp = { INVALID_TILE, 0, layout }; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1698 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1699 TileIndex coast = tile; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1700 if (CircularTileSearch(&coast, 40, FindNearestEmptyLand, NULL)) { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1701 CircularTileSearch(&coast, 10, FindFurthestFromWater, &sp); |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1702 return sp.tile; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1703 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1704 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1705 /* if we get here just give up */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1706 return INVALID_TILE; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1707 } |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1708 |
11012
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1709 Town *CreateRandomTown(uint attempts, TownSize size, bool city, TownLayout layout) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1710 { |
10634
66515fd11ca9
(svn r14933) -Codechange: check the whether a pool item can be constructed instead of trying to make it and check for NULL.
rubidium <rubidium@openttd.org>
parents:
10571
diff
changeset
|
1711 if (!Town::CanAllocateItem()) return NULL; |
66515fd11ca9
(svn r14933) -Codechange: check the whether a pool item can be constructed instead of trying to make it and check for NULL.
rubidium <rubidium@openttd.org>
parents:
10571
diff
changeset
|
1712 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1713 do { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1714 /* Generate a tile index not too close from the edge */ |
11757
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1715 TileIndex tile = AlignTileToGrid(RandomTile(), layout); |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1716 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1717 /* if we tried to place the town on water, slide it over onto |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1718 * the nearest likely-looking spot */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1719 if (IsTileType(tile, MP_WATER)) { |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1720 tile = FindNearestGoodCoastalTownSpot(tile, layout); |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1721 if (tile == INVALID_TILE) continue; |
10564
47ec3be0f65c
(svn r14821) -Change [FS#2390]: make the road grids of town match, when all are using the same road layout ofcourse (cirdan)
rubidium <rubidium@openttd.org>
parents:
10550
diff
changeset
|
1722 } |
11529
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1723 |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1724 /* Make sure town can be placed here */ |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1725 if (CmdFailed(TownCanBePlacedHere(tile))) continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1726 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1727 uint32 townnameparts; |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1728 /* Get a unique name for the town. */ |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1729 if (!GenerateTownName(&townnameparts)) break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1730 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1731 /* Allocate a town struct */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1732 Town *t = new Town(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1733 |
11012
88712c0e082e
(svn r15352) -Codechange: make the arguments passed around while founding a town a bit more readable
smatz <smatz@openttd.org>
parents:
11002
diff
changeset
|
1734 DoCreateTown(t, tile, townnameparts, size, city, layout); |
11757
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1735 |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1736 /* if the population is still 0 at the point, then the |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1737 * placement is so bad it couldn't grow at all */ |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1738 if (t->population > 0) return t; |
b4b83f6e760a
(svn r16147) -Feature [FS#2635]: give the town generator a slight tendency to build towns near water by not discarding watery random tiles but by searching for near land (db48x)
rubidium <rubidium@openttd.org>
parents:
11730
diff
changeset
|
1739 delete t; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1740 } while (--attempts != 0); |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1741 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1742 return NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1743 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1744 |
9334
3945a8340531
(svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas <belugas@openttd.org>
parents:
9322
diff
changeset
|
1745 static const byte _num_initial_towns[4] = {5, 11, 23, 46}; // very low, low, normal, high |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1746 |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
1747 bool GenerateTowns(TownLayout layout) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1748 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1749 uint num = 0; |
11345
c78d659d5029
(svn r15695) -Feature [FS#2672]: Allow the number of towns that will be generated in the generate world window to be customized.
belugas <belugas@openttd.org>
parents:
11339
diff
changeset
|
1750 uint difficulty = _settings_game.difficulty.number_towns; |
11347
8656dc2695e9
(svn r15697) -Fix (r15695): warning about comparing signed vs unsigned.
rubidium <rubidium@openttd.org>
parents:
11345
diff
changeset
|
1751 uint n = (difficulty == (uint)CUSTOM_TOWN_NUMBER_DIFFICULTY) ? _settings_game.game_creation.custom_town_number : ScaleByMapSize(_num_initial_towns[difficulty] + (Random() & 7)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1752 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1753 SetGeneratingWorldProgress(GWP_TOWN, n); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1754 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1755 do { |
11391
105bd5e1cbed
(svn r15744) -Fix (r9667): when town generator failed to create requested number of towns, there were too many cities
smatz <smatz@openttd.org>
parents:
11379
diff
changeset
|
1756 bool city = (_settings_game.economy.larger_towns != 0 && Chance16(1, _settings_game.economy.larger_towns)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1757 IncreaseGeneratingWorldProgress(GWP_TOWN); |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1758 /* try 20 times to create a random-sized town for the first loop. */ |
11391
105bd5e1cbed
(svn r15744) -Fix (r9667): when town generator failed to create requested number of towns, there were too many cities
smatz <smatz@openttd.org>
parents:
11379
diff
changeset
|
1759 if (CreateRandomTown(20, TS_RANDOM, city, layout) != NULL) num++; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1760 } while (--n); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1761 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1762 /* give it a last try, but now more aggressive */ |
11391
105bd5e1cbed
(svn r15744) -Fix (r9667): when town generator failed to create requested number of towns, there were too many cities
smatz <smatz@openttd.org>
parents:
11379
diff
changeset
|
1763 if (num == 0 && CreateRandomTown(10000, TS_RANDOM, _settings_game.economy.larger_towns != 0, layout) == NULL) { |
11973
e17a54c88806
(svn r16379) -Codechange: remove GetNumTowns(), GetNumIndustries() and GetActiveCompanyCount(), use PoolItem::GetNumItems() instead
smatz <smatz@openttd.org>
parents:
11972
diff
changeset
|
1764 if (Town::GetNumItems() == 0) { |
11339
a41eac9012e2
(svn r15689) -Fix [FS#2720]: do not crash when the generate map doesn't contain a suitable location for a town.
rubidium <rubidium@openttd.org>
parents:
11312
diff
changeset
|
1765 if (_game_mode != GM_EDITOR) { |
a41eac9012e2
(svn r15689) -Fix [FS#2720]: do not crash when the generate map doesn't contain a suitable location for a town.
rubidium <rubidium@openttd.org>
parents:
11312
diff
changeset
|
1766 extern StringID _switch_mode_errorstr; |
a41eac9012e2
(svn r15689) -Fix [FS#2720]: do not crash when the generate map doesn't contain a suitable location for a town.
rubidium <rubidium@openttd.org>
parents:
11312
diff
changeset
|
1767 _switch_mode_errorstr = STR_COULD_NOT_CREATE_TOWN; |
a41eac9012e2
(svn r15689) -Fix [FS#2720]: do not crash when the generate map doesn't contain a suitable location for a town.
rubidium <rubidium@openttd.org>
parents:
11312
diff
changeset
|
1768 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1769 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1770 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1771 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1772 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1773 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1774 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1775 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1776 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1777 |
8308
e9042729a5c5
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas <belugas@openttd.org>
parents:
8291
diff
changeset
|
1778 /** Returns the bit corresponding to the town zone of the specified tile |
8943
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1779 * @param t Town on which town zone is to be found |
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1780 * @param tile TileIndex where town zone needs to be found |
8308
e9042729a5c5
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas <belugas@openttd.org>
parents:
8291
diff
changeset
|
1781 * @return the bit position of the given zone, as defined in HouseZones |
e9042729a5c5
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas <belugas@openttd.org>
parents:
8291
diff
changeset
|
1782 */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1783 HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1784 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1785 uint dist = DistanceSquare(tile, t->xy); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1786 |
8308
e9042729a5c5
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas <belugas@openttd.org>
parents:
8291
diff
changeset
|
1787 if (t->fund_buildings_months && dist <= 25) return HZB_TOWN_CENTRE; |
e9042729a5c5
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas <belugas@openttd.org>
parents:
8291
diff
changeset
|
1788 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1789 HouseZonesBits smallest = HZB_TOWN_EDGE; |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
1790 for (HouseZonesBits i = HZB_BEGIN; i < HZB_END; i++) { |
8943
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
1791 if (dist < t->squared_town_zone_radius[i]) smallest = i; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1792 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1793 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1794 return smallest; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1795 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1796 |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1797 /** |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1798 * Clears tile and builds a house or house part. |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1799 * @param t tile index |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1800 * @param tid Town index |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1801 * @param counter of construction step |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1802 * @param stage of construction (used for drawing) |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1803 * @param type of house. Index into house specs array |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1804 * @param random_bits required for newgrf houses |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1805 * @pre house can be built here |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1806 */ |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1807 static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits) |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1808 { |
9436
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
1809 CommandCost cc = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR); |
8618
4a33194e5ee7
(svn r12201) -Fix (r12060): compilation warnings - uninitialized variable when compiling with assert disabled
smatz <smatz@openttd.org>
parents:
8616
diff
changeset
|
1810 |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1811 assert(CmdSucceeded(cc)); |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1812 |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1813 IncreaseBuildingCount(t, type); |
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1814 MakeHouseTile(tile, t->index, counter, stage, type, random_bits); |
9006
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
1815 if (GetHouseSpecs(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(tile); |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
1816 |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
1817 MarkTileDirtyByTile(tile); |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1818 } |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1819 |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1820 |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1821 /** |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1822 * Write house information into the map. For houses > 1 tile, all tiles are marked. |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1823 * @param t tile index |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1824 * @param tid Town index |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1825 * @param counter of construction step |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1826 * @param stage of construction (used for drawing) |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1827 * @param type of house. Index into house specs array |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1828 * @param random_bits required for newgrf houses |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1829 * @pre house can be built here |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1830 */ |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1831 static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, HouseID type, byte random_bits) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1832 { |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1833 BuildingFlags size = GetHouseSpecs(type)->building_flags; |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1834 |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1835 ClearMakeHouseTile(t, town, counter, stage, type, random_bits); |
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1836 if (size & BUILDING_2_TILES_Y) ClearMakeHouseTile(t + TileDiffXY(0, 1), town, counter, stage, ++type, random_bits); |
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1837 if (size & BUILDING_2_TILES_X) ClearMakeHouseTile(t + TileDiffXY(1, 0), town, counter, stage, ++type, random_bits); |
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1838 if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(t + TileDiffXY(1, 1), town, counter, stage, ++type, random_bits); |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1839 } |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1840 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1841 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1842 /** |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1843 * Checks if a house can be built here. Important is slope, bridge above |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1844 * and ability to clear the land. |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1845 * @param tile tile to check |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1846 * @param town town that is checking |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1847 * @param noslope are slopes (foundations) allowed? |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1848 * @return true iff house can be built here |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1849 */ |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1850 static inline bool CanBuildHouseHere(TileIndex tile, TownID town, bool noslope) |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1851 { |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1852 /* cannot build on these slopes... */ |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1853 Slope slope = GetTileSlope(tile, NULL); |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1854 if ((noslope && slope != SLOPE_FLAT) || IsSteepSlope(slope)) return false; |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1855 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1856 /* building under a bridge? */ |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1857 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1858 |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1859 /* do not try to build over house owned by another town */ |
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1860 if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) != town) return false; |
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1861 |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1862 /* can we clear the land? */ |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1863 return CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR)); |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1864 } |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1865 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1866 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1867 /** |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1868 * Checks if a house can be built at this tile, must have the same max z as parameter. |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1869 * @param tile tile to check |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1870 * @param town town that is checking |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1871 * @param z max z of this tile so more parts of a house are at the same height (with foundation) |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1872 * @param noslope are slopes (foundations) allowed? |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1873 * @return true iff house can be built here |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1874 * @see CanBuildHouseHere() |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1875 */ |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1876 static inline bool CheckBuildHouseSameZ(TileIndex tile, TownID town, uint z, bool noslope) |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1877 { |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1878 if (!CanBuildHouseHere(tile, town, noslope)) return false; |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1879 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1880 /* if building on slopes is allowed, there will be flattening foundation (to tile max z) */ |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1881 if (GetTileMaxZ(tile) != z) return false; |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1882 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1883 return true; |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1884 } |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1885 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1886 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1887 /** |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1888 * Checks if a house of size 2x2 can be built at this tile |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1889 * @param tile tile, N corner |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1890 * @param town town that is checking |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1891 * @param z maximum tile z so all tile have the same max z |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1892 * @param noslope are slopes (foundations) allowed? |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1893 * @return true iff house can be built |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1894 * @see CheckBuildHouseSameZ() |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1895 */ |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1896 static bool CheckFree2x2Area(TileIndex tile, TownID town, uint z, bool noslope) |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1897 { |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1898 /* we need to check this tile too because we can be at different tile now */ |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1899 if (!CheckBuildHouseSameZ(tile, town, z, noslope)) return false; |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1900 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1901 for (DiagDirection d = DIAGDIR_SE; d < DIAGDIR_END; d++) { |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1902 tile += TileOffsByDiagDir(d); |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1903 if (!CheckBuildHouseSameZ(tile, town, z, noslope)) return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1904 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1905 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1906 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1907 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1908 |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1909 |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
1910 /** |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1911 * Checks if current town layout allows building here |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1912 * @param t town |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1913 * @param tile tile to check |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1914 * @return true iff town layout allows building here |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1915 * @note see layouts |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1916 */ |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1917 static inline bool TownLayoutAllowsHouseHere(Town *t, TileIndex tile) |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1918 { |
11255
7cc3c9bfa047
(svn r15604) -Fix [FS#2661]: towns would only build houses where the grid would not be, even when they aren't allowed to build roads and the user 'implements' another layout.
rubidium <rubidium@openttd.org>
parents:
11231
diff
changeset
|
1919 /* Allow towns everywhere when we don't build roads */ |
7cc3c9bfa047
(svn r15604) -Fix [FS#2661]: towns would only build houses where the grid would not be, even when they aren't allowed to build roads and the user 'implements' another layout.
rubidium <rubidium@openttd.org>
parents:
11231
diff
changeset
|
1920 if (!_settings_game.economy.allow_town_roads && !_generating_world) return true; |
7cc3c9bfa047
(svn r15604) -Fix [FS#2661]: towns would only build houses where the grid would not be, even when they aren't allowed to build roads and the user 'implements' another layout.
rubidium <rubidium@openttd.org>
parents:
11231
diff
changeset
|
1921 |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1922 TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile); |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1923 |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1924 switch (t->layout) { |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1925 case TL_2X2_GRID: |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1926 if ((grid_pos.x % 3) == 0 || (grid_pos.y % 3) == 0) return false; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1927 break; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1928 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1929 case TL_3X3_GRID: |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1930 if ((grid_pos.x % 4) == 0 || (grid_pos.y % 4) == 0) return false; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1931 break; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1932 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1933 default: |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1934 break; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1935 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1936 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1937 return true; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1938 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1939 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1940 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1941 /** |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1942 * Checks if current town layout allows 2x2 building here |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1943 * @param t town |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1944 * @param tile tile to check |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1945 * @return true iff town layout allows 2x2 building here |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1946 * @note see layouts |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1947 */ |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1948 static inline bool TownLayoutAllows2x2HouseHere(Town *t, TileIndex tile) |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1949 { |
11255
7cc3c9bfa047
(svn r15604) -Fix [FS#2661]: towns would only build houses where the grid would not be, even when they aren't allowed to build roads and the user 'implements' another layout.
rubidium <rubidium@openttd.org>
parents:
11231
diff
changeset
|
1950 /* Allow towns everywhere when we don't build roads */ |
7cc3c9bfa047
(svn r15604) -Fix [FS#2661]: towns would only build houses where the grid would not be, even when they aren't allowed to build roads and the user 'implements' another layout.
rubidium <rubidium@openttd.org>
parents:
11231
diff
changeset
|
1951 if (!_settings_game.economy.allow_town_roads && !_generating_world) return true; |
7cc3c9bfa047
(svn r15604) -Fix [FS#2661]: towns would only build houses where the grid would not be, even when they aren't allowed to build roads and the user 'implements' another layout.
rubidium <rubidium@openttd.org>
parents:
11231
diff
changeset
|
1952 |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1953 /* MapSize() is sure dividable by both MapSizeX() and MapSizeY(), |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1954 * so to do only one memory access, use MapSize() */ |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1955 uint dx = MapSize() + TileX(t->xy) - TileX(tile); |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1956 uint dy = MapSize() + TileY(t->xy) - TileY(tile); |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1957 |
11000
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1958 switch (t->layout) { |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1959 case TL_2X2_GRID: |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1960 if ((dx % 3) != 0 || (dy % 3) != 0) return false; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1961 break; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1962 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1963 case TL_3X3_GRID: |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1964 if ((dx % 4) < 2 || (dy % 4) < 2) return false; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1965 break; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1966 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1967 default: |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1968 break; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1969 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1970 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1971 return true; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1972 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1973 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1974 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1975 /** |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1976 * Checks if 1x2 or 2x1 building is allowed here, also takes into account current town layout |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1977 * Also, tests both building positions that occupy this tile |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1978 * @param tile tile where the building should be built |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1979 * @param t town |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1980 * @param maxz all tiles should have the same height |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1981 * @param noslope are slopes forbidden? |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1982 * @param second diagdir from first tile to second tile |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1983 **/ |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1984 static bool CheckTownBuild2House(TileIndex *tile, Town *t, uint maxz, bool noslope, DiagDirection second) |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1985 { |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1986 /* 'tile' is already checked in BuildTownHouse() - CanBuildHouseHere() and slope test */ |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1987 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1988 TileIndex tile2 = *tile + TileOffsByDiagDir(second); |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1989 if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, t->index, maxz, noslope)) return true; |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1990 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1991 tile2 = *tile + TileOffsByDiagDir(ReverseDiagDir(second)); |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
1992 if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, t->index, maxz, noslope)) { |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1993 *tile = tile2; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1994 return true; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1995 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1996 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1997 return false; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1998 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
1999 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2000 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2001 /** |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2002 * Checks if 2x2 building is allowed here, also takes into account current town layout |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2003 * Also, tests all four building positions that occupy this tile |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2004 * @param tile tile where the building should be built |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2005 * @param t town |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2006 * @param maxz all tiles should have the same height |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2007 * @param noslope are slopes forbidden? |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2008 **/ |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2009 static bool CheckTownBuild2x2House(TileIndex *tile, Town *t, uint maxz, bool noslope) |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2010 { |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2011 TileIndex tile2 = *tile; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2012 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2013 for (DiagDirection d = DIAGDIR_SE;;d++) { // 'd' goes through DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_END |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
2014 if (TownLayoutAllows2x2HouseHere(t, tile2) && CheckFree2x2Area(tile2, t->index, maxz, noslope)) { |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2015 *tile = tile2; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2016 return true; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2017 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2018 if (d == DIAGDIR_END) break; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2019 tile2 += TileOffsByDiagDir(ReverseDiagDir(d)); // go clockwise |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2020 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2021 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2022 return false; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2023 } |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2024 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2025 |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2026 /** |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
2027 * Tries to build a house at this tile |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
2028 * @param t town the house will belong to |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
2029 * @param tile where the house will be built |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
2030 * @return false iff no house can be built at this tile |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
2031 */ |
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
2032 static bool BuildTownHouse(Town *t, TileIndex tile) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2033 { |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2034 /* forbidden building here by town layout */ |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2035 if (!TownLayoutAllowsHouseHere(t, tile)) return false; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2036 |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
2037 /* no house allowed at all, bail out */ |
8581
0060507052b9
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
smatz <smatz@openttd.org>
parents:
8580
diff
changeset
|
2038 if (!CanBuildHouseHere(tile, t->index, false)) return false; |
8485
a4493021a8f3
(svn r12060) -Fix: do not clear tiles when the town won't be able to build any buildings anyway
smatz <smatz@openttd.org>
parents:
8461
diff
changeset
|
2039 |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2040 uint z; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2041 Slope slope = GetTileSlope(tile, &z); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2042 |
8308
e9042729a5c5
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas <belugas@openttd.org>
parents:
8291
diff
changeset
|
2043 /* Get the town zone type of the current tile, as well as the climate. |
e9042729a5c5
(svn r11873) -Codechange: less a few magical numbers and a tiny bit more comments on town zones
belugas <belugas@openttd.org>
parents:
8291
diff
changeset
|
2044 * This will allow to easily compare with the specs of the new house to build */ |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2045 HouseZonesBits rad = GetTownRadiusGroup(t, tile); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2046 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2047 /* Above snow? */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
2048 int land = _settings_game.game_creation.landscape; |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
2049 if (land == LT_ARCTIC && z >= _settings_game.game_creation.snow_line) land = -1; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2050 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2051 uint bitmask = (1 << rad) + (1 << (land + 12)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2052 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2053 /* bits 0-4 are used |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2054 * bits 11-15 are used |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2055 * bits 5-10 are not used. */ |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2056 HouseID houses[HOUSE_MAX]; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2057 uint num = 0; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2058 uint probs[HOUSE_MAX]; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2059 uint probability_max = 0; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2060 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2061 /* Generate a list of all possible houses that can be built. */ |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2062 for (uint i = 0; i < HOUSE_MAX; i++) { |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2063 const HouseSpec *hs = GetHouseSpecs(i); |
11470
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2064 |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2065 /* Verify that the candidate house spec matches the current tile status */ |
11470
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2066 if ((~hs->building_availability & bitmask) != 0 || !hs->enabled) continue; |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2067 |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2068 /* Don't let these counters overflow. Global counters are 32bit, there will never be that many houses. */ |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2069 if (hs->class_id != HOUSE_NO_CLASS) { |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2070 /* id_count is always <= class_count, so it doesn't need to be checked */ |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2071 if (t->building_counts.class_count[hs->class_id] == UINT16_MAX) continue; |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2072 } else { |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2073 /* If the house has no class, check id_count instead */ |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2074 if (t->building_counts.id_count[i] == UINT16_MAX) continue; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2075 } |
11470
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2076 |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2077 /* Without NewHouses, all houses have probability '1' */ |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2078 uint cur_prob = (_loaded_newgrf_features.has_newhouses ? hs->probability : 1); |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2079 probability_max += cur_prob; |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2080 probs[num] = cur_prob; |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2081 houses[num++] = (HouseID)i; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2082 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2083 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2084 uint maxz = GetTileMaxZ(tile); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2085 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2086 while (probability_max > 0) { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2087 uint r = RandomRange(probability_max); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2088 uint i; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2089 for (i = 0; i < num; i++) { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2090 if (probs[i] > r) break; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2091 r -= probs[i]; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2092 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2093 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2094 HouseID house = houses[i]; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2095 probability_max -= probs[i]; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2096 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2097 /* remove tested house from the set */ |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2098 num--; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2099 houses[i] = houses[num]; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2100 probs[i] = probs[num]; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2101 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2102 const HouseSpec *hs = GetHouseSpecs(house); |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2103 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2104 if (_loaded_newgrf_features.has_newhouses) { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2105 if (hs->override != 0) { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2106 house = hs->override; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2107 hs = GetHouseSpecs(house); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2108 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2109 |
11290
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2110 if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world && _game_mode != GM_EDITOR) continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2111 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2112 |
9450
abbb771cc919
(svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
belugas <belugas@openttd.org>
parents:
9449
diff
changeset
|
2113 if (_cur_year < hs->min_year || _cur_year > hs->max_year) continue; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2114 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2115 /* Special houses that there can be only one of. */ |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2116 uint oneof = 0; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2117 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2118 if (hs->building_flags & BUILDING_IS_CHURCH) { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2119 SetBit(oneof, TOWN_HAS_CHURCH); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2120 } else if (hs->building_flags & BUILDING_IS_STADIUM) { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2121 SetBit(oneof, TOWN_HAS_STADIUM); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2122 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2123 |
9505
4a9a94edf11a
(svn r13489) -Fix: first determine where to *exactly* build a house before asking a NewGRF whether the location is good instead of possibly moving the house a tile after the NewGRF said the location is good.
rubidium <rubidium@openttd.org>
parents:
9470
diff
changeset
|
2124 if (HASBITS(t->flags12, oneof)) continue; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2125 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2126 /* Make sure there is no slope? */ |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2127 bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2128 if (noslope && slope != SLOPE_FLAT) continue; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2129 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2130 if (hs->building_flags & TILE_SIZE_2x2) { |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2131 if (!CheckTownBuild2x2House(&tile, t, maxz, noslope)) continue; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2132 } else if (hs->building_flags & TILE_SIZE_2x1) { |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2133 if (!CheckTownBuild2House(&tile, t, maxz, noslope, DIAGDIR_SW)) continue; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2134 } else if (hs->building_flags & TILE_SIZE_1x2) { |
8580
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2135 if (!CheckTownBuild2House(&tile, t, maxz, noslope, DIAGDIR_SE)) continue; |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2136 } else { |
1cbedb922142
(svn r12161) -Fix: towns will no longer build houses > 1x1 there where should be road (with 2x2, 3x3 grid town layouts)
smatz <smatz@openttd.org>
parents:
8488
diff
changeset
|
2137 /* 1x1 house checks are already done */ |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2138 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2139 |
9505
4a9a94edf11a
(svn r13489) -Fix: first determine where to *exactly* build a house before asking a NewGRF whether the location is good instead of possibly moving the house a tile after the NewGRF said the location is good.
rubidium <rubidium@openttd.org>
parents:
9470
diff
changeset
|
2140 if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) { |
4a9a94edf11a
(svn r13489) -Fix: first determine where to *exactly* build a house before asking a NewGRF whether the location is good instead of possibly moving the house a tile after the NewGRF said the location is good.
rubidium <rubidium@openttd.org>
parents:
9470
diff
changeset
|
2141 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile); |
4a9a94edf11a
(svn r13489) -Fix: first determine where to *exactly* build a house before asking a NewGRF whether the location is good instead of possibly moving the house a tile after the NewGRF said the location is good.
rubidium <rubidium@openttd.org>
parents:
9470
diff
changeset
|
2142 if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) == 0) continue; |
4a9a94edf11a
(svn r13489) -Fix: first determine where to *exactly* build a house before asking a NewGRF whether the location is good instead of possibly moving the house a tile after the NewGRF said the location is good.
rubidium <rubidium@openttd.org>
parents:
9470
diff
changeset
|
2143 } |
4a9a94edf11a
(svn r13489) -Fix: first determine where to *exactly* build a house before asking a NewGRF whether the location is good instead of possibly moving the house a tile after the NewGRF said the location is good.
rubidium <rubidium@openttd.org>
parents:
9470
diff
changeset
|
2144 |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2145 /* build the house */ |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2146 t->num_houses++; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2147 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2148 /* Special houses that there can be only one of. */ |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2149 t->flags12 |= oneof; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2150 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2151 byte construction_counter = 0; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2152 byte construction_stage = 0; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2153 |
11290
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2154 if (_generating_world || _game_mode == GM_EDITOR) { |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2155 uint32 r = Random(); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2156 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2157 construction_stage = TOWN_HOUSE_COMPLETED; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2158 if (Chance16(1, 7)) construction_stage = GB(r, 0, 2); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2159 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2160 if (construction_stage == TOWN_HOUSE_COMPLETED) { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2161 ChangePopulation(t, hs->population); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2162 } else { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2163 construction_counter = GB(r, 2, 2); |
8487
b616c9edbe1c
(svn r12062) -Fix: possible deadlock when there are no houses available to build at given tile
smatz <smatz@openttd.org>
parents:
8485
diff
changeset
|
2164 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2165 } |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2166 |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
2167 MakeTownHouse(tile, t, construction_counter, construction_stage, house, Random()); |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2168 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2169 return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2170 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2171 |
8487
b616c9edbe1c
(svn r12062) -Fix: possible deadlock when there are no houses available to build at given tile
smatz <smatz@openttd.org>
parents:
8485
diff
changeset
|
2172 return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2173 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2174 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2175 /** |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2176 * Update data structures when a house is removed |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2177 * @param tile Tile of the house |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2178 * @param t Town owning the house |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2179 * @param house House type |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2180 */ |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
2181 static void DoClearTownHouseHelper(TileIndex tile, Town *t, HouseID house) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2182 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2183 assert(IsTileType(tile, MP_HOUSE)); |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
2184 DecreaseBuildingCount(t, house); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2185 DoClearSquare(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2186 DeleteAnimatedTile(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2187 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2188 |
8942
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2189 /** |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2190 * Determines if a given HouseID is part of a multitile house. |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2191 * The given ID is set to the ID of the north tile and the TileDiff to the north tile is returned. |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2192 * |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2193 * @param house Is changed to the HouseID of the north tile of the same house |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2194 * @return TileDiff from the tile of the given HouseID to the north tile |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2195 */ |
10269
b678a31b4b36
(svn r14504) -Cleanup: Use the right variable type for tile offsets.
michi_cc <michi_cc@openttd.org>
parents:
10260
diff
changeset
|
2196 TileIndexDiff GetHouseNorthPart(HouseID &house) |
8942
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2197 { |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2198 if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks. |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2199 if (GetHouseSpecs(house - 1)->building_flags & TILE_SIZE_2x1) { |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2200 house--; |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2201 return TileDiffXY(-1, 0); |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2202 } else if (GetHouseSpecs(house - 1)->building_flags & BUILDING_2_TILES_Y) { |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2203 house--; |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2204 return TileDiffXY(0, -1); |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2205 } else if (GetHouseSpecs(house - 2)->building_flags & BUILDING_HAS_4_TILES) { |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2206 house -= 2; |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2207 return TileDiffXY(-1, 0); |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2208 } else if (GetHouseSpecs(house - 3)->building_flags & BUILDING_HAS_4_TILES) { |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2209 house -= 3; |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2210 return TileDiffXY(-1, -1); |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2211 } |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2212 } |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2213 return 0; |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2214 } |
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2215 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2216 void ClearTownHouse(Town *t, TileIndex tile) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2217 { |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2218 assert(IsTileType(tile, MP_HOUSE)); |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2219 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2220 HouseID house = GetHouseType(tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2221 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2222 /* need to align the tile to point to the upper left corner of the house */ |
8942
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2223 tile += GetHouseNorthPart(house); // modifies house to the ID of the north tile |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2224 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2225 const HouseSpec *hs = GetHouseSpecs(house); |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2226 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2227 /* Remove population from the town if the house is finished. */ |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2228 if (IsHouseCompleted(tile)) { |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2229 ChangePopulation(t, -hs->population); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2230 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2231 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2232 t->num_houses--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2233 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2234 /* Clear flags for houses that only may exist once/town. */ |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2235 if (hs->building_flags & BUILDING_IS_CHURCH) { |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
2236 ClrBit(t->flags12, TOWN_HAS_CHURCH); |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2237 } else if (hs->building_flags & BUILDING_IS_STADIUM) { |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
2238 ClrBit(t->flags12, TOWN_HAS_STADIUM); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2239 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2240 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2241 /* Do the actual clearing of tiles */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2242 uint eflags = hs->building_flags; |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
2243 DoClearTownHouseHelper(tile, t, house); |
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
2244 if (eflags & BUILDING_2_TILES_Y) DoClearTownHouseHelper(tile + TileDiffXY(0, 1), t, ++house); |
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
2245 if (eflags & BUILDING_2_TILES_X) DoClearTownHouseHelper(tile + TileDiffXY(1, 0), t, ++house); |
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
2246 if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1), t, ++house); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2247 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2248 |
7097
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2249 static bool IsUniqueTownName(const char *name) |
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2250 { |
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2251 const Town *t; |
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2252 |
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2253 FOR_ALL_TOWNS(t) { |
10656
39feee39693a
(svn r14958) -Codechange [FS#1923]: when checking for unique names, compare only with manually set names
smatz <smatz@openttd.org>
parents:
10634
diff
changeset
|
2254 if (t->name != NULL && strcmp(t->name, name) == 0) return false; |
7097
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2255 } |
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2256 |
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2257 return true; |
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2258 } |
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2259 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2260 /** Rename a town (server-only). |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2261 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2262 * @param flags type of operation |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2263 * @param p1 town ID to rename |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2264 * @param p2 unused |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2265 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
2266 CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2267 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11926
diff
changeset
|
2268 Town *t = Town::GetIfValid(p1); |
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11926
diff
changeset
|
2269 if (t == NULL) return CMD_ERROR; |
10148
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
9914
diff
changeset
|
2270 |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10487
diff
changeset
|
2271 bool reset = StrEmpty(text); |
10148
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
9914
diff
changeset
|
2272 |
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
9914
diff
changeset
|
2273 if (!reset) { |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10487
diff
changeset
|
2274 if (strlen(text) >= MAX_LENGTH_TOWN_NAME_BYTES) return CMD_ERROR; |
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10487
diff
changeset
|
2275 if (!IsUniqueTownName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
10148
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
9914
diff
changeset
|
2276 } |
7097
5c2889ace3ac
(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 <peter1138@openttd.org>
parents:
7058
diff
changeset
|
2277 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2278 if (flags & DC_EXEC) { |
8258
6017c5ebeb7e
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138 <peter1138@openttd.org>
parents:
8254
diff
changeset
|
2279 free(t->name); |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10487
diff
changeset
|
2280 t->name = reset ? NULL : strdup(text); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2281 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2282 UpdateTownVirtCoord(t); |
9387
a240dd49a2e8
(svn r13297) -Codechange: Use GUIList for the town directory window
peter1138 <peter1138@openttd.org>
parents:
9358
diff
changeset
|
2283 InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2284 UpdateAllStationVirtCoord(); |
7709
1859cffc251e
(svn r11243) -Fix: update waypoint signs when renaming a town
glx <glx@openttd.org>
parents:
7684
diff
changeset
|
2285 UpdateAllWaypointSigns(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2286 MarkWholeScreenDirty(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2287 } |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6946
diff
changeset
|
2288 return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2289 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2290 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2291 /** Called from GUI */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2292 void ExpandTown(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2293 { |
11290
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2294 /* Warn the users if towns are not allowed to build roads, |
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2295 * but do this only onces per openttd run. */ |
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2296 static bool warned_no_roads = false; |
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2297 if (!_settings_game.economy.allow_town_roads && !warned_no_roads) { |
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2298 ShowErrorMessage(INVALID_STRING_ID, STR_TOWN_EXPAND_WARN_NO_ROADS, 0, 0); |
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2299 warned_no_roads = true; |
e1cd1326a902
(svn r15639) -Change: When you disable "Towns are allowed to build roads", pressing "Expand" in the town window in the scenario editor will no longer build roads.
yexo <yexo@openttd.org>
parents:
11255
diff
changeset
|
2300 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2301 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2302 /* The more houses, the faster we grow */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2303 uint amount = RandomRange(ClampToU16(t->num_houses / 10)) + 3; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2304 t->num_houses += amount; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2305 UpdateTownRadius(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2306 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2307 uint n = amount * 10; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2308 do GrowTown(t); while (--n); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2309 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2310 t->num_houses -= amount; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2311 UpdateTownRadius(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2312 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2313 UpdateTownMaxPass(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2314 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2315 |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
2316 extern const byte _town_action_costs[8] = { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2317 2, 4, 9, 35, 48, 53, 117, 175 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2318 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2319 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2320 static void TownActionAdvertiseSmall(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2321 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2322 ModifyStationRatingAround(t->xy, _current_company, 0x40, 10); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2323 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2324 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2325 static void TownActionAdvertiseMedium(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2326 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2327 ModifyStationRatingAround(t->xy, _current_company, 0x70, 15); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2328 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2329 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2330 static void TownActionAdvertiseLarge(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2331 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2332 ModifyStationRatingAround(t->xy, _current_company, 0xA0, 20); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2333 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2334 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2335 static void TownActionRoadRebuild(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2336 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2337 t->road_build_months = 6; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2338 |
11219
1e8d1d0c7cd7
(svn r15572) -Fix (r13730): theoretical buffer overflow when company with too long name funded a road reconstruction
smatz <smatz@openttd.org>
parents:
11155
diff
changeset
|
2339 char company_name[MAX_LENGTH_COMPANY_NAME_BYTES]; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2340 SetDParam(0, _current_company); |
11219
1e8d1d0c7cd7
(svn r15572) -Fix (r13730): theoretical buffer overflow when company with too long name funded a road reconstruction
smatz <smatz@openttd.org>
parents:
11155
diff
changeset
|
2341 GetString(company_name, STR_COMPANY_NAME, lastof(company_name)); |
1e8d1d0c7cd7
(svn r15572) -Fix (r13730): theoretical buffer overflow when company with too long name funded a road reconstruction
smatz <smatz@openttd.org>
parents:
11155
diff
changeset
|
2342 |
1e8d1d0c7cd7
(svn r15572) -Fix (r13730): theoretical buffer overflow when company with too long name funded a road reconstruction
smatz <smatz@openttd.org>
parents:
11155
diff
changeset
|
2343 char *cn = strdup(company_name); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2344 SetDParam(0, t->index); |
11219
1e8d1d0c7cd7
(svn r15572) -Fix (r13730): theoretical buffer overflow when company with too long name funded a road reconstruction
smatz <smatz@openttd.org>
parents:
11155
diff
changeset
|
2345 SetDParamStr(1, cn); |
1e8d1d0c7cd7
(svn r15572) -Fix (r13730): theoretical buffer overflow when company with too long name funded a road reconstruction
smatz <smatz@openttd.org>
parents:
11155
diff
changeset
|
2346 |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
2347 AddNewsItem(STR_NEWS_ROAD_REBUILDING, NS_GENERAL, t->xy, 0, cn); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2348 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2349 |
6257
d7d39048e2ee
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight <truelight@openttd.org>
parents:
6247
diff
changeset
|
2350 static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2351 { |
7549
b202efd99ae5
(svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium <rubidium@openttd.org>
parents:
7545
diff
changeset
|
2352 /* Statues can be build on slopes, just like houses. Only the steep slopes is a no go. */ |
b202efd99ae5
(svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium <rubidium@openttd.org>
parents:
7545
diff
changeset
|
2353 if (IsSteepSlope(GetTileSlope(tile, NULL))) return false; |
11057
a56076ea98c6
(svn r15397) -Fix [FS#2618]: a town could build a statue under a bridge.
rubidium <rubidium@openttd.org>
parents:
11041
diff
changeset
|
2354 /* Don't build statues under bridges. */ |
a56076ea98c6
(svn r15397) -Fix [FS#2618]: a town could build a statue under a bridge.
rubidium <rubidium@openttd.org>
parents:
11041
diff
changeset
|
2355 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2356 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2357 if (!IsTileType(tile, MP_HOUSE) && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2358 !IsTileType(tile, MP_CLEAR) && |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2359 !IsTileType(tile, MP_TREES)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2360 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2361 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2362 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2363 CompanyID old = _current_company; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2364 _current_company = OWNER_NONE; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2365 CommandCost r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2366 _current_company = old; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2367 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2368 if (CmdFailed(r)) return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2369 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2370 MakeStatue(tile, _current_company, town_id); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2371 MarkTileDirtyByTile(tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2372 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2373 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2374 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2375 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2376 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2377 * Search callback function for TownActionBuildStatue |
6484
17fdaec13730
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas <belugas@openttd.org>
parents:
6455
diff
changeset
|
2378 * @param tile on which to perform the search |
9592
b8910fe673fc
(svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch <frosch@openttd.org>
parents:
9581
diff
changeset
|
2379 * @param user_data The town_id for which we want a statue |
6201
3b141366478a
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents:
6133
diff
changeset
|
2380 * @return the result of the test |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2381 */ |
9592
b8910fe673fc
(svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch <frosch@openttd.org>
parents:
9581
diff
changeset
|
2382 static bool SearchTileForStatue(TileIndex tile, void *user_data) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2383 { |
9592
b8910fe673fc
(svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch <frosch@openttd.org>
parents:
9581
diff
changeset
|
2384 TownID *town_id = (TownID *)user_data; |
b8910fe673fc
(svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch <frosch@openttd.org>
parents:
9581
diff
changeset
|
2385 return DoBuildStatueOfCompany(tile, *town_id); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2386 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2387 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2388 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2389 * Perform a 9x9 tiles circular search from the center of the town |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2390 * in order to find a free tile to place a statue |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2391 * @param t town to search in |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2392 */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2393 static void TownActionBuildStatue(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2394 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2395 TileIndex tile = t->xy; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2396 |
9592
b8910fe673fc
(svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
frosch <frosch@openttd.org>
parents:
9581
diff
changeset
|
2397 if (CircularTileSearch(&tile, 9, SearchTileForStatue, &t->index)) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2398 SetBit(t->statues, _current_company); // Once found and built, "inform" the Town |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2399 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2400 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2401 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2402 static void TownActionFundBuildings(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2403 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2404 /* Build next tick */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2405 t->grow_counter = 1; |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2406 /* If we were not already growing */ |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
2407 SetBit(t->flags12, TOWN_IS_FUNDED); |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2408 /* And grow for 3 months */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2409 t->fund_buildings_months = 3; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2410 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2411 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2412 static void TownActionBuyRights(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2413 { |
7657
65ad965cd225
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium <rubidium@openttd.org>
parents:
7642
diff
changeset
|
2414 /* Check if it's allowed to by the rights */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
2415 if (!_settings_game.economy.exclusive_rights) return; |
7657
65ad965cd225
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium <rubidium@openttd.org>
parents:
7642
diff
changeset
|
2416 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2417 t->exclusive_counter = 12; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2418 t->exclusivity = _current_company; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2419 |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2420 ModifyStationRatingAround(t->xy, _current_company, 130, 17); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2421 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2422 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2423 static void TownActionBribe(Town *t) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2424 { |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2425 if (Chance16(1, 14)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2426 /* set as unwanted for 6 months */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2427 t->unwanted[_current_company] = 6; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2428 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2429 /* set all close by station ratings to 0 */ |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2430 Station *st; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2431 FOR_ALL_STATIONS(st) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2432 if (st->town == t && st->owner == _current_company) { |
6350
8132258640be
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138 <peter1138@openttd.org>
parents:
6343
diff
changeset
|
2433 for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2434 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2435 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2436 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2437 /* only show errormessage to the executing player. All errors are handled command.c |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2438 * but this is special, because it can only 'fail' on a DC_EXEC */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2439 if (IsLocalCompany()) ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2440 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2441 /* decrease by a lot! |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2442 * ChangeTownRating is only for stuff in demolishing. Bribe failure should |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2443 * be independent of any cheat settings |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2444 */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2445 if (t->ratings[_current_company] > RATING_BRIBE_DOWN_TO) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2446 t->ratings[_current_company] = RATING_BRIBE_DOWN_TO; |
9444
c0d73c88570a
(svn r13362) -Fix: make the town authority window a bit less glitchy
smatz <smatz@openttd.org>
parents:
9436
diff
changeset
|
2447 InvalidateWindow(WC_TOWN_AUTHORITY, t->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2448 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2449 } else { |
11106
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2450 ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM, DC_EXEC); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2451 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2452 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2453 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2454 typedef void TownActionProc(Town *t); |
11376
b9b2391afd1a
(svn r15726) -Codechange: unify coding style for const pointers
smatz <smatz@openttd.org>
parents:
11368
diff
changeset
|
2455 static TownActionProc * const _town_action_proc[] = { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2456 TownActionAdvertiseSmall, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2457 TownActionAdvertiseMedium, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2458 TownActionAdvertiseLarge, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2459 TownActionRoadRebuild, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2460 TownActionBuildStatue, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2461 TownActionFundBuildings, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2462 TownActionBuyRights, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2463 TownActionBribe |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2464 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2465 |
10814
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2466 enum TownActions { |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2467 TACT_NONE = 0x00, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2468 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2469 TACT_ADVERTISE_SMALL = 0x01, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2470 TACT_ADVERTISE_MEDIUM = 0x02, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2471 TACT_ADVERTISE_LARGE = 0x04, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2472 TACT_ROAD_REBUILD = 0x08, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2473 TACT_BUILD_STATUE = 0x10, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2474 TACT_FOUND_BUILDINGS = 0x20, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2475 TACT_BUY_RIGHTS = 0x40, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2476 TACT_BRIBE = 0x80, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2477 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2478 TACT_ADVERTISE = TACT_ADVERTISE_SMALL | TACT_ADVERTISE_MEDIUM | TACT_ADVERTISE_LARGE, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2479 TACT_CONSTRUCTION = TACT_ROAD_REBUILD | TACT_BUILD_STATUE | TACT_FOUND_BUILDINGS, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2480 TACT_FUNDS = TACT_BUY_RIGHTS | TACT_BRIBE, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2481 TACT_ALL = TACT_ADVERTISE | TACT_CONSTRUCTION | TACT_FUNDS, |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2482 }; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2483 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2484 DECLARE_ENUM_AS_BIT_SET(TownActions); |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2485 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2486 /** Get a list of available actions to do at a town. |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2487 * @param nump if not NULL add put the number of available actions in it |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2488 * @param cid the company that is querying the town |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2489 * @param t the town that is queried |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2490 * @return bitmasked value of enabled actions |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2491 */ |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2492 uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t) |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2493 { |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2494 int num = 0; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2495 TownActions buttons = TACT_NONE; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2496 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2497 /* Spectators and unwanted have no options */ |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2498 if (cid != COMPANY_SPECTATOR && !(_settings_game.economy.bribe && t->unwanted[cid])) { |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2499 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2500 /* Things worth more than this are not shown */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11908
diff
changeset
|
2501 Money avail = Company::Get(cid)->money + _price.station_value * 200; |
10814
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2502 Money ref = _price.build_industry >> 8; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2503 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2504 /* Check the action bits for validity and |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2505 * if they are valid add them */ |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2506 for (uint i = 0; i != lengthof(_town_action_costs); i++) { |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2507 const TownActions cur = (TownActions)(1 << i); |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2508 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2509 /* Is the company not able to bribe ? */ |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2510 if (cur == TACT_BRIBE && (!_settings_game.economy.bribe || t->ratings[cid] >= RATING_BRIBE_MAXIMUM)) |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2511 continue; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2512 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2513 /* Is the company not able to buy exclusive rights ? */ |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2514 if (cur == TACT_BUY_RIGHTS && !_settings_game.economy.exclusive_rights) |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2515 continue; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2516 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2517 /* Is the company not able to build a statue ? */ |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2518 if (cur == TACT_BUILD_STATUE && HasBit(t->statues, cid)) |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2519 continue; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2520 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2521 if (avail >= _town_action_costs[i] * ref) { |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2522 buttons |= cur; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2523 num++; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2524 } |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2525 } |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2526 } |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2527 |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2528 if (nump != NULL) *nump = num; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2529 return buttons; |
7d649936eaa3
(svn r15149) -Codechange: GetMaskOfTownActions() is used by a Cmd handler, therefore it does not belong in _gui.
peter1138 <peter1138@openttd.org>
parents:
10696
diff
changeset
|
2530 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2531 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2532 /** Do a town action. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2533 * This performs an action such as advertising, building a statue, funding buildings, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2534 * but also bribing the town-council |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2535 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2536 * @param flags type of operation |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2537 * @param p1 town to do the action at |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2538 * @param p2 action to perform, @see _town_action_proc for the list of available actions |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2539 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
2540 CommandCost CmdDoTownAction(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2541 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11926
diff
changeset
|
2542 Town *t = Town::GetIfValid(p1); |
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11926
diff
changeset
|
2543 if (t == NULL || p2 >= lengthof(_town_action_proc)) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2544 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2545 if (!HasBit(GetMaskOfTownActions(NULL, _current_company, t), p2)) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2546 |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
2547 CommandCost cost(EXPENSES_OTHER, (_price.build_industry >> 8) * _town_action_costs[p2]); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2548 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2549 if (flags & DC_EXEC) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2550 _town_action_proc[p2](t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2551 InvalidateWindow(WC_TOWN_AUTHORITY, p1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2552 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2553 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2554 return cost; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2555 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2556 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2557 static void UpdateTownGrowRate(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2558 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2559 /* Increase company ratings if they're low */ |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2560 const Company *c; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2561 FOR_ALL_COMPANIES(c) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2562 if (t->ratings[c->index] < RATING_GROWTH_MAXIMUM) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2563 t->ratings[c->index] = min((int)RATING_GROWTH_MAXIMUM, t->ratings[c->index] + RATING_GROWTH_UP_STEP); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2564 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2565 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2566 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2567 int n = 0; |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2568 |
8816
d278baac2725
(svn r12562) -Cleanup: variable scope in terraform_cmd.cpp
smatz <smatz@openttd.org>
parents:
8815
diff
changeset
|
2569 const Station *st; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2570 FOR_ALL_STATIONS(st) { |
8943
d5c75b8f3503
(svn r12726) -Fix [FS#1877]: overflow causing strange building behaviour in towns.
rubidium <rubidium@openttd.org>
parents:
8942
diff
changeset
|
2571 if (DistanceSquare(st->xy, t->xy) <= t->squared_town_zone_radius[0]) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2572 if (st->time_since_load <= 20 || st->time_since_unload <= 20) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2573 n++; |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
2574 if (Company::IsValidID(st->owner)) { |
8815
d89ac2583e59
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
smatz <smatz@openttd.org>
parents:
8814
diff
changeset
|
2575 int new_rating = t->ratings[st->owner] + RATING_STATION_UP_STEP; |
d89ac2583e59
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
smatz <smatz@openttd.org>
parents:
8814
diff
changeset
|
2576 t->ratings[st->owner] = min(new_rating, INT16_MAX); // do not let it overflow |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2577 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2578 } else { |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
2579 if (Company::IsValidID(st->owner)) { |
8815
d89ac2583e59
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
smatz <smatz@openttd.org>
parents:
8814
diff
changeset
|
2580 int new_rating = t->ratings[st->owner] + RATING_STATION_DOWN_STEP; |
d89ac2583e59
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
smatz <smatz@openttd.org>
parents:
8814
diff
changeset
|
2581 t->ratings[st->owner] = max(new_rating, INT16_MIN); |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2582 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2583 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2584 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2585 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2586 |
8815
d89ac2583e59
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
smatz <smatz@openttd.org>
parents:
8814
diff
changeset
|
2587 /* clamp all ratings to valid values */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2588 for (uint i = 0; i < MAX_COMPANIES; i++) { |
8815
d89ac2583e59
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
smatz <smatz@openttd.org>
parents:
8814
diff
changeset
|
2589 t->ratings[i] = Clamp(t->ratings[i], RATING_MINIMUM, RATING_MAXIMUM); |
d89ac2583e59
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
smatz <smatz@openttd.org>
parents:
8814
diff
changeset
|
2590 } |
d89ac2583e59
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
smatz <smatz@openttd.org>
parents:
8814
diff
changeset
|
2591 |
9444
c0d73c88570a
(svn r13362) -Fix: make the town authority window a bit less glitchy
smatz <smatz@openttd.org>
parents:
9436
diff
changeset
|
2592 InvalidateWindow(WC_TOWN_AUTHORITY, t->index); |
c0d73c88570a
(svn r13362) -Fix: make the town authority window a bit less glitchy
smatz <smatz@openttd.org>
parents:
9436
diff
changeset
|
2593 |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
2594 ClrBit(t->flags12, TOWN_IS_FUNDED); |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
2595 if (_settings_game.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return; |
6454
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
2596 |
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
2597 /** Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the |
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
2598 * number of times towns are processed before a new building is built. */ |
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
2599 static const uint16 _grow_count_values[2][6] = { |
7641
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
2600 { 120, 120, 120, 100, 80, 60 }, // Fund new buildings has been activated |
5e3cd60f89c4
(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 <rubidium@openttd.org>
parents:
7603
diff
changeset
|
2601 { 320, 420, 300, 220, 160, 100 } // Normal values |
6454
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
2602 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2603 |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2604 uint16 m; |
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2605 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2606 if (t->fund_buildings_months != 0) { |
6454
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
2607 m = _grow_count_values[0][min(n, 5)]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2608 t->fund_buildings_months--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2609 } else { |
6454
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
2610 m = _grow_count_values[1][min(n, 5)]; |
7967
e30c5ec2d272
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13 <skidd13@openttd.org>
parents:
7931
diff
changeset
|
2611 if (n == 0 && !Chance16(1, 12)) return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2612 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2613 |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
2614 if (_settings_game.game_creation.landscape == LT_ARCTIC) { |
6343
f75b72d9fc98
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros <maedhros@openttd.org>
parents:
6342
diff
changeset
|
2615 if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2616 return; |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
2617 } else if (_settings_game.game_creation.landscape == LT_TROPIC) { |
8969
01cc3ee6ecb1
(svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium <rubidium@openttd.org>
parents:
8965
diff
changeset
|
2618 if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food == 0 || t->act_water == 0) && t->population > 60) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2619 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2620 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2621 |
6455
d686356a6da6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros <maedhros@openttd.org>
parents:
6454
diff
changeset
|
2622 /* Use the normal growth rate values if new buildings have been funded in |
d686356a6da6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros <maedhros@openttd.org>
parents:
6454
diff
changeset
|
2623 * this town and the growth rate is set to none. */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
2624 uint growth_multiplier = _settings_game.economy.town_growth_rate != 0 ? _settings_game.economy.town_growth_rate - 1 : 1; |
6455
d686356a6da6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros <maedhros@openttd.org>
parents:
6454
diff
changeset
|
2625 |
d686356a6da6
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros <maedhros@openttd.org>
parents:
6454
diff
changeset
|
2626 m >>= growth_multiplier; |
6486
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
2627 if (t->larger_town) m /= 2; |
6454
b0788d6496a9
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents:
6427
diff
changeset
|
2628 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2629 t->growth_rate = m / (t->num_houses / 50 + 1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2630 if (m <= t->grow_counter) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2631 t->grow_counter = m; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2632 |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
2633 SetBit(t->flags12, TOWN_IS_FUNDED); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2634 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2635 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2636 static void UpdateTownAmounts(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2637 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2638 /* Using +1 here to prevent overflow and division by zero */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2639 t->pct_pass_transported = t->new_act_pass * 256 / (t->new_max_pass + 1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2640 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2641 t->max_pass = t->new_max_pass; t->new_max_pass = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2642 t->act_pass = t->new_act_pass; t->new_act_pass = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2643 t->act_food = t->new_act_food; t->new_act_food = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2644 t->act_water = t->new_act_water; t->new_act_water = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2645 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2646 /* Using +1 here to prevent overflow and division by zero */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2647 t->pct_mail_transported = t->new_act_mail * 256 / (t->new_max_mail + 1); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2648 t->max_mail = t->new_max_mail; t->new_max_mail = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2649 t->act_mail = t->new_act_mail; t->new_act_mail = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2650 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2651 InvalidateWindow(WC_TOWN_VIEW, t->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2652 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2653 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2654 static void UpdateTownUnwanted(Town *t) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2655 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2656 const Company *c; |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2657 |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2658 FOR_ALL_COMPANIES(c) { |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2659 if (t->unwanted[c->index] > 0) t->unwanted[c->index]--; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2660 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2661 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2662 |
10681
b232483d773c
(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.
frosch <frosch@openttd.org>
parents:
10656
diff
changeset
|
2663 /** |
b232483d773c
(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.
frosch <frosch@openttd.org>
parents:
10656
diff
changeset
|
2664 * Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile |
b232483d773c
(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.
frosch <frosch@openttd.org>
parents:
10656
diff
changeset
|
2665 * @param tile The tile where the station shall be constructed. |
11103
5980315ec1f3
(svn r15449) -Codechange: Rename DC_NO_TOWN_RATING to DC_NO_TEST_TOWN_RATING as that is what it does.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
2666 * @param flags Command flags. DC_NO_TEST_TOWN_RATING is tested. |
10681
b232483d773c
(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.
frosch <frosch@openttd.org>
parents:
10656
diff
changeset
|
2667 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
2668 bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2669 { |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
2670 if (!Company::IsValidID(_current_company) || (flags & DC_NO_TEST_TOWN_RATING)) return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2671 |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9387
diff
changeset
|
2672 Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2673 if (t == NULL) return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2674 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2675 if (t->ratings[_current_company] > RATING_VERYPOOR) return true; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2676 |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
2677 _error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2678 SetDParam(0, t->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2679 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2680 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2681 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2682 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2683 |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
2684 Town *CalcClosestTownFromTile(TileIndex tile, uint threshold, const Town *ignore) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2685 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2686 Town *t; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2687 uint best = threshold; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2688 Town *best_town = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2689 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2690 FOR_ALL_TOWNS(t) { |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
2691 if (t == ignore) continue; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2692 uint dist = DistanceManhattan(tile, t->xy); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2693 if (dist < best) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2694 best = dist; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2695 best_town = t; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2696 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2697 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2698 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2699 return best_town; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2700 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2701 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2702 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2703 Town *ClosestTownFromTile(TileIndex tile, uint threshold) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2704 { |
10340
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2705 switch (GetTileType(tile)) { |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2706 case MP_ROAD: |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2707 if (!HasTownOwnedRoad(tile)) { |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2708 TownID tid = GetTownIndex(tile); |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
2709 |
10340
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2710 if (tid == (TownID)INVALID_TOWN) { |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2711 /* in the case we are generating "many random towns", this value may be INVALID_TOWN */ |
10345
3f904839d38f
(svn r14596) -Fix (r14591): Missing 'return'.
frosch <frosch@openttd.org>
parents:
10340
diff
changeset
|
2712 if (_generating_world) return CalcClosestTownFromTile(tile, threshold); |
11973
e17a54c88806
(svn r16379) -Codechange: remove GetNumTowns(), GetNumIndustries() and GetActiveCompanyCount(), use PoolItem::GetNumItems() instead
smatz <smatz@openttd.org>
parents:
11972
diff
changeset
|
2713 assert(Town::GetNumItems() == 0); |
10340
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2714 return NULL; |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2715 } |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2716 |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
2717 assert(Town::IsValidID(tid)); |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11908
diff
changeset
|
2718 Town *town = Town::Get(tid); |
10340
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2719 |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2720 if (DistanceManhattan(tile, town->xy) >= threshold) town = NULL; |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2721 |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2722 return town; |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2723 } |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2724 /* FALL THROUGH */ |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2725 |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2726 case MP_HOUSE: |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2727 return GetTownByTile(tile); |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2728 |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2729 default: |
e3f0f062c7c3
(svn r14591) -Fix [FS#2388](r14528): cached nearest town could be invalid after importing older savegame and during town generation
smatz <smatz@openttd.org>
parents:
10289
diff
changeset
|
2730 return CalcClosestTownFromTile(tile, threshold); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2731 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2732 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2733 |
8232
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2734 static bool _town_rating_test = false; |
10487
75d47d3e0644
(svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents:
10480
diff
changeset
|
2735 SmallMap<const Town *, int, 4> _town_test_ratings; |
8232
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2736 |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2737 void SetTownRatingTestMode(bool mode) |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2738 { |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2739 static int ref_count = 0; |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2740 if (mode) { |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2741 if (ref_count == 0) { |
10487
75d47d3e0644
(svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents:
10480
diff
changeset
|
2742 _town_test_ratings.Clear(); |
8232
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2743 } |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2744 ref_count++; |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2745 } else { |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2746 assert(ref_count > 0); |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2747 ref_count--; |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2748 } |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2749 _town_rating_test = !(ref_count == 0); |
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2750 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2751 |
9040
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2752 static int GetRating(const Town *t) |
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2753 { |
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2754 if (_town_rating_test) { |
10487
75d47d3e0644
(svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents:
10480
diff
changeset
|
2755 SmallMap<const Town *, int>::iterator it = _town_test_ratings.Find(t); |
75d47d3e0644
(svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents:
10480
diff
changeset
|
2756 if (it != _town_test_ratings.End()) { |
75d47d3e0644
(svn r14742) -Codechange: use SmallMap in two cases to reduce compilation time and binary size
smatz <smatz@openttd.org>
parents:
10480
diff
changeset
|
2757 return it->second; |
9040
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2758 } |
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2759 } |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2760 return t->ratings[_current_company]; |
9040
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2761 } |
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2762 |
11106
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2763 /** |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2764 * Changes town rating of the current company |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2765 * @param t Town to affect |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2766 * @param add Value to add |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2767 * @param max Minimum (add < 0) resp. maximum (add > 0) rating that should be archievable with this change |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2768 * @param flags Command flags, especially DC_NO_MODIFY_TOWN_RATING is tested |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2769 */ |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2770 void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2771 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2772 /* if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff */ |
11106
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
2773 if (t == NULL || (flags & DC_NO_MODIFY_TOWN_RATING) || |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
2774 !Company::IsValidID(_current_company) || |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2775 (_cheats.magic_bulldozer.value && add < 0)) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2776 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2777 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2778 |
9040
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2779 int rating = GetRating(t); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2780 if (add < 0) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2781 if (rating > max) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2782 rating += add; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2783 if (rating < max) rating = max; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2784 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2785 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2786 if (rating < max) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2787 rating += add; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2788 if (rating > max) rating = max; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2789 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2790 } |
8232
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2791 if (_town_rating_test) { |
9040
37ec76c96c04
(svn r12859) -Fix: make the town rating tests use less memory and much quicker; from 13% to unnoticable in the profile in games with lots of towns and lots of very active AIs.
rubidium <rubidium@openttd.org>
parents:
9036
diff
changeset
|
2792 _town_test_ratings[t] = rating; |
8232
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2793 } else { |
11312
74e7c86b79aa
(svn r15662) -Fix (r11795): Don't mark a company as having ratings in a town when querying the cost of a command.
peter1138 <peter1138@openttd.org>
parents:
11293
diff
changeset
|
2794 SetBit(t->have_ratings, _current_company); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2795 t->ratings[_current_company] = rating; |
9444
c0d73c88570a
(svn r13362) -Fix: make the town authority window a bit less glitchy
smatz <smatz@openttd.org>
parents:
9436
diff
changeset
|
2796 InvalidateWindow(WC_TOWN_AUTHORITY, t->index); |
8232
cca79a4335e0
(svn r11795) -Fix [FS#1616]: take town rating into account when testing if a command can be executed.
glx <glx@openttd.org>
parents:
8230
diff
changeset
|
2797 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2798 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2799 |
11879
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2800 bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2801 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2802 /* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */ |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
2803 if (t == NULL || !Company::IsValidID(_current_company) || |
11879
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2804 _cheats.magic_bulldozer.value || (flags & DC_NO_TEST_TOWN_RATING)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2805 return true; |
11879
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2806 } |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2807 |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2808 /* minimum rating needed to be allowed to remove stuff */ |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2809 static const int needed_rating[][TOWN_RATING_CHECK_TYPE_COUNT] = { |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2810 /* ROAD_REMOVE, TUNNELBRIDGE_REMOVE */ |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2811 { RATING_ROAD_NEEDED_PERMISSIVE, RATING_TUNNEL_BRIDGE_NEEDED_PERMISSIVE}, // Permissive |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2812 { RATING_ROAD_NEEDED_NEUTRAL, RATING_TUNNEL_BRIDGE_NEEDED_NEUTRAL}, // Neutral |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2813 { RATING_ROAD_NEEDED_HOSTILE, RATING_TUNNEL_BRIDGE_NEEDED_HOSTILE}, // Hostile |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2814 }; |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2815 |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2816 /* check if you're allowed to remove the road/bridge/tunnel |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2817 * owned by a town no removal if rating is lower than ... depends now on |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2818 * difficulty setting. Minimum town rating selected by difficulty level |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2819 */ |
11879
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2820 int needed = needed_rating[_settings_game.difficulty.town_council_tolerance][type]; |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2821 |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
2822 if (GetRating(t) < needed) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2823 SetDParam(0, t->index); |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11713
diff
changeset
|
2824 _error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2825 return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2826 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2827 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2828 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2829 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2830 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
2831 void TownsMonthlyLoop() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2832 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2833 Town *t; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2834 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2835 FOR_ALL_TOWNS(t) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2836 if (t->road_build_months != 0) t->road_build_months--; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2837 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2838 if (t->exclusive_counter != 0) |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10191
diff
changeset
|
2839 if (--t->exclusive_counter == 0) t->exclusivity = INVALID_COMPANY; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2840 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2841 UpdateTownGrowRate(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2842 UpdateTownAmounts(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2843 UpdateTownUnwanted(t); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2844 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2845 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2846 |
10360
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2847 void TownsYearlyLoop() |
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2848 { |
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2849 /* Increment house ages */ |
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2850 for (TileIndex t = 0; t < MapSize(); t++) { |
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2851 if (!IsTileType(t, MP_HOUSE)) continue; |
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2852 IncrementHouseAge(t); |
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2853 } |
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2854 } |
d352cf399eb7
(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
frosch <frosch@openttd.org>
parents:
10345
diff
changeset
|
2855 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
2856 void InitializeTowns() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2857 { |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11949
diff
changeset
|
2858 _town_pool.CleanPool(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2859 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2860 memset(_subsidies, 0, sizeof(_subsidies)); |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2861 for (Subsidy *s = _subsidies; s != endof(_subsidies); s++) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2862 s->cargo_type = CT_INVALID; |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2863 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2864 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2865 |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
2866 static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new) |
7494
3f6f5fcc079a
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium <rubidium@openttd.org>
parents:
7483
diff
changeset
|
2867 { |
7582
e77bd387f449
(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 <rubidium@openttd.org>
parents:
7577
diff
changeset
|
2868 if (AutoslopeEnabled()) { |
e77bd387f449
(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 <rubidium@openttd.org>
parents:
7577
diff
changeset
|
2869 HouseID house = GetHouseType(tile); |
8942
a1797e9f9173
(svn r12717) -Fix (r11107): Check the TILE_NOT_SLOPED flag of the _north_ tile of multi-tile houses to decide if autoslope is allowed.
frosch <frosch@openttd.org>
parents:
8847
diff
changeset
|
2870 GetHouseNorthPart(house); // modifies house to the ID of the north tile |
8814
eb3b487b80a4
(svn r12560) -Cleanup: town_cmd.cpp and header files - variable scope and a bit of coding style
smatz <smatz@openttd.org>
parents:
8806
diff
changeset
|
2871 const HouseSpec *hs = GetHouseSpecs(house); |
7582
e77bd387f449
(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 <rubidium@openttd.org>
parents:
7577
diff
changeset
|
2872 |
e77bd387f449
(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 <rubidium@openttd.org>
parents:
7577
diff
changeset
|
2873 /* Here we differ from TTDP by checking TILE_NOT_SLOPED */ |
e77bd387f449
(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 <rubidium@openttd.org>
parents:
7577
diff
changeset
|
2874 if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) && |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
2875 (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); |
7582
e77bd387f449
(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 <rubidium@openttd.org>
parents:
7577
diff
changeset
|
2876 } |
e77bd387f449
(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 <rubidium@openttd.org>
parents:
7577
diff
changeset
|
2877 |
7494
3f6f5fcc079a
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium <rubidium@openttd.org>
parents:
7483
diff
changeset
|
2878 return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
3f6f5fcc079a
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium <rubidium@openttd.org>
parents:
7483
diff
changeset
|
2879 } |
3f6f5fcc079a
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium <rubidium@openttd.org>
parents:
7483
diff
changeset
|
2880 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2881 /** Tile callback functions for a town */ |
5587
c44c070c5032
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents:
5584
diff
changeset
|
2882 extern const TileTypeProcs _tile_type_town_procs = { |
10259
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2883 DrawTile_Town, // draw_tile_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2884 GetSlopeZ_Town, // get_slope_z_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2885 ClearTile_Town, // clear_tile_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2886 GetAcceptedCargo_Town, // get_accepted_cargo_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2887 GetTileDesc_Town, // get_tile_desc_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2888 GetTileTrackStatus_Town, // get_tile_track_status_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2889 ClickTile_Town, // click_tile_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2890 AnimateTile_Town, // animate_tile_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2891 TileLoop_Town, // tile_loop_clear |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2892 ChangeTileOwner_Town, // change_tile_owner_clear |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2893 GetProducedCargo_Town, // get_produced_cargo_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2894 NULL, // vehicle_enter_tile_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2895 GetFoundation_Town, // get_foundation_proc |
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
2896 TerraformTile_Town, // terraform_tile_proc |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2897 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2898 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2899 void ResetHouses() |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2900 { |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2901 memset(&_house_specs, 0, sizeof(_house_specs)); |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2902 memcpy(&_house_specs, &_original_house_specs, sizeof(_original_house_specs)); |
7666
93b6cfc32b2e
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas <belugas@openttd.org>
parents:
7657
diff
changeset
|
2903 |
93b6cfc32b2e
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas <belugas@openttd.org>
parents:
7657
diff
changeset
|
2904 /* Reset any overrides that have been set. */ |
93b6cfc32b2e
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas <belugas@openttd.org>
parents:
7657
diff
changeset
|
2905 _house_mngr.ResetOverride(); |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2906 } |