Mercurial > hg > openttd
annotate src/town_cmd.cpp @ 19290:68bfe04ccd9a draft
(svn r24179) -Codechange: move some variables of Town to TownCache
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 25 Apr 2012 20:50:13 +0000 |
parents | 87d0ea2d8725 |
children | 880b56912255 |
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 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12658
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12658
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12658
diff
changeset
|
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12658
diff
changeset
|
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12658
diff
changeset
|
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12658
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12658
diff
changeset
|
9 |
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
|
10 /** @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
|
11 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
8102
afb4c7da91df
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium <rubidium@openttd.org>
parents:
8088
diff
changeset
|
13 #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
|
14 #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
|
15 #include "landscape.h" |
8224
c45446125bf0
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents:
8214
diff
changeset
|
16 #include "viewport_func.h" |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
15002
diff
changeset
|
17 #include "cmd_helper.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
|
18 #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
|
19 #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
|
20 #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
|
21 #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
|
22 #include "news_func.h" |
18627
1972f6346144
(svn r23474) -Codechange: move the declaration error related functions to error.h
rubidium <rubidium@openttd.org>
parents:
18562
diff
changeset
|
23 #include "error.h" |
15744
f9e8032ac213
(svn r20411) -Codechange: rename unmovables as quite a lot of them are actually movable; e.g. HQ and owned land are pretty movable.
rubidium <rubidium@openttd.org>
parents:
15742
diff
changeset
|
24 #include "object.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
|
25 #include "genworld.h" |
15083
68d1f9ea65c3
(svn r19709) -Feature: NewGRF debugging/inspecting of (primarily) enabled callbacks and values of variables
rubidium <rubidium@openttd.org>
parents:
15037
diff
changeset
|
26 #include "newgrf_debug.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
|
27 #include "newgrf_house.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" |
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
|
30 #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
|
31 #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
|
32 #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
|
33 #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
|
34 #include "newgrf_cargo.h" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10855
diff
changeset
|
35 #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
|
36 #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
|
37 #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
|
38 #include "subsidy_func.h" |
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
|
39 #include "core/pool_func.hpp" |
12249
559350145373
(svn r16664) -Codechange: move house-related stuff from town.h and town_type.h to separate files
smatz <smatz@openttd.org>
parents:
12245
diff
changeset
|
40 #include "town.h" |
13110
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
41 #include "townname_func.h" |
14258
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
14167
diff
changeset
|
42 #include "core/random_func.hpp" |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15115
diff
changeset
|
43 #include "core/backup_type.hpp" |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
44 #include "depot_base.h" |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
45 #include "object_map.h" |
15807
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
46 #include "object_base.h" |
16929
9345826dd1fd
(svn r21664) -Add: [NoAI] AIEventTownFounded
yexo <yexo@openttd.org>
parents:
16683
diff
changeset
|
47 #include "ai/ai.hpp" |
18774
1fa19d70aea9
(svn r23622) -Add: a set of events to trigger in a GameScript
truebrain <truebrain@openttd.org>
parents:
18772
diff
changeset
|
48 #include "game/game.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
|
49 |
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
|
50 #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
|
51 #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
|
52 |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
53 TownID _new_town_id; |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
54 uint32 _town_cargoes_accepted; ///< Bitmap of all cargoes accepted by houses. |
8268
ab53b3bf7100
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
55 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
56 /* 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
|
57 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
|
58 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
|
59 |
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
60 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
|
61 { |
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
|
62 free(this->name); |
18778
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
63 free(this->text); |
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
|
64 |
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 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
|
66 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
67 /* 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
|
68 * 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
|
69 DeleteWindowById(WC_TOWN_VIEW, 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
|
70 |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
71 /* Check no industry is related to us. */ |
15807
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
72 const Industry *i; |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
73 FOR_ALL_INDUSTRIES(i) assert(i->town != this); |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
74 |
15807
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
75 /* ... and no object is related to us. */ |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
76 const Object *o; |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
77 FOR_ALL_OBJECTS(o) assert(o->town != this); |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
78 |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
79 /* Check no tile is related to us. */ |
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
|
80 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
|
81 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
|
82 case MP_HOUSE: |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
83 assert(GetTownIndex(tile) != 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
|
84 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
85 |
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
|
86 case MP_ROAD: |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
87 assert(!HasTownOwnedRoad(tile) || GetTownIndex(tile) != this->index); |
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
|
88 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
|
89 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
90 case MP_TUNNELBRIDGE: |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
91 assert(!IsTileOwner(tile, OWNER_TOWN) || 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
|
92 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
93 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
94 default: |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
95 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
96 } |
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 |
17784
ebbbd5ad03d2
(svn r22569) -Feature: [NewGRF] Persistent storage for towns.
terkhen <terkhen@openttd.org>
parents:
17702
diff
changeset
|
99 /* Clear the persistent storage list. */ |
ebbbd5ad03d2
(svn r22569) -Feature: [NewGRF] Persistent storage for towns.
terkhen <terkhen@openttd.org>
parents:
17702
diff
changeset
|
100 this->psa_list.clear(); |
ebbbd5ad03d2
(svn r22569) -Feature: [NewGRF] Persistent storage for towns.
terkhen <terkhen@openttd.org>
parents:
17702
diff
changeset
|
101 |
12652
0f7fab6a27e9
(svn r17107) -Codechange: store type of subsidy source and destination in the Subsidy struct instead of determining it every time it's needed
smatz <smatz@openttd.org>
parents:
12632
diff
changeset
|
102 DeleteSubsidyWith(ST_TOWN, this->index); |
15083
68d1f9ea65c3
(svn r19709) -Feature: NewGRF debugging/inspecting of (primarily) enabled callbacks and values of variables
rubidium <rubidium@openttd.org>
parents:
15037
diff
changeset
|
103 DeleteNewGRFInspectWindow(GSF_FAKE_TOWNS, this->index); |
12658
b75d8c6681bd
(svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents:
12652
diff
changeset
|
104 CargoPacket::InvalidateAllFrom(ST_TOWN, 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
|
105 MarkWholeScreenDirty(); |
12326
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
106 } |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
107 |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
108 |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
109 /** |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
110 * Invalidating of the "nearest town cache" has to be done |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
111 * after removing item from the pool. |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
112 * @param index index of deleted item |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
113 */ |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
114 void Town::PostDestructor(size_t index) |
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
115 { |
13112
639555b91b28
(svn r17614) -Fix: crash when deleting town while TownDirectory is open
smatz <smatz@openttd.org>
parents:
13110
diff
changeset
|
116 InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0); |
12326
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
117 UpdateNearestTownForRoadTiles(false); |
15807
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
118 |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
119 /* Give objects a new home! */ |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
120 Object *o; |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
121 FOR_ALL_OBJECTS(o) { |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
122 if (o->town == NULL) o->town = CalcClosestTownFromTile(o->location.tile, UINT_MAX); |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
123 } |
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
|
124 } |
f9b4e970b14d
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents:
7370
diff
changeset
|
125 |
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
|
126 /** |
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
|
127 * 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
|
128 */ |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
129 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
|
130 { |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 } |
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
|
135 |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
136 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
|
137 } |
54e679b675c5
(svn r12534) -Feature: Add a new type of town road layouts - random for each town
skidd13 <skidd13@openttd.org>
parents:
8791
diff
changeset
|
138 |
12252
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
139 /** |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
140 * Return a random valid town. |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
141 * @return random town, NULL if there are no towns |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
142 */ |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
143 /* static */ Town *Town::GetRandom() |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
144 { |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
145 if (Town::GetNumItems() == 0) return NULL; |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
146 int num = RandomRange((uint16)Town::GetNumItems()); |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
147 size_t index = MAX_UVALUE(size_t); |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
148 |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
149 while (num >= 0) { |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
150 num--; |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
151 index++; |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
152 |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
153 /* Make sure we have a valid town */ |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
154 while (!Town::IsValidID(index)) { |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
155 index++; |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
156 assert(index < Town::GetPoolSize()); |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
157 } |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
158 } |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
159 |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
160 return Town::Get(index); |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
161 } |
f758517b6645
(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents:
12251
diff
changeset
|
162 |
17108
5ae3089defb2
(svn r21845) -Codechange: move documentation towards the code to make it more likely to be updates [d-m].
rubidium <rubidium@openttd.org>
parents:
16929
diff
changeset
|
163 /** |
5ae3089defb2
(svn r21845) -Codechange: move documentation towards the code to make it more likely to be updates [d-m].
rubidium <rubidium@openttd.org>
parents:
16929
diff
changeset
|
164 * Get the cost for removing this house |
5ae3089defb2
(svn r21845) -Codechange: move documentation towards the code to make it more likely to be updates [d-m].
rubidium <rubidium@openttd.org>
parents:
16929
diff
changeset
|
165 * @return the cost (inflation corrected etc) |
5ae3089defb2
(svn r21845) -Codechange: move documentation towards the code to make it more likely to be updates [d-m].
rubidium <rubidium@openttd.org>
parents:
16929
diff
changeset
|
166 */ |
9463
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
167 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
|
168 { |
13486
f2535c5098a0
(svn r18005) -Codechange: Convert the Prices struct into an array and an enum.
frosch <frosch@openttd.org>
parents:
13419
diff
changeset
|
169 return (_price[PR_CLEAR_HOUSE] * this->removal_cost) >> 8; |
9463
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
170 } |
371c474da67e
(svn r13383) -Codechange: Put the cost of house removal in a class member
belugas <belugas@openttd.org>
parents:
9450
diff
changeset
|
171 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
172 // Local |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
173 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
|
174 |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
175 /* 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
|
176 enum TownGrowthResult { |
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
177 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
|
178 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
|
179 // 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
|
180 }; |
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
181 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
182 static bool BuildTownHouse(Town *t, TileIndex tile); |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
183 static Town *CreateRandomTown(uint attempts, 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
|
184 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
185 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
|
186 { |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5587
diff
changeset
|
187 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
|
188 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
189 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
190 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
|
191 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
|
192 TownDrawHouseLift |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
193 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
194 |
8791
2693434c1f4c
(svn r12513) -Codechange: rename OriginalTileRandomiser something more descriptive
skidd13 <skidd13@openttd.org>
parents:
8787
diff
changeset
|
195 /** |
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
|
196 * 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
|
197 * |
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
|
198 * @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
|
199 */ |
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
|
200 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
|
201 { |
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
|
202 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
|
203 } |
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
|
204 |
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
|
205 /** |
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
|
206 * 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
|
207 * 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
|
208 * @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
|
209 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
210 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
|
211 { |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
212 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
|
213 |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
214 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
|
215 /* 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
|
216 * 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
|
217 * house id is drawn instead. */ |
16341
d177aab74b30
(svn r21052) -Fix (r20435): house/airporttile/industrytile newgrfs that defined tiles that relied on the substitute being drawn were broken
yexo <yexo@openttd.org>
parents:
16164
diff
changeset
|
218 if (HouseSpec::Get(house_id)->grf_prop.spritegroup[0] != NULL) { |
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
|
219 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
|
220 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
|
221 } else { |
15734
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
222 house_id = HouseSpec::Get(house_id)->grf_prop.subst_id; |
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
|
223 } |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
224 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
225 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
226 /* 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
|
227 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
|
228 |
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
|
229 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
|
230 |
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
|
231 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
|
232 |
8806
104bbcae351d
(svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz <smatz@openttd.org>
parents:
8796
diff
changeset
|
233 /* 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
|
234 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
|
235 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
236 /* 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
|
237 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
|
238 if (image != 0) { |
7333
7110c41ab174
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents:
7226
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 dcts->width, |
a9acd5d86f94
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium <rubidium@openttd.org>
parents:
7566
diff
changeset
|
243 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
|
244 dcts->dz, |
7333
7110c41ab174
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents:
7226
diff
changeset
|
245 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
|
246 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
|
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 |
7849
e6ee8bfd9045
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas <belugas@openttd.org>
parents:
7847
diff
changeset
|
249 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
|
250 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
251 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
252 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
253 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
|
254 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
255 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
|
256 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
257 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
258 |
18271
f63c96a8cfb5
(svn r23107) -Codechange: let GetSlopePixelZ and TerraformTile tile type functions use int z as well
rubidium <rubidium@openttd.org>
parents:
18270
diff
changeset
|
259 static int GetSlopePixelZ_Town(TileIndex tile, uint x, uint y) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 { |
18255
b3cb40aab91b
(svn r23091) -Codechange: rename some Get*Z functions to Get*PixelZ functions if they return the Z in pixels (like TilePixelHeight)
rubidium <rubidium@openttd.org>
parents:
18246
diff
changeset
|
261 return GetTileMaxPixelZ(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
|
262 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
263 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
264 /** 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
|
265 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
|
266 { |
13060
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
267 HouseID hid = GetHouseType(tile); |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
268 |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
269 /* For NewGRF house tiles we might not be drawing a foundation. We need to |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
270 * account for this, as other structures should |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
271 * draw the wall of the foundation in this case. |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
272 */ |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
273 if (hid >= NEW_HOUSE_OFFSET) { |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
274 const HouseSpec *hs = HouseSpec::Get(hid); |
16341
d177aab74b30
(svn r21052) -Fix (r20435): house/airporttile/industrytile newgrfs that defined tiles that relied on the substitute being drawn were broken
yexo <yexo@openttd.org>
parents:
16164
diff
changeset
|
275 if (hs->grf_prop.spritegroup[0] != NULL && HasBit(hs->callback_mask, CBM_HOUSE_DRAW_FOUNDATIONS)) { |
13060
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
276 uint32 callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, hid, Town::GetByTile(tile), tile); |
18311
09cb5ec03259
(svn r23147) -Change: [NewGRF v8] Unify the return values of boolean callbacks, and check the results for validity.
frosch <frosch@openttd.org>
parents:
18306
diff
changeset
|
277 if (callback_res != CALLBACK_FAILED && !ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DRAW_FOUNDATIONS, callback_res)) return FOUNDATION_NONE; |
13060
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
278 } |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
279 } |
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
|
280 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
|
281 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
282 |
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
|
283 /** |
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
|
284 * 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
|
285 * 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
|
286 * 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
|
287 * @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
|
288 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
289 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
|
290 { |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
291 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
|
292 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
|
293 return; |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
294 } |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
295 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
296 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
|
297 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
298 /* 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
|
299 * 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
|
300 * 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
|
301 * That bug seems to have been here since day 1?? */ |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
302 if (!(HouseSpec::Get(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
|
303 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
|
304 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
305 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
306 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
307 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
|
308 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
|
309 |
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
|
310 /* 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
|
311 * 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
|
312 * 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
|
313 * 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
|
314 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
|
315 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
|
316 } 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
|
317 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
318 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
|
319 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
320 |
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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 |
9006
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
326 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
|
327 HaltLift(tile); |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
328 DeleteAnimatedTile(tile); |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
329 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
330 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
331 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
|
332 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
333 |
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
|
334 /** |
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 * 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
|
336 * @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
|
337 * @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
|
338 * @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
|
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 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
|
341 { |
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
|
342 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
|
343 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
344 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
|
345 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
|
346 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
347 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
|
348 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
349 |
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
|
350 /** |
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 * 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
|
352 * 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
|
353 */ |
12391
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
354 void Town::UpdateVirtCoord() |
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 { |
12391
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
356 Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE); |
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
357 SetDParam(0, this->index); |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
358 SetDParam(1, this->cache.population); |
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
359 this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_LVL_BASE, |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12540
diff
changeset
|
360 _settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN); |
12787
156c10435e35
(svn r17268) -Fix [FS#3143]: Station/Town window titles weren't updated when they got renamed
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
361 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12999
diff
changeset
|
362 SetWindowDirty(WC_TOWN_VIEW, 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
|
363 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
364 |
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
|
365 /** 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
|
366 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
|
367 { |
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
|
368 Town *t; |
12391
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
369 |
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
|
370 FOR_ALL_TOWNS(t) { |
12391
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
371 t->UpdateVirtCoord(); |
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
|
372 } |
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
|
373 } |
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
|
374 |
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
|
375 /** |
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
|
376 * 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
|
377 * @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
|
378 * @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
|
379 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
380 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
|
381 { |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
382 t->cache.population += mod; |
19099
92bc2ad02277
(svn r23953) -Fix [FS#5062]: When the population of a town changes the town view might even have to change size due to different cargo requirements.
frosch <frosch@openttd.org>
parents:
18964
diff
changeset
|
383 InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations |
12391
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
384 t->UpdateVirtCoord(); |
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 |
9387
a240dd49a2e8
(svn r13297) -Codechange: Use GUIList for the town directory window
peter1138 <peter1138@openttd.org>
parents:
9358
diff
changeset
|
386 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
|
387 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
388 |
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
|
389 /** |
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
|
390 * 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
|
391 * 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
|
392 * @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
|
393 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
394 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
|
395 { |
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
|
396 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
|
397 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
|
398 |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
399 FOR_ALL_TOWNS(t) pop += t->cache.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
|
400 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
|
401 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
402 |
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
|
403 /** |
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
|
404 * 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
|
405 * @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
|
406 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
407 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
|
408 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
409 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
|
410 |
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
|
411 /* 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
|
412 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
|
413 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
|
414 |
15939
d818797c4bd0
(svn r20627) -Codechange: unify the animation code of station, airport, house and industry tiles
rubidium <rubidium@openttd.org>
parents:
15858
diff
changeset
|
415 AnimateNewHouseConstruction(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 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
|
418 /* 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
|
419 * building to the town. */ |
15939
d818797c4bd0
(svn r20627) -Codechange: unify the animation code of station, airport, house and industry tiles
rubidium <rubidium@openttd.org>
parents:
15858
diff
changeset
|
420 ChangePopulation(Town::GetByTile(tile), HouseSpec::Get(GetHouseType(tile))->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
|
421 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
|
422 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 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
|
424 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
425 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
426 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
427 * 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
|
428 * @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
|
429 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
430 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
|
431 { |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
432 uint flags = HouseSpec::Get(GetHouseType(tile))->building_flags; |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
433 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
|
434 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
|
435 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
|
436 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
|
437 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
438 |
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
|
439 /** |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
440 * Tile callback function. |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
441 * |
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
|
442 * 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
|
443 * @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
|
444 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
445 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
|
446 { |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
447 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
|
448 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
449 /* 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
|
450 * 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
|
451 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
|
452 |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
453 if (!IsHouseCompleted(tile)) { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
454 /* 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
|
455 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
|
456 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
457 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
458 |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
459 const HouseSpec *hs = HouseSpec::Get(house_id); |
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
|
460 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
461 /* 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
|
462 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
|
463 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
|
464 !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
|
465 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
|
466 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
|
467 } |
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
|
468 |
12250
b2b9e7cd3be5
(svn r16665) -Codechange: replace GetTownByTile() by Town::GetByTile()
smatz <smatz@openttd.org>
parents:
12249
diff
changeset
|
469 Town *t = Town::GetByTile(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
|
470 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
|
471 |
14167
cecdc0326a09
(svn r18715) -Codechange: make StationFinder a subclass of TileArea
rubidium <rubidium@openttd.org>
parents:
14025
diff
changeset
|
472 StationFinder stations(TileArea(tile, 1, 1)); |
13586
6093f71745bf
(svn r18110) -Codechange [FS#3316]: search for stations nearby only once per producer (instead of once pre produced cargo type) (fonsinchen)
smatz <smatz@openttd.org>
parents:
13508
diff
changeset
|
473 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7903
diff
changeset
|
474 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
|
475 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
|
476 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
|
477 |
8287
988d9721ef31
(svn r11851) -Codechange: A few magic numbers removal, plus a little code style
belugas <belugas@openttd.org>
parents:
8268
diff
changeset
|
478 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
|
479 |
15734
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
480 CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grf_prop.grffile); |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
481 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
|
482 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
483 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
|
484 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
|
485 |
13586
6093f71745bf
(svn r18110) -Codechange [FS#3316]: search for stations nearby only once per producer (instead of once pre produced cargo type) (fonsinchen)
smatz <smatz@openttd.org>
parents:
13508
diff
changeset
|
486 uint moved = MoveGoodsToStation(cargo, amt, ST_TOWN, t->index, stations.GetStations()); |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
487 |
12415
6a77d1df56e2
(svn r16849) -Codechange: replace GetCargo() by CargoSpec::Get()
smatz <smatz@openttd.org>
parents:
12407
diff
changeset
|
488 const CargoSpec *cs = CargoSpec::Get(cargo); |
18454
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
489 t->supplied[cs->Index()].new_max += amt; |
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
490 t->supplied[cs->Index()].new_act += moved; |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
491 } |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
492 } else { |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
493 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
|
494 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
|
495 |
16440
c776a99ce938
(svn r21156) -Codechange: Introduce EconomyIsInRecession().
alberth <alberth@openttd.org>
parents:
16341
diff
changeset
|
496 if (EconomyIsInRecession()) amt = (amt + 1) >> 1; |
18454
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
497 t->supplied[CT_PASSENGERS].new_max += amt; |
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
498 t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, ST_TOWN, t->index, stations.GetStations()); |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
499 } |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
500 |
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
501 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
|
502 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
|
503 |
16440
c776a99ce938
(svn r21156) -Codechange: Introduce EconomyIsInRecession().
alberth <alberth@openttd.org>
parents:
16341
diff
changeset
|
504 if (EconomyIsInRecession()) amt = (amt + 1) >> 1; |
18454
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
505 t->supplied[CT_MAIL].new_max += amt; |
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
506 t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, ST_TOWN, t->index, stations.GetStations()); |
6645
75841d480476
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents:
6642
diff
changeset
|
507 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
508 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
509 |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
510 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE); |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
511 |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12010
diff
changeset
|
512 if ((hs->building_flags & BUILDING_HAS_1_TILE) && |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
513 HasBit(t->flags, 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
|
514 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
|
515 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
|
516 --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
|
517 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
|
518 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
519 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
|
520 |
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
|
521 /* 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
|
522 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
|
523 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15115
diff
changeset
|
525 cur_company.Restore(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
526 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
527 |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
528 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
|
529 { |
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
|
530 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
|
531 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
|
532 |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
533 const HouseSpec *hs = HouseSpec::Get(GetHouseType(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
|
534 |
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
|
535 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
|
536 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
|
537 |
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
|
538 int rating = hs->remove_rating_decrease; |
16164
5677428dfc6d
(svn r20860) -Cleanup: remove some unused functions and variables
smatz <smatz@openttd.org>
parents:
16109
diff
changeset
|
539 Town *t = Town::GetByTile(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
|
540 |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
541 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
|
542 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
|
543 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
|
544 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
|
545 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
546 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
547 |
11106
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
552 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
553 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
|
554 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
555 |
12263
2af84c928595
(svn r16678) -Codechange: Turn CargoArray into a class, so one does not have to deal with sizeof() wrt. typedef-ed arrays.
frosch <frosch@openttd.org>
parents:
12261
diff
changeset
|
556 static void AddProducedCargo_Town(TileIndex tile, CargoArray &produced) |
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
|
557 { |
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 HouseID house_id = GetHouseType(tile); |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
559 const HouseSpec *hs = HouseSpec::Get(house_id); |
12250
b2b9e7cd3be5
(svn r16665) -Codechange: replace GetTownByTile() by Town::GetByTile()
smatz <smatz@openttd.org>
parents:
12249
diff
changeset
|
560 Town *t = Town::GetByTile(tile); |
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
|
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 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
|
563 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
|
564 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
|
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 (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
|
567 |
15734
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
568 CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grf_prop.grffile); |
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
|
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 if (cargo == CT_INVALID) continue; |
12261
c42d8d239142
(svn r16676) -Codechange: Rename AcceptedCargo to CargoArray and its instances to more meaningful names.
frosch <frosch@openttd.org>
parents:
12258
diff
changeset
|
571 produced[cargo]++; |
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
|
572 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
573 } 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
|
574 if (hs->population > 0) { |
12261
c42d8d239142
(svn r16676) -Codechange: Rename AcceptedCargo to CargoArray and its instances to more meaningful names.
frosch <frosch@openttd.org>
parents:
12258
diff
changeset
|
575 produced[CT_PASSENGERS]++; |
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
|
576 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
577 if (hs->mail_generation > 0) { |
12261
c42d8d239142
(svn r16676) -Codechange: Rename AcceptedCargo to CargoArray and its instances to more meaningful names.
frosch <frosch@openttd.org>
parents:
12258
diff
changeset
|
578 produced[CT_MAIL]++; |
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
|
579 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
580 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
581 } |
838e1d6a0321
(svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium <rubidium@openttd.org>
parents:
8818
diff
changeset
|
582 |
13089
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13082
diff
changeset
|
583 static inline void AddAcceptedCargoSetMask(CargoID cargo, uint amount, CargoArray &acceptance, uint32 *always_accepted) |
12946
560c26f15688
(svn r17439) -Fix (r17436): you weren't paid for cargo delivered to houses and headquarters anymore
smatz <smatz@openttd.org>
parents:
12787
diff
changeset
|
584 { |
560c26f15688
(svn r17439) -Fix (r17436): you weren't paid for cargo delivered to houses and headquarters anymore
smatz <smatz@openttd.org>
parents:
12787
diff
changeset
|
585 if (cargo == CT_INVALID || amount == 0) return; |
560c26f15688
(svn r17439) -Fix (r17436): you weren't paid for cargo delivered to houses and headquarters anymore
smatz <smatz@openttd.org>
parents:
12787
diff
changeset
|
586 acceptance[cargo] += amount; |
13089
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13082
diff
changeset
|
587 SetBit(*always_accepted, cargo); |
12946
560c26f15688
(svn r17439) -Fix (r17436): you weren't paid for cargo delivered to houses and headquarters anymore
smatz <smatz@openttd.org>
parents:
12787
diff
changeset
|
588 } |
560c26f15688
(svn r17439) -Fix (r17436): you weren't paid for cargo delivered to houses and headquarters anymore
smatz <smatz@openttd.org>
parents:
12787
diff
changeset
|
589 |
13089
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13082
diff
changeset
|
590 static void AddAcceptedCargo_Town(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
591 { |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
592 const HouseSpec *hs = HouseSpec::Get(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
|
593 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
|
594 |
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
|
595 /* 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
|
596 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
|
597 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
|
598 } |
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
|
599 |
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 /* 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
|
601 if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) { |
12250
b2b9e7cd3be5
(svn r16665) -Codechange: replace GetTownByTile() by Town::GetByTile()
smatz <smatz@openttd.org>
parents:
12249
diff
changeset
|
602 uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), Town::GetByTile(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
|
603 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
|
604 /* Replace accepted cargo types with translated values from callback */ |
15734
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
605 accepts[0] = GetCargoTranslation(GB(callback, 0, 5), hs->grf_prop.grffile); |
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
606 accepts[1] = GetCargoTranslation(GB(callback, 5, 5), hs->grf_prop.grffile); |
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
607 accepts[2] = GetCargoTranslation(GB(callback, 10, 5), hs->grf_prop.grffile); |
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
|
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 } |
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 |
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 /* 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
|
612 if (HasBit(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) { |
12250
b2b9e7cd3be5
(svn r16665) -Codechange: replace GetTownByTile() by Town::GetByTile()
smatz <smatz@openttd.org>
parents:
12249
diff
changeset
|
613 uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), Town::GetByTile(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
|
614 if (callback != CALLBACK_FAILED) { |
13089
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13082
diff
changeset
|
615 AddAcceptedCargoSetMask(accepts[0], GB(callback, 0, 4), acceptance, always_accepted); |
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13082
diff
changeset
|
616 AddAcceptedCargoSetMask(accepts[1], GB(callback, 4, 4), acceptance, always_accepted); |
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
|
617 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
|
618 /* The 'S' bit indicates food instead of goods */ |
13089
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13082
diff
changeset
|
619 AddAcceptedCargoSetMask(CT_FOOD, GB(callback, 8, 4), acceptance, always_accepted); |
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
|
620 } else { |
13089
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13082
diff
changeset
|
621 AddAcceptedCargoSetMask(accepts[2], GB(callback, 8, 4), acceptance, always_accepted); |
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
|
622 } |
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
|
623 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
|
624 } |
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
|
625 } |
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
|
626 |
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
|
627 /* 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
|
628 for (uint8 i = 0; i < lengthof(accepts); i++) { |
13089
559dafab3ecb
(svn r17589) -Codechange: rename town_acc to always_accepted
smatz <smatz@openttd.org>
parents:
13082
diff
changeset
|
629 AddAcceptedCargoSetMask(accepts[i], hs->cargo_acceptance[i], acceptance, always_accepted); |
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
|
630 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
631 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
632 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
633 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
|
634 { |
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
|
635 const HouseID house = GetHouseType(tile); |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
636 const HouseSpec *hs = HouseSpec::Get(house); |
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
|
637 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
|
638 |
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 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
|
640 |
12250
b2b9e7cd3be5
(svn r16665) -Codechange: replace GetTownByTile() by Town::GetByTile()
smatz <smatz@openttd.org>
parents:
12249
diff
changeset
|
641 uint16 callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, Town::GetByTile(tile), tile); |
18306
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18272
diff
changeset
|
642 if (callback_res != CALLBACK_FAILED && callback_res != 0x400) { |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18272
diff
changeset
|
643 if (callback_res > 0x400) { |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18272
diff
changeset
|
644 ErrorUnknownCallbackResult(hs->grf_prop.grffile->grfid, CBID_HOUSE_CUSTOM_NAME, callback_res); |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18272
diff
changeset
|
645 } else { |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18272
diff
changeset
|
646 StringID new_name = GetGRFStringID(hs->grf_prop.grffile->grfid, 0xD000 + callback_res); |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18272
diff
changeset
|
647 if (new_name != STR_NULL && new_name != STR_UNDEFINED) { |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18272
diff
changeset
|
648 td->str = new_name; |
21d2cc91c3ce
(svn r23142) -Change: [NewGRF v8] Unify the return values of callbacks returning D0xx texts.
frosch <frosch@openttd.org>
parents:
18272
diff
changeset
|
649 } |
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
|
650 } |
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
|
651 } |
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
|
652 |
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
|
653 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
|
654 SetDParamX(td->dparam, 0, td->str); |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12540
diff
changeset
|
655 td->str = STR_LAI_TOWN_INDUSTRY_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
|
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 |
15734
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
658 if (hs->grf_prop.grffile != NULL) { |
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
659 const GRFConfig *gc = GetGRFConfig(hs->grf_prop.grffile->grfid); |
14711
74b0a8a64ff5
(svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
yexo <yexo@openttd.org>
parents:
14696
diff
changeset
|
660 td->grf = gc->GetName(); |
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
|
661 } |
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
|
662 |
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
|
663 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
|
664 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
665 |
8616
9e46ac001a8c
(svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch <frosch@openttd.org>
parents:
8596
diff
changeset
|
666 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
|
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 /* 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
|
669 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
|
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 |
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
|
672 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
|
673 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
674 /* 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
|
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 |
18560
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
677 /** Update the total cargo acceptance of the whole town. |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
678 * @param t The town to update. |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
679 */ |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
680 void UpdateTownCargoTotal(Town *t) |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
681 { |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
682 t->cargo_accepted_total = 0; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
683 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
684 const TileArea &area = t->cargo_accepted.GetArea(); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
685 TILE_AREA_LOOP(tile, area) { |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
686 if (TileX(tile) % AcceptanceMatrix::GRID == 0 && TileY(tile) % AcceptanceMatrix::GRID == 0) { |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
687 t->cargo_accepted_total |= t->cargo_accepted[tile]; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
688 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
689 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
690 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
691 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
692 /** |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
693 * Update accepted town cargoes around a specific tile. |
18560
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
694 * @param t The town to update. |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
695 * @param start Update the values around this tile. |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
696 * @param update_total Set to true if the total cargo acceptance should be updated. |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
697 */ |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
698 static void UpdateTownCargoes(Town *t, TileIndex start, bool update_total = true) |
18560
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
699 { |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
700 CargoArray accepted, produced; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
701 uint32 dummy; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
702 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
703 /* Gather acceptance for all houses in an area around the start tile. |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
704 * The area is composed of the square the tile is in, extended one square in all |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
705 * directions as the coverage area of a single station is bigger than just one square. */ |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
706 TileArea area = AcceptanceMatrix::GetAreaForTile(start, 1); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
707 TILE_AREA_LOOP(tile, area) { |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
708 if (!IsTileType(tile, MP_HOUSE) || GetTownIndex(tile) != t->index) continue; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
709 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
710 AddAcceptedCargo_Town(tile, accepted, &dummy); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
711 AddProducedCargo_Town(tile, produced); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
712 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
713 |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
714 /* Create bitmap of produced and accepted cargoes. */ |
18560
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
715 uint32 acc = 0; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
716 for (uint cid = 0; cid < NUM_CARGO; cid++) { |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
717 if (accepted[cid] >= 8) SetBit(acc, cid); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
718 if (produced[cid] > 0) SetBit(t->cargo_produced, cid); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
719 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
720 t->cargo_accepted[start] = acc; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
721 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
722 if (update_total) UpdateTownCargoTotal(t); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
723 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
724 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
725 /** Update cargo acceptance for the complete town. |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
726 * @param t The town to update. |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
727 */ |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
728 void UpdateTownCargoes(Town *t) |
18560
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
729 { |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
730 t->cargo_produced = 0; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
731 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
732 const TileArea &area = t->cargo_accepted.GetArea(); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
733 if (area.tile == INVALID_TILE) return; |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
734 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
735 /* Update acceptance for each grid square. */ |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
736 TILE_AREA_LOOP(tile, area) { |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
737 if (TileX(tile) % AcceptanceMatrix::GRID == 0 && TileY(tile) % AcceptanceMatrix::GRID == 0) { |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
738 UpdateTownCargoes(t, tile, false); |
18560
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
739 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
740 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
741 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
742 /* Update the total acceptance. */ |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
743 UpdateTownCargoTotal(t); |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
744 } |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
745 |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
746 /** Updates the bitmap of all cargoes accepted by houses. */ |
18562
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
747 void UpdateTownCargoBitmap() |
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
748 { |
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
749 Town *town; |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
750 _town_cargoes_accepted = 0; |
18562
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
751 |
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
752 FOR_ALL_TOWNS(town) { |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
753 _town_cargoes_accepted |= town->cargo_accepted_total; |
18562
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
754 } |
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
755 } |
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
756 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
757 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
|
758 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
759 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
|
760 { |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
761 if (HasBit(t->flags, 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
|
762 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
|
763 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
|
764 if (GrowTown(t)) { |
18772
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
765 i = t->growth_rate & (~TOWN_GROW_RATE_CUSTOM); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
766 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
767 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
|
768 } |
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 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
|
771 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
772 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
773 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
|
774 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
775 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
776 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
|
777 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
778 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
|
779 |
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
|
780 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
|
781 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
|
782 /* Run town tick at regular intervals, but not all at once. */ |
17702
bcd20b97e0ee
(svn r22482) -Codechange: Add some contants for the number of ticks between certain cyclical tasks.
frosch <frosch@openttd.org>
parents:
17684
diff
changeset
|
783 if ((_tick_counter + t->index) % TOWN_GROWTH_TICKS == 0) { |
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
|
784 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
|
785 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
786 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
787 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
788 |
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 /** |
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
|
790 * 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
|
791 * |
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
|
792 * @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
|
793 * @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
|
794 * @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
|
795 * @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
|
796 */ |
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
|
797 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
|
798 { |
12370
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
799 if (IsRoadDepotTile(tile) || IsStandardRoadStopTile(tile)) return ROAD_NONE; |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
800 |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
801 return GetAnyRoadBits(tile, ROADTYPE_ROAD, 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
|
802 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
803 |
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
|
804 /** |
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
|
805 * 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
|
806 * 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
|
807 * 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
|
808 * |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
809 * @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
|
810 * @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
|
811 * @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
|
812 * @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
|
813 */ |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
814 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
|
815 { |
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
|
816 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
|
817 |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
818 /* 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 }; |
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
|
824 |
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
|
825 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
|
826 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
|
827 /* 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
|
828 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
|
829 |
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
|
830 /* 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
|
831 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
|
832 |
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
|
833 /* 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
|
834 if (IsValidTile(tile + cur) && |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
835 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
|
836 } |
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
|
837 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
|
838 } |
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 |
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
|
840 /** |
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
|
841 * 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
|
842 * |
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
|
843 * @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
|
844 * @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
|
845 * @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
|
846 * @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
|
847 */ |
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
|
848 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
|
849 { |
12370
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
850 if (DistanceFromEdge(tile) == 0) 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
|
851 |
17902
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
852 /* Check if there already is a road at this point? */ |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
853 if (GetTownRoadBits(tile) == ROAD_NONE) { |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
854 /* No, try if we are able to build a road piece there. |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
855 * If that fails clear the land, and if that fails exit. |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
856 * This is to make sure that we can build a road here later. */ |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
857 if (DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X), 0, DC_AUTO, CMD_BUILD_ROAD).Failed() && |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
858 DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR).Failed()) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
859 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
|
860 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
861 } |
17902
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
862 |
18258
c27aabdb6433
(svn r23094) -Codechange: add a default NULL to GetFoundationSlope and use it
rubidium <rubidium@openttd.org>
parents:
18257
diff
changeset
|
863 Slope cur_slope = _settings_game.construction.build_on_slopes ? GetFoundationSlope(tile) : GetTileSlope(tile); |
17902
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
864 bool ret = !IsNeighborRoadTile(tile, dir, t->layout == TL_ORIGINAL ? 1 : 2); |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
865 if (cur_slope == SLOPE_FLAT) return ret; |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
866 |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
867 /* If the tile is not a slope in the right direction, then |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
868 * maybe terraform some. */ |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
869 Slope desired_slope = (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? SLOPE_NW : SLOPE_NE; |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
870 if (desired_slope != cur_slope && ComplementSlope(desired_slope) != cur_slope) { |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
871 if (Chance16(1, 8)) { |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
872 CommandCost res = CMD_ERROR; |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
873 if (!_generating_world && Chance16(1, 10)) { |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
874 /* Note: Do not replace "^ SLOPE_ELEVATED" with ComplementSlope(). The slope might be steep. */ |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
875 res = DoCommand(tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0, |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
876 DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
877 } |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
878 if (res.Failed() && Chance16(1, 3)) { |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
879 /* We can consider building on the slope, though. */ |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
880 return ret; |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
881 } |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
882 } |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
883 return false; |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
884 } |
ec936cb32175
(svn r22706) -Cleanup: A loop is no loop, if it never iterates.
frosch <frosch@openttd.org>
parents:
17898
diff
changeset
|
885 return ret; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
886 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
887 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
888 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
|
889 { |
11231
1b7daea82ad7
(svn r15585) -Codechange: Remove TILE_ASSERT and replace all instances with assert(tile < MapSize()).
yexo <yexo@openttd.org>
parents:
11230
diff
changeset
|
890 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
|
891 |
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
|
892 CommandCost r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
893 if (r.Failed() || r.GetCost() >= (_price[PR_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
|
894 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
|
895 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
|
896 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
897 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
898 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
|
899 { |
11231
1b7daea82ad7
(svn r15585) -Codechange: Remove TILE_ASSERT and replace all instances with assert(tile < MapSize()).
yexo <yexo@openttd.org>
parents:
11230
diff
changeset
|
900 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
|
901 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
902 /* 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
|
903 if (IsTileType(tile, MP_HOUSE)) return; |
18257
b6026cba5dae
(svn r23093) -Codechange: add a default NULL for the Z of GetTileSlope and use it
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
904 Slope tileh = GetTileSlope(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
|
905 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
|
906 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
907 /* 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
|
908 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
|
909 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
|
910 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
911 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
912 |
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
|
913 /** |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
914 * 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
|
915 * |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
916 * @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
|
917 * @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
|
918 * @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
|
919 * @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
|
920 * 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
|
921 */ |
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
|
922 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
|
923 { |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
924 /* 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
|
925 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
|
926 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
|
927 |
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
|
928 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
|
929 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
|
930 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
931 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
|
932 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
|
933 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
|
934 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
|
935 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
936 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
|
937 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
|
938 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
|
939 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
|
940 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
941 |
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
|
942 /* 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
|
943 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
|
944 |
f0585ed32dd3
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7762
diff
changeset
|
945 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
|
946 |
18257
b6026cba5dae
(svn r23093) -Codechange: add a default NULL for the Z of GetTileSlope and use it
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
947 switch (GetTileSlope(tile)) { |
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
|
948 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
|
949 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
|
950 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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 } |
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
|
964 |
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
|
965 /* 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
|
966 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
|
967 /* 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
|
968 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
|
969 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
970 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
971 /** |
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 * 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
|
973 * 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
|
974 * 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
|
975 * 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
|
976 * |
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
|
977 * @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
|
978 * @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
|
979 * @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
|
980 */ |
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
|
981 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
|
982 { |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
983 /* We can't look further than that. */ |
12370
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
984 if (DistanceFromEdge(tile) == 0) 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
|
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 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
|
987 |
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
|
988 /* 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
|
989 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { |
12370
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
990 /* Count both void and house tiles for checking whether there |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
991 * are enough houses in the area. This to make it likely that |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
992 * houses get build up to the edge of the map. */ |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
993 switch (GetTileType(TileAddByDiagDir(tile, dir))) { |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
994 case MP_HOUSE: |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
995 case MP_VOID: |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
996 counter++; |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
997 break; |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
998 |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
999 default: |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
1000 break; |
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
1001 } |
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
|
1002 |
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 /* 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
|
1004 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
|
1005 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
|
1006 _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
|
1007 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
|
1008 } |
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
|
1009 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
|
1010 } |
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
|
1011 } |
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
|
1012 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
|
1013 } |
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 |
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
|
1015 /** |
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 * 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
|
1017 * |
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
|
1018 * @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
|
1019 * @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
|
1020 * @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
|
1021 * @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
|
1022 */ |
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
|
1023 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
|
1024 { |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1025 if (DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Succeeded()) { |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
1026 _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
|
1027 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
|
1028 } |
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
|
1029 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
|
1030 } |
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
|
1031 |
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
|
1032 /** |
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
|
1033 * 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
|
1034 * 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
|
1035 * 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
|
1036 * |
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
|
1037 * @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
|
1038 * @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
|
1039 * @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
|
1040 * @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
|
1041 */ |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
1042 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
|
1043 { |
7845
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
1044 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
|
1045 |
18257
b6026cba5dae
(svn r23093) -Codechange: add a default NULL for the Z of GetTileSlope and use it
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
1046 const Slope slope = GetTileSlope(tile); |
7845
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
1047 |
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
1048 /* 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
|
1049 * 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
|
1050 * reverse direction. */ |
18078
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1051 if (slope != SLOPE_FLAT && 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
|
1052 |
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
|
1053 /* 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
|
1054 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
|
1055 |
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
|
1056 /* 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
|
1057 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
|
1058 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
|
1059 |
8451
af88cc5ebb4b
(svn r12021) -Cleanup: Make some parts of the town growth a bit more descriptive
skidd13 <skidd13@openttd.org>
parents:
8359
diff
changeset
|
1060 const int delta = TileOffsByDiagDir(bridge_dir); |
18078
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1061 |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1062 if (slope == SLOPE_FLAT) { |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1063 /* Bridges starting on flat tiles are only allowed when crossing rivers. */ |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1064 do { |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1065 if (bridge_length++ >= 4) { |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1066 /* Allow to cross rivers, not big lakes. */ |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1067 return false; |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1068 } |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1069 bridge_tile += delta; |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1070 } while (IsValidTile(bridge_tile) && IsWaterTile(bridge_tile) && !IsSea(bridge_tile)); |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1071 } else { |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1072 do { |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1073 if (bridge_length++ >= 11) { |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1074 /* Max 11 tile long bridges */ |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1075 return false; |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1076 } |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1077 bridge_tile += delta; |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1078 } while (IsValidTile(bridge_tile) && IsWaterTile(bridge_tile)); |
3f5752deb867
(svn r22899) -Add: Allow towns to build bridges over canals and rivers.
terkhen <terkhen@openttd.org>
parents:
18001
diff
changeset
|
1079 } |
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
|
1080 |
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
|
1081 /* 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
|
1082 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
|
1083 |
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
|
1084 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
|
1085 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
|
1086 |
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
|
1087 /* Can we actually build the bridge? */ |
16109
5e95ab62c484
(svn r20802) -Fix: Building bridges on water/watery objects behaved inconsistently for towns and the bridge selection GUI.
frosch <frosch@openttd.org>
parents:
16098
diff
changeset
|
1088 if (DoCommand(tile, bridge_tile, bridge_type | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE).Succeeded()) { |
5e95ab62c484
(svn r20802) -Fix: Building bridges on water/watery objects behaved inconsistently for towns and the bridge selection GUI.
frosch <frosch@openttd.org>
parents:
16098
diff
changeset
|
1089 DoCommand(tile, bridge_tile, bridge_type | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), 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
|
1090 _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
|
1091 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
|
1092 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1093 } |
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
|
1094 /* 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
|
1095 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
|
1096 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1097 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1098 /** |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1099 * 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
|
1100 * 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
|
1101 * 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
|
1102 * @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
|
1103 * @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
|
1104 * @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
|
1105 * @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
|
1106 * @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
|
1107 * @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
|
1108 * @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
|
1109 * |
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 * @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
|
1111 * @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
|
1112 * @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
|
1113 * @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
|
1114 */ |
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
|
1115 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
|
1116 { |
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
|
1117 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
|
1118 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
|
1119 |
11231
1b7daea82ad7
(svn r15585) -Codechange: Remove TILE_ASSERT and replace all instances with assert(tile < MapSize()).
yexo <yexo@openttd.org>
parents:
11230
diff
changeset
|
1120 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
|
1121 |
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
|
1122 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
|
1123 /* 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
|
1124 * 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
|
1125 _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
|
1126 |
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
|
1127 if (!_settings_game.economy.allow_town_roads && !_generating_world) return; |
15405
fa04125ca60d
(svn r20048) -Feature: Add a setting to forbid towns building level crossings.
michi_cc <michi_cc@openttd.org>
parents:
15404
diff
changeset
|
1128 if (!_settings_game.economy.allow_town_level_crossings && IsTileType(tile, MP_RAILWAY)) return; |
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
|
1129 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1130 /* 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
|
1131 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
|
1132 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1133 /* 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
|
1134 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
|
1135 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
|
1136 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1137 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
|
1138 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
|
1139 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
|
1140 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
|
1141 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
|
1142 |
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 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
|
1144 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
|
1145 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
|
1146 |
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
|
1147 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
|
1148 |
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
|
1149 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
|
1150 /* 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
|
1151 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
|
1152 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1153 |
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
|
1154 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
|
1155 /* 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
|
1156 * 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
|
1157 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
|
1158 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1159 /* 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
|
1160 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
|
1161 !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
|
1162 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
|
1163 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1164 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1165 /* 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
|
1166 * 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
|
1167 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1168 |
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
|
1169 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
|
1170 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
|
1171 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1172 |
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
|
1173 } 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
|
1174 /* 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
|
1175 * 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
|
1176 * 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
|
1177 _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
|
1178 |
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
|
1179 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
|
1180 |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1181 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
|
1182 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
|
1183 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1184 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
|
1185 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
|
1186 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
|
1187 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
|
1188 |
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 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
|
1190 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
|
1191 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
|
1192 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
|
1193 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1194 } 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
|
1195 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
|
1196 |
18001
6e430c0b722b
(svn r22810) -Fix: Growth a town on both ends of a tunnel/bridge if the town centre tile is a bridge ramp/tunnel portal.
michi_cc <michi_cc@openttd.org>
parents:
18000
diff
changeset
|
1197 /* Reached a tunnel/bridge? Then continue at the other side of it, unless |
6e430c0b722b
(svn r22810) -Fix: Growth a town on both ends of a tunnel/bridge if the town centre tile is a bridge ramp/tunnel portal.
michi_cc <michi_cc@openttd.org>
parents:
18000
diff
changeset
|
1198 * it is the starting tile. Half the time, we stay on this side then.*/ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1199 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
18001
6e430c0b722b
(svn r22810) -Fix: Growth a town on both ends of a tunnel/bridge if the town centre tile is a bridge ramp/tunnel portal.
michi_cc <michi_cc@openttd.org>
parents:
18000
diff
changeset
|
1200 if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD && (target_dir != DIAGDIR_END || Chance16(1, 2))) { |
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
|
1201 *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
|
1202 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1203 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1204 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1205 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1206 /* 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
|
1207 * 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
|
1208 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
|
1209 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
|
1210 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1211 /* 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
|
1212 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
|
1213 |
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
|
1214 /* Don't walk into water. */ |
16563
8e0848deda46
(svn r21291) -Fix: Treat objects on water like water in more cases.
frosch <frosch@openttd.org>
parents:
16467
diff
changeset
|
1215 if (HasTileWaterGround(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
|
1216 |
12370
ac52bf3742f4
(svn r16795) -Fix [FS#3025]: houses wouldn't get build on the map edge.
rubidium <rubidium@openttd.org>
parents:
12344
diff
changeset
|
1217 if (!IsValidTile(house_tile)) return; |
10855
7881d9cd55ab
(svn r15190) -Feature: Allow terraforming of the tiles at the edges of the map.
Yexo <Yexo@openttd.org>
parents:
10837
diff
changeset
|
1218 |
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
|
1219 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
|
1220 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
|
1221 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
|
1222 |
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
|
1223 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
|
1224 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
|
1225 /* 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
|
1226 |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1227 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
|
1228 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
|
1229 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
|
1230 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
|
1231 |
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
|
1232 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
|
1233 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
|
1234 /* 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
|
1235 |
def5dbb7e314
(svn r15340) -Fix [FS#2121]: changing town road layout in-game caused ugly road networks
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1236 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
|
1237 /* 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
|
1238 * 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
|
1239 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
|
1240 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
|
1241 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
|
1242 } |
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
|
1243 } |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1244 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1245 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
|
1246 /* 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
|
1247 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
|
1248 /* 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
|
1249 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
|
1250 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1251 /* And build a house. |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1252 * 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
|
1253 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
|
1254 _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
|
1255 } |
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 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1258 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1259 |
7684
ea99aeb26c95
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents:
7666
diff
changeset
|
1260 _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
|
1261 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1262 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1263 /* Return if a water tile */ |
16563
8e0848deda46
(svn r21291) -Fix: Treat objects on water like water in more cases.
frosch <frosch@openttd.org>
parents:
16467
diff
changeset
|
1264 if (HasTileWaterGround(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
|
1265 |
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
|
1266 /* 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
|
1267 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
|
1268 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
|
1269 |
7845
469ee079ee16
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents:
7766
diff
changeset
|
1270 /* 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
|
1271 * 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
|
1272 * 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
|
1273 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
|
1274 |
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
|
1275 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
|
1276 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1277 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1278 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1279 * Returns "growth" if a house was built, or no if the build failed. |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1280 * @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
|
1281 * @param tile to inquiry |
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1282 * @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
|
1283 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1284 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
|
1285 { |
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
|
1286 /* 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
|
1287 * @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
|
1288 */ |
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
|
1289 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
|
1290 |
11231
1b7daea82ad7
(svn r15585) -Codechange: Remove TILE_ASSERT and replace all instances with assert(tile < MapSize()).
yexo <yexo@openttd.org>
parents:
11230
diff
changeset
|
1291 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
|
1292 |
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
|
1293 /* 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
|
1294 * 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
|
1295 * 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
|
1296 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
|
1297 case TL_BETTER_ROADS: |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1298 _grow_town_result = 10 + t->cache.num_houses * 2 / 9; |
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
|
1299 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
|
1300 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1301 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
|
1302 case TL_2X2_GRID: |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1303 _grow_town_result = 10 + t->cache.num_houses * 1 / 9; |
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
|
1304 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
|
1305 |
6777295c2328
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents:
6560
diff
changeset
|
1306 default: |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1307 _grow_town_result = 10 + t->cache.num_houses * 4 / 9; |
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
|
1308 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
|
1309 } |
5584
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 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
|
1312 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
|
1313 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1314 /* 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
|
1315 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
|
1316 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1317 /* 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
|
1318 * 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
|
1319 cur_rb &= ~DiagDirToRoadBits(ReverseDiagDir(target_dir)); |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
1320 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
|
1321 return _grow_town_result; |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
1322 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1323 |
18000
7a129cd9f0b4
(svn r22809) -Fix [FS#4731]: towns expanding from the "wrong" side of a tunnel or bridge
rubidium <rubidium@openttd.org>
parents:
17902
diff
changeset
|
1324 if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
7a129cd9f0b4
(svn r22809) -Fix [FS#4731]: towns expanding from the "wrong" side of a tunnel or bridge
rubidium <rubidium@openttd.org>
parents:
17902
diff
changeset
|
1325 /* Only build in the direction away from the tunnel or bridge. */ |
7a129cd9f0b4
(svn r22809) -Fix [FS#4731]: towns expanding from the "wrong" side of a tunnel or bridge
rubidium <rubidium@openttd.org>
parents:
17902
diff
changeset
|
1326 target_dir = ReverseDiagDir(GetTunnelBridgeDirection(tile)); |
7a129cd9f0b4
(svn r22809) -Fix [FS#4731]: towns expanding from the "wrong" side of a tunnel or bridge
rubidium <rubidium@openttd.org>
parents:
17902
diff
changeset
|
1327 } else { |
7a129cd9f0b4
(svn r22809) -Fix [FS#4731]: towns expanding from the "wrong" side of a tunnel or bridge
rubidium <rubidium@openttd.org>
parents:
17902
diff
changeset
|
1328 /* Select a random bit from the blockmask, walk a step |
7a129cd9f0b4
(svn r22809) -Fix [FS#4731]: towns expanding from the "wrong" side of a tunnel or bridge
rubidium <rubidium@openttd.org>
parents:
17902
diff
changeset
|
1329 * and continue the search from there. */ |
7a129cd9f0b4
(svn r22809) -Fix [FS#4731]: towns expanding from the "wrong" side of a tunnel or bridge
rubidium <rubidium@openttd.org>
parents:
17902
diff
changeset
|
1330 do target_dir = RandomDiagDir(); while (!(cur_rb & DiagDirToRoadBits(target_dir))); |
7a129cd9f0b4
(svn r22809) -Fix [FS#4731]: towns expanding from the "wrong" side of a tunnel or bridge
rubidium <rubidium@openttd.org>
parents:
17902
diff
changeset
|
1331 } |
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
|
1332 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
|
1333 |
9341
98ef22a4841d
(svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch <frosch@openttd.org>
parents:
9334
diff
changeset
|
1334 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
|
1335 /* Don't allow building over roads of other cities */ |
12250
b2b9e7cd3be5
(svn r16665) -Codechange: replace GetTownByTile() by Town::GetByTile()
smatz <smatz@openttd.org>
parents:
12249
diff
changeset
|
1336 if (IsRoadOwner(tile, ROADTYPE_ROAD, OWNER_TOWN) && Town::GetByTile(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
|
1337 _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
|
1338 } 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
|
1339 /* 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
|
1340 * 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
|
1341 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
|
1342 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1345 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1346 /* 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
|
1347 } 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
|
1348 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1349 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
|
1350 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1351 |
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
|
1352 /** |
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
|
1353 * 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
|
1354 * 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
|
1355 * 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
|
1356 * |
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
|
1357 * @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
|
1358 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
1359 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
|
1360 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1361 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
|
1362 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
|
1363 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
|
1364 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
|
1365 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
|
1366 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1367 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1368 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1369 * 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
|
1370 * @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
|
1371 * @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
|
1372 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1373 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
|
1374 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1375 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
|
1376 {-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
|
1377 { 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
|
1378 { 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
|
1379 {-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
|
1380 {-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
|
1381 { 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
|
1382 { 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
|
1383 { 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
|
1384 {-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
|
1385 {-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
|
1386 { 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
|
1387 { 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
|
1388 { 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
|
1389 }; |
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
|
1390 |
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
|
1391 /* Current "company" is a town */ |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
1392 Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1393 |
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
|
1394 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
|
1395 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1396 /* 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
|
1397 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
|
1398 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
|
1399 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
|
1400 int r = GrowTownAtRoad(t, tile); |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15115
diff
changeset
|
1401 cur_company.Restore(); |
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
|
1402 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
|
1403 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1404 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
|
1405 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1406 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1407 /* 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
|
1408 * clearing some land and then building a road there. */ |
12951
9b2b7c2b2f40
(svn r17444) -Fix [FS#3173]: when building roads isn't allowed for town, then don't build the initial piece either
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
1409 if (_settings_game.economy.allow_town_roads || _generating_world) { |
9b2b7c2b2f40
(svn r17444) -Fix [FS#3173]: when building roads isn't allowed for town, then don't build the initial piece either
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
1410 tile = t->xy; |
9b2b7c2b2f40
(svn r17444) -Fix [FS#3173]: when building roads isn't allowed for town, then don't build the initial piece either
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
1411 for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
9b2b7c2b2f40
(svn r17444) -Fix [FS#3173]: when building roads isn't allowed for town, then don't build the initial piece either
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
1412 /* Only work with plain land that not already has a house */ |
18257
b6026cba5dae
(svn r23093) -Codechange: add a default NULL for the Z of GetTileSlope and use it
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
1413 if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile) == SLOPE_FLAT) { |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1414 if (DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded()) { |
12951
9b2b7c2b2f40
(svn r17444) -Fix [FS#3173]: when building roads isn't allowed for town, then don't build the initial piece either
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
1415 DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15115
diff
changeset
|
1416 cur_company.Restore(); |
12951
9b2b7c2b2f40
(svn r17444) -Fix [FS#3173]: when building roads isn't allowed for town, then don't build the initial piece either
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
1417 return true; |
9b2b7c2b2f40
(svn r17444) -Fix [FS#3173]: when building roads isn't allowed for town, then don't build the initial piece either
rubidium <rubidium@openttd.org>
parents:
12946
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 } |
12951
9b2b7c2b2f40
(svn r17444) -Fix [FS#3173]: when building roads isn't allowed for town, then don't build the initial piece either
rubidium <rubidium@openttd.org>
parents:
12946
diff
changeset
|
1420 tile = TILE_ADD(tile, ToTileIndexDiff(*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
|
1421 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1422 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1423 |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15115
diff
changeset
|
1424 cur_company.Restore(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1425 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
|
1426 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1427 |
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
|
1428 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
|
1429 { |
8944
24302d526047
(svn r12731) -Fix (r12726): copying a 16bit array into 32bit wouldn't work
smatz <smatz@openttd.org>
parents:
8943
diff
changeset
|
1430 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
|
1431 { 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
|
1432 { 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
|
1433 { 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
|
1434 { 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
|
1435 { 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
|
1436 { 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
|
1437 { 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
|
1438 { 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
|
1439 { 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
|
1440 { 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
|
1441 { 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
|
1442 { 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
|
1443 { 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
|
1444 { 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
|
1445 { 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
|
1446 { 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
|
1447 { 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
|
1448 { 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
|
1449 {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
|
1450 {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
|
1451 {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
|
1452 {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
|
1453 {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
|
1454 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1455 |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1456 if (t->cache.num_houses < 92) { |
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1457 memcpy(t->cache.squared_town_zone_radius, _town_squared_town_zone_radius_data[t->cache.num_houses / 4], sizeof(t->cache.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
|
1458 } else { |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1459 int mass = t->cache.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
|
1460 /* 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
|
1461 * 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
|
1462 * to the calculated value.*/ |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1463 t->cache.squared_town_zone_radius[0] = mass * 15 - 40; |
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1464 t->cache.squared_town_zone_radius[1] = mass * 9 - 15; |
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1465 t->cache.squared_town_zone_radius[2] = 0; |
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1466 t->cache.squared_town_zone_radius[3] = mass * 5 - 5; |
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1467 t->cache.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
|
1468 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1469 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1470 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1471 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
|
1472 { |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1473 t->supplied[CT_PASSENGERS].old_max = t->cache.population >> 3; |
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1474 t->supplied[CT_MAIL].old_max = t->cache.population >> 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
|
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 |
6486
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1477 /** |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1478 * 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
|
1479 * |
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1480 * @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
|
1481 * @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
|
1482 * @param townnameparts The town name |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
1483 * @param size Parameter for size determination |
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
1484 * @param city whether to build a city or town |
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
1485 * @param layout the (road) layout of the town |
13776
d00566f5e4c8
(svn r18302) -Fix [FS#3328](r18281): city size multiplier was ignored when generating new game
smatz <smatz@openttd.org>
parents:
13758
diff
changeset
|
1486 * @param manual was the town placed manually? |
6486
12262d0c44ed
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents:
6484
diff
changeset
|
1487 */ |
13776
d00566f5e4c8
(svn r18302) -Fix [FS#3328](r18281): city size multiplier was ignored when generating new game
smatz <smatz@openttd.org>
parents:
13758
diff
changeset
|
1488 static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout, bool manual) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1489 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1490 t->xy = tile; |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1491 t->cache.num_houses = 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
|
1492 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
|
1493 UpdateTownRadius(t); |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
1494 t->flags = 0; |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1495 t->cache.population = 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
|
1496 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
|
1497 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
|
1498 |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1499 /* Set the default cargo requirement for town growth */ |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1500 switch (_settings_game.game_creation.landscape) { |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1501 case LT_ARCTIC: |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1502 if (FindFirstCargoWithTownEffect(TE_FOOD) != NULL) t->goal[TE_FOOD] = TOWN_GROWTH_WINTER; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1503 break; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1504 |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1505 case LT_TROPIC: |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1506 if (FindFirstCargoWithTownEffect(TE_FOOD) != NULL) t->goal[TE_FOOD] = TOWN_GROWTH_DESERT; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1507 if (FindFirstCargoWithTownEffect(TE_WATER) != NULL) t->goal[TE_WATER] = TOWN_GROWTH_DESERT; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1508 break; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1509 } |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
1510 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1511 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
|
1512 |
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
|
1513 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
|
1514 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1515 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
|
1516 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
|
1517 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
|
1518 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
|
1519 |
13110
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1520 extern int _nb_orig_names; |
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
|
1521 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
|
1522 /* Original town name */ |
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
1523 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
|
1524 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
|
1525 } else { |
6d300d04ac5e
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents:
6950
diff
changeset
|
1526 /* 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
|
1527 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
|
1528 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
|
1529 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1530 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
|
1531 |
12391
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
1532 t->UpdateVirtCoord(); |
9387
a240dd49a2e8
(svn r13297) -Codechange: Use GUIList for the town directory window
peter1138 <peter1138@openttd.org>
parents:
9358
diff
changeset
|
1533 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
|
1534 |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
1535 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
|
1536 |
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
|
1537 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
|
1538 |
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
|
1539 int x = (int)size * 16 + 3; |
14882
f2931c1d6199
(svn r19478) -Codechange: Resolve TS_ prefix clash between TileSource and TownSize enums.
alberth <alberth@openttd.org>
parents:
14810
diff
changeset
|
1540 if (size == TSZ_RANDOM) x = (Random() & 0xF) + 8; |
13776
d00566f5e4c8
(svn r18302) -Fix [FS#3328](r18281): city size multiplier was ignored when generating new game
smatz <smatz@openttd.org>
parents:
13758
diff
changeset
|
1541 /* Don't create huge cities when founding town in-game */ |
d00566f5e4c8
(svn r18302) -Fix [FS#3328](r18281): city size multiplier was ignored when generating new game
smatz <smatz@openttd.org>
parents:
13758
diff
changeset
|
1542 if (city && (!manual || _game_mode == GM_EDITOR)) 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
|
1543 |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1544 t->cache.num_houses += x; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1545 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
|
1546 |
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
|
1547 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
|
1548 do { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1549 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
|
1550 } 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
|
1551 |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1552 t->cache.num_houses -= x; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1553 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
|
1554 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
|
1555 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
|
1556 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1557 |
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
|
1558 /** |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1559 * 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
|
1560 * @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
|
1561 * @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
|
1562 */ |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1563 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
|
1564 { |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1565 /* 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
|
1566 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
|
1567 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
|
1568 } |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1569 |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1570 /* 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
|
1571 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
|
1572 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
|
1573 } |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1574 |
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 /* Can only build on clear flat areas, possibly with trees. */ |
18257
b6026cba5dae
(svn r23093) -Codechange: add a default NULL for the Z of GetTileSlope and use it
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
1576 if ((!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES)) || GetTileSlope(tile) != 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
|
1577 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
|
1578 } |
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 |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1580 return CommandCost(EXPENSES_OTHER); |
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
|
1581 } |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1582 |
13110
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1583 /** |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1584 * Verifies this custom name is unique. Only custom names are checked. |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1585 * @param name name to check |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1586 * @return is this name unique? |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1587 */ |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1588 static bool IsUniqueTownName(const char *name) |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1589 { |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1590 const Town *t; |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1591 |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1592 FOR_ALL_TOWNS(t) { |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1593 if (t->name != NULL && strcmp(t->name, name) == 0) return false; |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1594 } |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1595 |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1596 return true; |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1597 } |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1598 |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1599 /** |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1600 * Create a new 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
|
1601 * @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
|
1602 * @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
|
1603 * @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
|
1604 * 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
|
1605 * 3..5 town road layout (@see TownLayout) |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1606 * 6 use random location (randomize \c tile ) |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1607 * @param p2 town name parts |
16467
389964fe107f
(svn r21191) -Doc: Add missing information for a parameter of CmdFoundTown.
terkhen <terkhen@openttd.org>
parents:
16440
diff
changeset
|
1608 * @param text Custom name for the town. If empty, the town name parts will be used. |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13060
diff
changeset
|
1609 * @return the cost of this operation or an 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
|
1610 */ |
13102
f5a5aaceaea7
(svn r17603) -Codechange: since now, towns are 'founded' instead of 'built'
smatz <smatz@openttd.org>
parents:
13089
diff
changeset
|
1611 CommandCost CmdFoundTown(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
|
1612 { |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
15002
diff
changeset
|
1613 TownSize size = Extract<TownSize, 0, 2>(p1); |
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
|
1614 bool city = HasBit(p1, 2); |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
15002
diff
changeset
|
1615 TownLayout layout = Extract<TownLayout, 3, 3>(p1); |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1616 TownNameParams par(_settings_game.game_creation.town_name); |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1617 bool random = HasBit(p1, 6); |
11155
0f3a338d8432
(svn r15505) -Codechange: pass name of new town as parameter to CMD_BUILD_TOWN
smatz <smatz@openttd.org>
parents:
11108
diff
changeset
|
1618 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
|
1619 |
14883
341dafa0f361
(svn r19479) -Codechange: Test range of town size and layout instead of against the current last value.
alberth <alberth@openttd.org>
parents:
14882
diff
changeset
|
1620 if (size >= TSZ_END) return CMD_ERROR; |
341dafa0f361
(svn r19479) -Codechange: Test range of town size and layout instead of against the current last value.
alberth <alberth@openttd.org>
parents:
14882
diff
changeset
|
1621 if (layout >= NUM_TLS) 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
|
1622 |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1623 /* Some things are allowed only in the scenario editor */ |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1624 if (_game_mode != GM_EDITOR) { |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1625 if (_settings_game.economy.found_town == TF_FORBIDDEN) return CMD_ERROR; |
14882
f2931c1d6199
(svn r19478) -Codechange: Resolve TS_ prefix clash between TileSource and TownSize enums.
alberth <alberth@openttd.org>
parents:
14810
diff
changeset
|
1626 if (size == TSZ_LARGE) return CMD_ERROR; |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1627 if (random) return CMD_ERROR; |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1628 if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT && layout != _settings_game.economy.town_layout) { |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1629 return CMD_ERROR; |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1630 } |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1631 } |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1632 |
13110
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1633 if (StrEmpty(text)) { |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1634 /* If supplied name is empty, townnameparts has to generate unique automatic name */ |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1635 if (!VerifyTownName(townnameparts, &par)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1636 } else { |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1637 /* If name is not empty, it has to be unique custom name */ |
16683
50342e8df7e6
(svn r21414) -Codechange: limit town name by amount of characters, not bytes
rubidium <rubidium@openttd.org>
parents:
16681
diff
changeset
|
1638 if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return CMD_ERROR; |
13110
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1639 if (!IsUniqueTownName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); |
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1640 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1641 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1642 /* 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
|
1643 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
|
1644 |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1645 if (!random) { |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1646 CommandCost ret = TownCanBePlacedHere(tile); |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1647 if (ret.Failed()) return ret; |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1648 } |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1649 |
14882
f2931c1d6199
(svn r19478) -Codechange: Resolve TS_ prefix clash between TileSource and TownSize enums.
alberth <alberth@openttd.org>
parents:
14810
diff
changeset
|
1650 static const byte price_mult[][TSZ_RANDOM + 1] = {{ 15, 25, 40, 25 }, { 20, 35, 55, 35 }}; |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1651 /* multidimensional arrays have to have defined length of non-first dimension */ |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1652 assert_compile(lengthof(price_mult[0]) == 4); |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1653 |
13758
9a5050ee2cec
(svn r18283) -Feature: [NewGRF] Add new price bases for removing industries, building/removing unmovables (new objects), building/removing rail-waypoints/buoys, interacting with town-authority, building foundations, funding primary industries (when not prospecting) and towns.
frosch <frosch@openttd.org>
parents:
13756
diff
changeset
|
1654 CommandCost cost(EXPENSES_OTHER, _price[PR_BUILD_TOWN]); |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1655 byte mult = price_mult[city][size]; |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1656 |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1657 cost.MultiplyCost(mult); |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1658 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1659 /* 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
|
1660 if (flags & DC_EXEC) { |
14008
6eca3533ed1d
(svn r18550) -Fix (r18281): show expected price of town construction even when the company doesn't have enough money
smatz <smatz@openttd.org>
parents:
13886
diff
changeset
|
1661 if (cost.GetCost() > GetAvailableMoneyForCommand()) { |
6eca3533ed1d
(svn r18550) -Fix (r18281): show expected price of town construction even when the company doesn't have enough money
smatz <smatz@openttd.org>
parents:
13886
diff
changeset
|
1662 _additional_cash_required = cost.GetCost(); |
6eca3533ed1d
(svn r18550) -Fix (r18281): show expected price of town construction even when the company doesn't have enough money
smatz <smatz@openttd.org>
parents:
13886
diff
changeset
|
1663 return CommandCost(EXPENSES_OTHER); |
6eca3533ed1d
(svn r18550) -Fix (r18281): show expected price of town construction even when the company doesn't have enough money
smatz <smatz@openttd.org>
parents:
13886
diff
changeset
|
1664 } |
6eca3533ed1d
(svn r18550) -Fix (r18281): show expected price of town construction even when the company doesn't have enough money
smatz <smatz@openttd.org>
parents:
13886
diff
changeset
|
1665 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1666 _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
|
1667 UpdateNearestTownForRoadTiles(true); |
13110
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1668 Town *t; |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1669 if (random) { |
13110
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1670 t = CreateRandomTown(20, townnameparts, size, city, layout); |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1671 if (t == NULL) { |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1672 cost = CommandCost(STR_ERROR_NO_SPACE_FOR_TOWN); |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1673 } else { |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1674 _new_town_id = t->index; |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1675 } |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1676 } else { |
13110
ef8cf99dc344
(svn r17612) -Feature: possibility to choose (randomise or enter custom) town name before its creation (original patch by Terkhen)
smatz <smatz@openttd.org>
parents:
13109
diff
changeset
|
1677 t = new Town(tile); |
13776
d00566f5e4c8
(svn r18302) -Fix [FS#3328](r18281): city size multiplier was ignored when generating new game
smatz <smatz@openttd.org>
parents:
13758
diff
changeset
|
1678 DoCreateTown(t, tile, townnameparts, size, city, layout, true); |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1679 } |
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
|
1680 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
|
1681 _generating_world = false; |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1682 |
13113
07789c94f3db
(svn r17615) -Fix (r17612): town sign could be glitchy when creating town with custom name (Terkhen)
smatz <smatz@openttd.org>
parents:
13112
diff
changeset
|
1683 if (t != NULL && !StrEmpty(text)) { |
07789c94f3db
(svn r17615) -Fix (r17612): town sign could be glitchy when creating town with custom name (Terkhen)
smatz <smatz@openttd.org>
parents:
13112
diff
changeset
|
1684 t->name = strdup(text); |
07789c94f3db
(svn r17615) -Fix (r17612): town sign could be glitchy when creating town with custom name (Terkhen)
smatz <smatz@openttd.org>
parents:
13112
diff
changeset
|
1685 t->UpdateVirtCoord(); |
07789c94f3db
(svn r17615) -Fix (r17612): town sign could be glitchy when creating town with custom name (Terkhen)
smatz <smatz@openttd.org>
parents:
13112
diff
changeset
|
1686 } |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1687 |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1688 if (_game_mode != GM_EDITOR) { |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1689 /* 't' can't be NULL since 'random' is false outside scenedit */ |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1690 assert(!random); |
16681
3a1ac9bae6cc
(svn r21412) -Codechange: limit company name by amount of characters, not bytes
rubidium <rubidium@openttd.org>
parents:
16563
diff
changeset
|
1691 char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH]; |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1692 SetDParam(0, _current_company); |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1693 GetString(company_name, STR_COMPANY_NAME, lastof(company_name)); |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1694 |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1695 char *cn = strdup(company_name); |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1696 SetDParamStr(0, cn); |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1697 SetDParam(1, t->index); |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1698 |
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1699 AddNewsItem(STR_NEWS_NEW_TOWN, NS_INDUSTRY_OPEN, NR_TILE, tile, NR_NONE, UINT32_MAX, cn); |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18498
diff
changeset
|
1700 AI::BroadcastNewEvent(new ScriptEventTownFounded(t->index)); |
18774
1fa19d70aea9
(svn r23622) -Add: a set of events to trigger in a GameScript
truebrain <truebrain@openttd.org>
parents:
18772
diff
changeset
|
1701 Game::NewEvent(new ScriptEventTownFounded(t->index)); |
13756
9f062af2f34a
(svn r18281) -Feature: founding towns in-game (based on work by Belugas, TheJosh, GeekToo, Terkhen and others)
smatz <smatz@openttd.org>
parents:
13586
diff
changeset
|
1702 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1703 } |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1704 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
|
1705 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1706 |
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
|
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 * 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
|
1709 * 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
|
1710 * 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
|
1711 * |
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
|
1712 * @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
|
1713 * @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
|
1714 * @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
|
1715 */ |
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 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
|
1717 { |
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 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
|
1719 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
|
1720 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
|
1721 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
|
1722 } |
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
|
1723 } |
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
|
1724 |
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
|
1725 /** |
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
|
1726 * 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
|
1727 * 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
|
1728 * 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
|
1729 * |
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
|
1730 * @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
|
1731 * @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
|
1732 * @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
|
1733 */ |
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
|
1734 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
|
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 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
|
1737 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
|
1738 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
|
1739 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
|
1740 } |
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
|
1741 } |
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
|
1742 |
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
|
1743 /** |
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
|
1744 * 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
|
1745 */ |
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
|
1746 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
|
1747 TileIndex tile; ///< holds the tile that was found |
12407
fd13a5d93ffb
(svn r16841) -Cleanup: spaces/tabs where they don't belong
rubidium <rubidium@openttd.org>
parents:
12395
diff
changeset
|
1748 uint max_dist; ///< holds the distance that tile is from the water |
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
|
1749 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
|
1750 }; |
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
|
1751 |
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
|
1752 /** |
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
|
1753 * CircularTileSearch callback; finds the tile furthest from any |
15002
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14886
diff
changeset
|
1754 * water. slightly bit tricky, since it has to do a search of its own |
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
|
1755 * 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
|
1756 * 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
|
1757 * |
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
|
1758 * 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
|
1759 * 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
|
1760 * 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
|
1761 * |
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
|
1762 * @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
|
1763 * @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
|
1764 * 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
|
1765 * |
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
|
1766 * @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
|
1767 */ |
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
|
1768 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
|
1769 { |
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
|
1770 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
|
1771 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
|
1772 |
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
|
1773 if (IsTileType(tile, MP_CLEAR) && |
18257
b6026cba5dae
(svn r23093) -Codechange: add a default NULL for the Z of GetTileSlope and use it
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
1774 GetTileSlope(tile) == SLOPE_FLAT && |
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
|
1775 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
|
1776 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
|
1777 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
|
1778 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
|
1779 } |
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
|
1780 |
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
|
1781 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
|
1782 } |
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
|
1783 |
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
|
1784 /** |
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
|
1785 * 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
|
1786 * |
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
|
1787 * @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
|
1788 * @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
|
1789 */ |
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
|
1790 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
|
1791 { |
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
|
1792 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
|
1793 } |
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
|
1794 |
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
|
1795 /** |
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
|
1796 * 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
|
1797 * 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
|
1798 * 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
|
1799 * 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
|
1800 * 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
|
1801 * 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
|
1802 * |
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
|
1803 * @param tile Start looking from this spot. |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
1804 * @param layout the road layout to search for |
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
|
1805 * @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
|
1806 */ |
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
|
1807 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
|
1808 { |
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
|
1809 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
|
1810 |
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
|
1811 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
|
1812 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
|
1813 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
|
1814 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
|
1815 } |
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
|
1816 |
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
|
1817 /* 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
|
1818 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
|
1819 } |
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
|
1820 |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1821 static Town *CreateRandomTown(uint attempts, 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
|
1822 { |
18964
a5926c47032d
(svn r23819) -Fix [FS#4951]: Removal of towns with 0 population failed during map generation.
frosch <frosch@openttd.org>
parents:
18891
diff
changeset
|
1823 assert(_game_mode == GM_EDITOR || _generating_world); // These are the preconditions for CMD_DELETE_TOWN |
a5926c47032d
(svn r23819) -Fix [FS#4951]: Removal of towns with 0 population failed during map generation.
frosch <frosch@openttd.org>
parents:
18891
diff
changeset
|
1824 |
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
|
1825 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
|
1826 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1827 do { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1828 /* 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
|
1829 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
|
1830 |
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
|
1831 /* 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
|
1832 * 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
|
1833 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
|
1834 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
|
1835 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
|
1836 } |
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
|
1837 |
536d28b21537
(svn r15890) -Codechange: unify the way 'can a town be placed here?' checks are done
smatz <smatz@openttd.org>
parents:
11470
diff
changeset
|
1838 /* Make sure town can be placed here */ |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1839 if (TownCanBePlacedHere(tile).Failed()) 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
|
1840 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1841 /* 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
|
1842 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
|
1843 |
13776
d00566f5e4c8
(svn r18302) -Fix [FS#3328](r18281): city size multiplier was ignored when generating new game
smatz <smatz@openttd.org>
parents:
13758
diff
changeset
|
1844 DoCreateTown(t, tile, townnameparts, size, city, layout, false); |
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
|
1845 |
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
|
1846 /* 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
|
1847 * placement is so bad it couldn't grow at all */ |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1848 if (t->cache.population > 0) return t; |
18964
a5926c47032d
(svn r23819) -Fix [FS#4951]: Removal of towns with 0 population failed during map generation.
frosch <frosch@openttd.org>
parents:
18891
diff
changeset
|
1849 CommandCost rc = DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN); |
a5926c47032d
(svn r23819) -Fix [FS#4951]: Removal of towns with 0 population failed during map generation.
frosch <frosch@openttd.org>
parents:
18891
diff
changeset
|
1850 assert(rc.Succeeded()); |
17325
46688a193806
(svn r22065) -Fix [FS#4500]: pool allocation checks triggered when towns could not be built
rubidium <rubidium@openttd.org>
parents:
17278
diff
changeset
|
1851 |
46688a193806
(svn r22065) -Fix [FS#4500]: pool allocation checks triggered when towns could not be built
rubidium <rubidium@openttd.org>
parents:
17278
diff
changeset
|
1852 /* We already know that we can allocate a single town when |
46688a193806
(svn r22065) -Fix [FS#4500]: pool allocation checks triggered when towns could not be built
rubidium <rubidium@openttd.org>
parents:
17278
diff
changeset
|
1853 * entering this function. However, we create and delete |
46688a193806
(svn r22065) -Fix [FS#4500]: pool allocation checks triggered when towns could not be built
rubidium <rubidium@openttd.org>
parents:
17278
diff
changeset
|
1854 * a town which "resets" the allocation checks. As such we |
46688a193806
(svn r22065) -Fix [FS#4500]: pool allocation checks triggered when towns could not be built
rubidium <rubidium@openttd.org>
parents:
17278
diff
changeset
|
1855 * need to check again when assertions are enabled. */ |
46688a193806
(svn r22065) -Fix [FS#4500]: pool allocation checks triggered when towns could not be built
rubidium <rubidium@openttd.org>
parents:
17278
diff
changeset
|
1856 assert(Town::CanAllocateItem()); |
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
|
1857 } 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
|
1858 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1859 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
|
1860 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1861 |
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
|
1862 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
|
1863 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1864 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1865 * This function will generate a certain amount of towns, with a certain layout |
12539
b8c81bc9cb33
(svn r16977) -Fix(r1772)[FS#3059]: make it so that failing to generate many random towns in scenario editor returns a failing message.
belugas <belugas@openttd.org>
parents:
12475
diff
changeset
|
1866 * It can be called from the scenario editor (i.e.: generate Random Towns) |
b8c81bc9cb33
(svn r16977) -Fix(r1772)[FS#3059]: make it so that failing to generate many random towns in scenario editor returns a failing message.
belugas <belugas@openttd.org>
parents:
12475
diff
changeset
|
1867 * as well as from world creation. |
b8c81bc9cb33
(svn r16977) -Fix(r1772)[FS#3059]: make it so that failing to generate many random towns in scenario editor returns a failing message.
belugas <belugas@openttd.org>
parents:
12475
diff
changeset
|
1868 * @param layout which towns will be set to, when created |
b8c81bc9cb33
(svn r16977) -Fix(r1772)[FS#3059]: make it so that failing to generate many random towns in scenario editor returns a failing message.
belugas <belugas@openttd.org>
parents:
12475
diff
changeset
|
1869 * @return true if towns have been successfully created |
b8c81bc9cb33
(svn r16977) -Fix(r1772)[FS#3059]: make it so that failing to generate many random towns in scenario editor returns a failing message.
belugas <belugas@openttd.org>
parents:
12475
diff
changeset
|
1870 */ |
11002
9514cd63fe53
(svn r15342) -Feature: allow changing town layout in the 'Found new town' window
smatz <smatz@openttd.org>
parents:
11000
diff
changeset
|
1871 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
|
1872 { |
16017
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1873 uint current_number = 0; |
16018
f6bb3f37feb7
(svn r20711) -Fix [FS#4094]: Do not use new game settings when creating many random towns at the scenario editor.
terkhen <terkhen@openttd.org>
parents:
16017
diff
changeset
|
1874 uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_towns : 0; |
16017
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1875 uint total = (difficulty == (uint)CUSTOM_TOWN_NUMBER_DIFFICULTY) ? _settings_game.game_creation.custom_town_number : ScaleByMapSize(_num_initial_towns[difficulty] + (Random() & 7)); |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1876 uint32 townnameparts; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1877 |
16017
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1878 SetGeneratingWorldProgress(GWP_TOWN, total); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1879 |
12539
b8c81bc9cb33
(svn r16977) -Fix(r1772)[FS#3059]: make it so that failing to generate many random towns in scenario editor returns a failing message.
belugas <belugas@openttd.org>
parents:
12475
diff
changeset
|
1880 /* First attempt will be made at creating the suggested number of towns. |
12540
b0a0b29aa2b0
(svn r16978) -Fix(r16977): tab indentation instead of space indentation at beginning of a line, please
belugas <belugas@openttd.org>
parents:
12539
diff
changeset
|
1881 * Note that this is really a suggested value, not a required one. |
b0a0b29aa2b0
(svn r16978) -Fix(r16977): tab indentation instead of space indentation at beginning of a line, please
belugas <belugas@openttd.org>
parents:
12539
diff
changeset
|
1882 * We would not like the system to lock up just because the user wanted 100 cities on a 64*64 map, would we? */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1883 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
|
1884 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
|
1885 IncreaseGeneratingWorldProgress(GWP_TOWN); |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1886 /* Get a unique name for the town. */ |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1887 if (!GenerateTownName(&townnameparts)) continue; |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
1888 /* try 20 times to create a random-sized town for the first loop. */ |
16017
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1889 if (CreateRandomTown(20, townnameparts, TSZ_RANDOM, city, layout) != NULL) current_number++; // If creation was successful, raise a flag. |
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1890 } while (--total); |
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1891 |
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1892 if (current_number != 0) return true; |
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1893 |
0906e67b6ea6
(svn r20710) -Codechange: Clarify the name of some town generation variables.
terkhen <terkhen@openttd.org>
parents:
15944
diff
changeset
|
1894 /* If current_number is still zero at this point, it means that not a single town has been created. |
12540
b0a0b29aa2b0
(svn r16978) -Fix(r16977): tab indentation instead of space indentation at beginning of a line, please
belugas <belugas@openttd.org>
parents:
12539
diff
changeset
|
1895 * So give it a last try, but now more aggressive */ |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1896 if (GenerateTownName(&townnameparts) && |
14882
f2931c1d6199
(svn r19478) -Codechange: Resolve TS_ prefix clash between TileSource and TownSize enums.
alberth <alberth@openttd.org>
parents:
14810
diff
changeset
|
1897 CreateRandomTown(10000, townnameparts, TSZ_RANDOM, _settings_game.economy.larger_towns != 0, layout) != NULL) { |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1898 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
|
1899 } |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1900 |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1901 /* If there are no towns at all and we are generating new game, bail out */ |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1902 if (Town::GetNumItems() == 0 && _game_mode != GM_EDITOR) { |
18629
a55c2ad0bf2c
(svn r23476) -Codechange: use the error queue to replace switch mode error strings, again making it possible to return multiple errors
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
1903 ShowErrorMessage(STR_ERROR_COULD_NOT_CREATE_TOWN, INVALID_STRING_ID, WL_CRITICAL); |
13107
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1904 } |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1905 |
ddd1ec2f6086
(svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too
smatz <smatz@openttd.org>
parents:
13102
diff
changeset
|
1906 return false; // we are still without a town? we failed, simply |
5584
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1909 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1910 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
1911 * 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
|
1912 * @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
|
1913 * @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
|
1914 * @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
|
1915 */ |
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
|
1916 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
|
1917 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1918 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
|
1919 |
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
|
1920 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
|
1921 |
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
|
1922 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
|
1923 for (HouseZonesBits i = HZB_BEGIN; i < HZB_END; i++) { |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
1924 if (dist < t->cache.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
|
1925 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1926 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1927 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
|
1928 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1929 |
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
|
1930 /** |
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
|
1931 * Clears tile and builds a house or house part. |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
1932 * @param tile tile index |
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
1933 * @param t The town to clear the house for |
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
|
1934 * @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
|
1935 * @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
|
1936 * @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
|
1937 * @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
|
1938 * @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
|
1939 */ |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1940 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
|
1941 { |
9436
b3969ef775ba
(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents:
9413
diff
changeset
|
1942 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
|
1943 |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1944 assert(cc.Succeeded()); |
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
|
1945 |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1946 IncreaseBuildingCount(t, type); |
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1947 MakeHouseTile(tile, t->index, counter, stage, type, random_bits); |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
1948 if (HouseSpec::Get(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(tile); |
9006
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
1949 |
9bf1de259ada
(svn r12801) -Codechange: remove the dependency of function.h in town_map.h
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
1950 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
|
1951 } |
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
|
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 |
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
|
1954 /** |
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
|
1955 * 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
|
1956 * @param t tile index |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
1957 * @param town The town related to this 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
|
1958 * @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
|
1959 * @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
|
1960 * @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
|
1961 * @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
|
1962 * @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
|
1963 */ |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1964 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
|
1965 { |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
1966 BuildingFlags size = HouseSpec::Get(type)->building_flags; |
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
|
1967 |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
1968 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
|
1969 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
|
1970 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
|
1971 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
|
1972 } |
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
|
1973 |
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
|
1974 |
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
|
1975 /** |
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
|
1976 * 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
|
1977 * 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
|
1978 * @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
|
1979 * @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
|
1980 * @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
|
1981 * @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
|
1982 */ |
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
|
1983 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
|
1984 { |
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
|
1985 /* cannot build on these slopes... */ |
18257
b6026cba5dae
(svn r23093) -Codechange: add a default NULL for the Z of GetTileSlope and use it
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
1986 Slope slope = GetTileSlope(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
|
1987 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
|
1988 |
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
|
1989 /* 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
|
1990 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
|
1991 |
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 /* 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
|
1993 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
|
1994 |
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
|
1995 /* can we clear the land? */ |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1996 return DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded(); |
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
|
1997 } |
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
|
1998 |
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
|
1999 |
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
|
2000 /** |
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
|
2001 * 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
|
2002 * @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
|
2003 * @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
|
2004 * @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
|
2005 * @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
|
2006 * @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
|
2007 * @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
|
2008 */ |
18272
3ebab55c5495
(svn r23108) -Codechange: more uint -> int / byte -> int conversions for Z related variables
rubidium <rubidium@openttd.org>
parents:
18271
diff
changeset
|
2009 static inline bool CheckBuildHouseSameZ(TileIndex tile, TownID town, int 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
|
2010 { |
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
|
2011 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
|
2012 |
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
|
2013 /* if building on slopes is allowed, there will be flattening foundation (to tile max z) */ |
18265
c45ee8c2b36b
(svn r23101) -Codechange: remove pointless multiplications by TILE_HEIGHT from the station/object building code
rubidium <rubidium@openttd.org>
parents:
18264
diff
changeset
|
2014 if (GetTileMaxZ(tile) != z) 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
|
2015 |
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
|
2016 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
|
2017 } |
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
|
2018 |
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
|
2019 |
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
|
2020 /** |
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
|
2021 * 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
|
2022 * @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
|
2023 * @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
|
2024 * @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
|
2025 * @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
|
2026 * @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
|
2027 * @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
|
2028 */ |
18272
3ebab55c5495
(svn r23108) -Codechange: more uint -> int / byte -> int conversions for Z related variables
rubidium <rubidium@openttd.org>
parents:
18271
diff
changeset
|
2029 static bool CheckFree2x2Area(TileIndex tile, TownID town, int 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
|
2030 { |
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 /* 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
|
2032 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
|
2033 |
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
|
2034 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
|
2035 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
|
2036 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
|
2037 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2038 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2039 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
|
2040 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2041 |
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
|
2042 |
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
|
2043 /** |
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
|
2044 * 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
|
2045 * @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
|
2046 * @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
|
2047 * @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
|
2048 * @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
|
2049 */ |
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
|
2050 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
|
2051 { |
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
|
2052 /* 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
|
2053 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
|
2054 |
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
|
2055 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
|
2056 |
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
|
2057 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
|
2058 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
|
2059 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
|
2060 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
|
2061 |
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
|
2062 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
|
2063 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
|
2064 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
|
2065 |
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
|
2066 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
|
2067 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
|
2068 } |
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
|
2069 |
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
|
2070 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
|
2071 } |
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
|
2072 |
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
|
2073 |
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
|
2074 /** |
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
|
2075 * 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
|
2076 * @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
|
2077 * @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
|
2078 * @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
|
2079 * @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
|
2080 */ |
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
|
2081 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
|
2082 { |
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
|
2083 /* 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
|
2084 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
|
2085 |
16098
69fa0c82f849
(svn r20791) -Fix (r12161): Building 2x2 houses did not work for 2x2 road layouts on all map sizes.
frosch <frosch@openttd.org>
parents:
16097
diff
changeset
|
2086 /* Compute relative position of tile. (Positive offsets are towards north) */ |
69fa0c82f849
(svn r20791) -Fix (r12161): Building 2x2 houses did not work for 2x2 road layouts on all map sizes.
frosch <frosch@openttd.org>
parents:
16097
diff
changeset
|
2087 TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile); |
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
|
2088 |
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
|
2089 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
|
2090 case TL_2X2_GRID: |
16098
69fa0c82f849
(svn r20791) -Fix (r12161): Building 2x2 houses did not work for 2x2 road layouts on all map sizes.
frosch <frosch@openttd.org>
parents:
16097
diff
changeset
|
2091 grid_pos.x %= 3; |
69fa0c82f849
(svn r20791) -Fix (r12161): Building 2x2 houses did not work for 2x2 road layouts on all map sizes.
frosch <frosch@openttd.org>
parents:
16097
diff
changeset
|
2092 grid_pos.y %= 3; |
69fa0c82f849
(svn r20791) -Fix (r12161): Building 2x2 houses did not work for 2x2 road layouts on all map sizes.
frosch <frosch@openttd.org>
parents:
16097
diff
changeset
|
2093 if ((grid_pos.x != 2 && grid_pos.x != -1) || |
69fa0c82f849
(svn r20791) -Fix (r12161): Building 2x2 houses did not work for 2x2 road layouts on all map sizes.
frosch <frosch@openttd.org>
parents:
16097
diff
changeset
|
2094 (grid_pos.y != 2 && grid_pos.y != -1)) return false; |
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
|
2095 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
|
2096 |
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
|
2097 case TL_3X3_GRID: |
16098
69fa0c82f849
(svn r20791) -Fix (r12161): Building 2x2 houses did not work for 2x2 road layouts on all map sizes.
frosch <frosch@openttd.org>
parents:
16097
diff
changeset
|
2098 if ((grid_pos.x & 3) < 2 || (grid_pos.y & 3) < 2) return false; |
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
|
2099 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
|
2100 |
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
|
2101 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
|
2102 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
|
2103 } |
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
|
2104 |
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
|
2105 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
|
2106 } |
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
|
2107 |
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
|
2108 |
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
|
2109 /** |
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
|
2110 * 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
|
2111 * 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
|
2112 * @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
|
2113 * @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
|
2114 * @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
|
2115 * @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
|
2116 * @param second diagdir from first tile to second tile |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
2117 */ |
18272
3ebab55c5495
(svn r23108) -Codechange: more uint -> int / byte -> int conversions for Z related variables
rubidium <rubidium@openttd.org>
parents:
18271
diff
changeset
|
2118 static bool CheckTownBuild2House(TileIndex *tile, Town *t, int maxz, bool noslope, DiagDirection second) |
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
|
2119 { |
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
|
2120 /* '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
|
2121 |
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
|
2122 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
|
2123 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
|
2124 |
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
|
2125 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
|
2126 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
|
2127 *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
|
2128 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
|
2129 } |
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
|
2130 |
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 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
|
2132 } |
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 |
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
|
2134 |
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 /** |
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 * 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
|
2137 * 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
|
2138 * @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
|
2139 * @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
|
2140 * @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
|
2141 * @param noslope are slopes forbidden? |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
2142 */ |
18272
3ebab55c5495
(svn r23108) -Codechange: more uint -> int / byte -> int conversions for Z related variables
rubidium <rubidium@openttd.org>
parents:
18271
diff
changeset
|
2143 static bool CheckTownBuild2x2House(TileIndex *tile, Town *t, int maxz, bool 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
|
2144 { |
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
|
2145 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
|
2146 |
17684
2773b630b41f
(svn r22459) -Doc: Typo fixes and doxygen markup improvements.
alberth <alberth@openttd.org>
parents:
17370
diff
changeset
|
2147 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
|
2148 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
|
2149 *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
|
2150 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
|
2151 } |
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
|
2152 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
|
2153 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
|
2154 } |
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
|
2155 |
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
|
2156 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
|
2157 } |
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
|
2158 |
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
|
2159 |
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
|
2160 /** |
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
|
2161 * 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
|
2162 * @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
|
2163 * @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
|
2164 * @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
|
2165 */ |
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
|
2166 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
|
2167 { |
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
|
2168 /* 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
|
2169 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
|
2170 |
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
|
2171 /* 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
|
2172 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
|
2173 |
19190
102959356aa1
(svn r24064) -Fix [FS#5121]: make the full snowedness level of houses the same as roads and rails
rubidium <rubidium@openttd.org>
parents:
19099
diff
changeset
|
2174 Slope slope = GetTileSlope(tile); |
102959356aa1
(svn r24064) -Fix [FS#5121]: make the full snowedness level of houses the same as roads and rails
rubidium <rubidium@openttd.org>
parents:
19099
diff
changeset
|
2175 int maxz = GetTileMaxZ(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
|
2176 |
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
|
2177 /* 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
|
2178 * 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
|
2179 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
|
2180 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2181 /* 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
|
2182 int land = _settings_game.game_creation.landscape; |
19190
102959356aa1
(svn r24064) -Fix [FS#5121]: make the full snowedness level of houses the same as roads and rails
rubidium <rubidium@openttd.org>
parents:
19099
diff
changeset
|
2183 if (land == LT_ARCTIC && maxz > HighestSnowLine()) land = -1; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2184 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2185 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
|
2186 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2187 /* 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
|
2188 * 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
|
2189 * 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
|
2190 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
|
2191 uint num = 0; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2192 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
|
2193 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
|
2194 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2195 /* 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
|
2196 for (uint i = 0; i < HOUSE_MAX; i++) { |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
2197 const HouseSpec *hs = HouseSpec::Get(i); |
11470
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2198 |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2199 /* Verify that the candidate house spec matches the current tile status */ |
15734
ecf03c7c6d3b
(svn r20401) -Codechange: let HouseSpec use GRFFileProps
rubidium <rubidium@openttd.org>
parents:
15672
diff
changeset
|
2200 if ((~hs->building_availability & bitmask) != 0 || !hs->enabled || hs->grf_prop.override != INVALID_HOUSE_ID) continue; |
11470
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2201 |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2202 /* 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
|
2203 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
|
2204 /* id_count is always <= class_count, so it doesn't need to be checked */ |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
2205 if (t->cache.building_counts.class_count[hs->class_id] == UINT16_MAX) continue; |
11470
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2206 } else { |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2207 /* If the house has no class, check id_count instead */ |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
2208 if (t->cache.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
|
2209 } |
11470
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2210 |
9ca1973a975d
(svn r15831) -Fix: make sure house class/ID counters don't overflow
smatz <smatz@openttd.org>
parents:
11391
diff
changeset
|
2211 /* 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
|
2212 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
|
2213 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
|
2214 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
|
2215 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
|
2216 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2217 |
17898
307d1c360da9
(svn r22697) -Fix [FS#4694-ish]: when building a house it could be built at the wrong place if multitile houses failed some tests
rubidium <rubidium@openttd.org>
parents:
17784
diff
changeset
|
2218 TileIndex baseTile = tile; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2219 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2220 while (probability_max > 0) { |
17898
307d1c360da9
(svn r22697) -Fix [FS#4694-ish]: when building a house it could be built at the wrong place if multitile houses failed some tests
rubidium <rubidium@openttd.org>
parents:
17784
diff
changeset
|
2221 /* Building a multitile building can change the location of tile. |
307d1c360da9
(svn r22697) -Fix [FS#4694-ish]: when building a house it could be built at the wrong place if multitile houses failed some tests
rubidium <rubidium@openttd.org>
parents:
17784
diff
changeset
|
2222 * The building would still be built partially on that tile, but |
307d1c360da9
(svn r22697) -Fix [FS#4694-ish]: when building a house it could be built at the wrong place if multitile houses failed some tests
rubidium <rubidium@openttd.org>
parents:
17784
diff
changeset
|
2223 * its nothern tile would be elsewere. However, if the callback |
307d1c360da9
(svn r22697) -Fix [FS#4694-ish]: when building a house it could be built at the wrong place if multitile houses failed some tests
rubidium <rubidium@openttd.org>
parents:
17784
diff
changeset
|
2224 * fails we would be basing further work from the changed tile. |
307d1c360da9
(svn r22697) -Fix [FS#4694-ish]: when building a house it could be built at the wrong place if multitile houses failed some tests
rubidium <rubidium@openttd.org>
parents:
17784
diff
changeset
|
2225 * So a next 1x1 tile building could be built on the wrong tile. */ |
307d1c360da9
(svn r22697) -Fix [FS#4694-ish]: when building a house it could be built at the wrong place if multitile houses failed some tests
rubidium <rubidium@openttd.org>
parents:
17784
diff
changeset
|
2226 tile = baseTile; |
307d1c360da9
(svn r22697) -Fix [FS#4694-ish]: when building a house it could be built at the wrong place if multitile houses failed some tests
rubidium <rubidium@openttd.org>
parents:
17784
diff
changeset
|
2227 |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2228 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
|
2229 uint i; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2230 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
|
2231 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
|
2232 r -= probs[i]; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2233 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2234 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2235 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
|
2236 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
|
2237 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2238 /* 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
|
2239 num--; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2240 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
|
2241 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
|
2242 |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
2243 const HouseSpec *hs = HouseSpec::Get(house); |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2244 |
14025
ec50d4cd06b5
(svn r18567) -Fix [FS#2613]: [NewGRF] House property 15 did not work
rubidium <rubidium@openttd.org>
parents:
14008
diff
changeset
|
2245 if (_loaded_newgrf_features.has_newhouses && !_generating_world && |
ec50d4cd06b5
(svn r18567) -Fix [FS#2613]: [NewGRF] House property 15 did not work
rubidium <rubidium@openttd.org>
parents:
14008
diff
changeset
|
2246 _game_mode != GM_EDITOR && (hs->extra_flags & BUILDING_IS_HISTORICAL) != 0) { |
ec50d4cd06b5
(svn r18567) -Fix [FS#2613]: [NewGRF] House property 15 did not work
rubidium <rubidium@openttd.org>
parents:
14008
diff
changeset
|
2247 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
|
2248 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2249 |
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
|
2250 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
|
2251 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2252 /* 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
|
2253 uint oneof = 0; |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2254 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2255 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
|
2256 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
|
2257 } 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
|
2258 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
|
2259 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2260 |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
2261 if (t->flags & oneof) continue; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2262 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2263 /* 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
|
2264 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
|
2265 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
|
2266 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2267 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
|
2268 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
|
2269 } 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
|
2270 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
|
2271 } 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
|
2272 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
|
2273 } 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
|
2274 /* 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
|
2275 } |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2276 |
15115
a93503fec8db
(svn r19744) -Add [FS#3477]: [NewGRF] Access to random bits of houses and industries from construction callbacks 17, 28 and 2F. That is: The randombits the house/industry will start with, if construction succeeds.
frosch <frosch@openttd.org>
parents:
15114
diff
changeset
|
2277 byte random_bits = Random(); |
a93503fec8db
(svn r19744) -Add [FS#3477]: [NewGRF] Access to random bits of houses and industries from construction callbacks 17, 28 and 2F. That is: The randombits the house/industry will start with, if construction succeeds.
frosch <frosch@openttd.org>
parents:
15114
diff
changeset
|
2278 |
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
|
2279 if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) { |
15115
a93503fec8db
(svn r19744) -Add [FS#3477]: [NewGRF] Access to random bits of houses and industries from construction callbacks 17, 28 and 2F. That is: The randombits the house/industry will start with, if construction succeeds.
frosch <frosch@openttd.org>
parents:
15114
diff
changeset
|
2280 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile, true, random_bits); |
18311
09cb5ec03259
(svn r23147) -Change: [NewGRF v8] Unify the return values of boolean callbacks, and check the results for validity.
frosch <frosch@openttd.org>
parents:
18306
diff
changeset
|
2281 if (callback_res != CALLBACK_FAILED && !Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_ALLOW_CONSTRUCTION, callback_res)) continue; |
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
|
2282 } |
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
|
2283 |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2284 /* build the house */ |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
2285 t->cache.num_houses++; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2286 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2287 /* Special houses that there can be only one of. */ |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
2288 t->flags |= oneof; |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2289 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2290 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
|
2291 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
|
2292 |
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
|
2293 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
|
2294 uint32 r = Random(); |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2295 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2296 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
|
2297 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
|
2298 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2299 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
|
2300 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
|
2301 } else { |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2302 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
|
2303 } |
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 } |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2305 |
15115
a93503fec8db
(svn r19744) -Add [FS#3477]: [NewGRF] Access to random bits of houses and industries from construction callbacks 17, 28 and 2F. That is: The randombits the house/industry will start with, if construction succeeds.
frosch <frosch@openttd.org>
parents:
15114
diff
changeset
|
2306 MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits); |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
2307 UpdateTownCargoes(t, tile); |
8488
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2308 |
0b3e6ee2c852
(svn r12063) -Cleanup: use C++ indenting and variable scope/declaration in BuildTownHouse()
smatz <smatz@openttd.org>
parents:
8487
diff
changeset
|
2309 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
|
2310 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2311 |
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
|
2312 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
|
2313 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2314 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2315 /** |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2316 * 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
|
2317 * @param tile Tile of the house |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2318 * @param t Town owning the house |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2319 * @param house House type |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
2320 */ |
9522
4c8878e06411
(svn r13518) -Fix [FS#2083]: Properly count number of non-north housetiles.
frosch <frosch@openttd.org>
parents:
9505
diff
changeset
|
2321 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
|
2322 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2323 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
|
2324 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
|
2325 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
|
2326 DeleteAnimatedTile(tile); |
15083
68d1f9ea65c3
(svn r19709) -Feature: NewGRF debugging/inspecting of (primarily) enabled callbacks and values of variables
rubidium <rubidium@openttd.org>
parents:
15037
diff
changeset
|
2327 |
68d1f9ea65c3
(svn r19709) -Feature: NewGRF debugging/inspecting of (primarily) enabled callbacks and values of variables
rubidium <rubidium@openttd.org>
parents:
15037
diff
changeset
|
2328 DeleteNewGRFInspectWindow(GSF_HOUSES, 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
|
2329 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2330 |
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
|
2331 /** |
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
|
2332 * 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
|
2333 * 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
|
2334 * |
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
|
2335 * @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
|
2336 * @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
|
2337 */ |
10269
b678a31b4b36
(svn r14504) -Cleanup: Use the right variable type for tile offsets.
michi_cc <michi_cc@openttd.org>
parents:
10260
diff
changeset
|
2338 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
|
2339 { |
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
|
2340 if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks. |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
2341 if (HouseSpec::Get(house - 1)->building_flags & TILE_SIZE_2x1) { |
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
|
2342 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
|
2343 return TileDiffXY(-1, 0); |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
2344 } else if (HouseSpec::Get(house - 1)->building_flags & BUILDING_2_TILES_Y) { |
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
|
2345 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
|
2346 return TileDiffXY(0, -1); |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
2347 } else if (HouseSpec::Get(house - 2)->building_flags & BUILDING_HAS_4_TILES) { |
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
|
2348 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
|
2349 return TileDiffXY(-1, 0); |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
2350 } else if (HouseSpec::Get(house - 3)->building_flags & BUILDING_HAS_4_TILES) { |
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
|
2351 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
|
2352 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
|
2353 } |
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
|
2354 } |
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
|
2355 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
|
2356 } |
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
|
2357 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2358 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
|
2359 { |
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
|
2360 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
|
2361 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
2362 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
|
2363 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2364 /* 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
|
2365 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
|
2366 |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
2367 const HouseSpec *hs = HouseSpec::Get(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
|
2368 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2369 /* 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
|
2370 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
|
2371 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
|
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 |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
2374 t->cache.num_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
|
2375 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2376 /* 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
|
2377 if (hs->building_flags & BUILDING_IS_CHURCH) { |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
2378 ClrBit(t->flags, 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
|
2379 } else if (hs->building_flags & BUILDING_IS_STADIUM) { |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
2380 ClrBit(t->flags, 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
|
2381 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2382 |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2383 /* 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
|
2384 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
|
2385 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
|
2386 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
|
2387 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
|
2388 if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1), t, ++house); |
18560
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
2389 |
488cc0d0b505
(svn r23405) -Codechange: Keep a matrix of cargos accepted by houses for each town (michi_cc).
terkhen <terkhen@openttd.org>
parents:
18511
diff
changeset
|
2390 /* Update cargo acceptance. */ |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
2391 UpdateTownCargoes(t, 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
|
2392 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2393 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
2394 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
2395 * Rename a town (server-only). |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2396 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2397 * @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
|
2398 * @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
|
2399 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13060
diff
changeset
|
2400 * @param text the new name or an empty string when resetting to the default |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13060
diff
changeset
|
2401 * @return the cost of this operation or an 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
|
2402 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
2403 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
|
2404 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11926
diff
changeset
|
2405 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
|
2406 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
|
2407 |
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
|
2408 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
|
2409 |
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
|
2410 if (!reset) { |
16683
50342e8df7e6
(svn r21414) -Codechange: limit town name by amount of characters, not bytes
rubidium <rubidium@openttd.org>
parents:
16681
diff
changeset
|
2411 if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return CMD_ERROR; |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12540
diff
changeset
|
2412 if (!IsUniqueTownName(text)) return_cmd_error(STR_ERROR_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
|
2413 } |
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
|
2414 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2415 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
|
2416 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
|
2417 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
|
2418 |
12391
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
2419 t->UpdateVirtCoord(); |
9387
a240dd49a2e8
(svn r13297) -Codechange: Use GUIList for the town directory window
peter1138 <peter1138@openttd.org>
parents:
9358
diff
changeset
|
2420 InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1); |
12391
b7b1110f6c24
(svn r16821) -Codechange: unify the naming of type::UpdateVirtCoord and UpdateAll[Type]VirtCoords.
rubidium <rubidium@openttd.org>
parents:
12370
diff
changeset
|
2421 UpdateAllStationVirtCoords(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2422 } |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6946
diff
changeset
|
2423 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
|
2424 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2425 |
15657
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2426 /** |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2427 * Determines the first cargo with a certain town effect |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2428 * @param effect Town effect of interest |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2429 * @return first active cargo slot with that effect |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2430 */ |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2431 const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect) |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2432 { |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2433 const CargoSpec *cs; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2434 FOR_ALL_CARGOSPECS(cs) { |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2435 if (cs->town_effect == effect) return cs; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2436 } |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2437 return NULL; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2438 } |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2439 |
18772
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2440 static void UpdateTownGrowRate(Town *t); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2441 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2442 /** |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2443 * Change the cargo goal of a town. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2444 * @param tile Unused. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2445 * @param flags Type of operation. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2446 * @param p1 various bitstuffed elements |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2447 * - p1 = (bit 0 - 15) - Town ID to cargo game of. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2448 * - p1 = (bit 16 - 23) - TownEffect to change the game of. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2449 * @param p2 The new goal value. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2450 * @param text Unused. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2451 * @return Empty cost or an error. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2452 */ |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2453 CommandCost CmdTownCargoGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2454 { |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2455 if (_current_company != OWNER_DEITY) return CMD_ERROR; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2456 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2457 TownEffect te = (TownEffect)GB(p1, 16, 8); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2458 if (te < TE_BEGIN || te > TE_END) return CMD_ERROR; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2459 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2460 uint16 index = GB(p1, 0, 16); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2461 Town *t = Town::GetIfValid(index); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2462 if (t == NULL) return CMD_ERROR; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2463 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2464 /* Validate if there is a cargo which is the requested TownEffect */ |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2465 const CargoSpec *cargo = FindFirstCargoWithTownEffect(te); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2466 if (cargo == NULL) return CMD_ERROR; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2467 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2468 if (flags & DC_EXEC) { |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2469 t->goal[te] = p2; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2470 UpdateTownGrowRate(t); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2471 InvalidateWindowData(WC_TOWN_VIEW, index); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2472 } |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2473 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2474 return CommandCost(); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2475 } |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2476 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2477 /** |
18778
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2478 * Set a custom text in the Town window. |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2479 * @param tile Unused. |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2480 * @param flags Type of operation. |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2481 * @param p1 Town ID to change the text of. |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2482 * @param p2 Unused. |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2483 * @param text The new text (empty to remove the text). |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2484 * @return Empty cost or an error. |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2485 */ |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2486 CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2487 { |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2488 if (_current_company != OWNER_DEITY) return CMD_ERROR; |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2489 Town *t = Town::GetIfValid(p1); |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2490 if (t == NULL) return CMD_ERROR; |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2491 |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2492 if (flags & DC_EXEC) { |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2493 free(t->text); |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2494 t->text = StrEmpty(text) ? NULL : strdup(text); |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2495 InvalidateWindowData(WC_TOWN_VIEW, p1); |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2496 } |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2497 |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2498 return CommandCost(); |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2499 } |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2500 |
153e9c1e0d36
(svn r23626) -Add: ScriptTown::SetText, which adds custom text to the Town GUI
truebrain <truebrain@openttd.org>
parents:
18774
diff
changeset
|
2501 /** |
18772
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2502 * Change the growth rate of the town. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2503 * @param tile Unused. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2504 * @param flags Type of operation. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2505 * @param p1 Town ID to cargo game of. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2506 * @param p2 Amount of days between growth. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2507 * @param text Unused. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2508 * @return Empty cost or an error. |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2509 */ |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2510 CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2511 { |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2512 if (_current_company != OWNER_DEITY) return CMD_ERROR; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2513 if ((p2 & TOWN_GROW_RATE_CUSTOM) != 0) return CMD_ERROR; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2514 if (GB(p2, 16, 16) != 0) return CMD_ERROR; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2515 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2516 Town *t = Town::GetIfValid(p1); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2517 if (t == NULL) return CMD_ERROR; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2518 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2519 if (flags & DC_EXEC) { |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2520 t->growth_rate = (p2 == 0) ? 0 : p2 | TOWN_GROW_RATE_CUSTOM; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2521 UpdateTownGrowRate(t); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2522 InvalidateWindowData(WC_TOWN_VIEW, p1); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2523 } |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2524 |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2525 return CommandCost(); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2526 } |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
2527 |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2528 /** |
15657
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2529 * Expand a town (scenario editor only). |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2530 * @param tile Unused. |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2531 * @param flags Type of operation. |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2532 * @param p1 Town ID to expand. |
18769
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2533 * @param p2 Amount to grow, or 0 to grow a random size up to the current amount of houses. |
15657
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2534 * @param text Unused. |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2535 * @return Empty cost or an error. |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2536 */ |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2537 CommandCost CmdExpandTown(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
|
2538 { |
18769
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2539 if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY) return CMD_ERROR; |
15657
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2540 Town *t = Town::GetIfValid(p1); |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2541 if (t == NULL) return CMD_ERROR; |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2542 |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2543 if (flags & DC_EXEC) { |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2544 /* The more houses, the faster we grow */ |
18769
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2545 if (p2 == 0) { |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
2546 uint amount = RandomRange(ClampToU16(t->cache.num_houses / 10)) + 3; |
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
2547 t->cache.num_houses += amount; |
18769
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2548 UpdateTownRadius(t); |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2549 |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2550 uint n = amount * 10; |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2551 do GrowTown(t); while (--n); |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2552 |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
2553 t->cache.num_houses -= amount; |
18769
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2554 } else { |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2555 for (; p2 > 0; p2--) { |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2556 /* Try several times to grow, as we are really suppose to grow */ |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2557 for (uint i = 0; i < 25; i++) if (GrowTown(t)) break; |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2558 } |
7af05225a1dc
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
2559 } |
15657
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2560 UpdateTownRadius(t); |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2561 |
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2562 UpdateTownMaxPass(t); |
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
|
2563 } |
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 |
15657
ddfeab1a0a88
(svn r20322) -Codechange: Move Expand town code to a command.
terkhen <terkhen@openttd.org>
parents:
15655
diff
changeset
|
2565 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
|
2566 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2567 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
2568 /** |
18964
a5926c47032d
(svn r23819) -Fix [FS#4951]: Removal of towns with 0 population failed during map generation.
frosch <frosch@openttd.org>
parents:
18891
diff
changeset
|
2569 * Delete a town (scenario editor or worldgen only). |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2570 * @param tile Unused. |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2571 * @param flags Type of operation. |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2572 * @param p1 Town ID to delete. |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2573 * @param p2 Unused. |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2574 * @param text Unused. |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2575 * @return Empty cost or an error. |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2576 */ |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2577 CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2578 { |
18964
a5926c47032d
(svn r23819) -Fix [FS#4951]: Removal of towns with 0 population failed during map generation.
frosch <frosch@openttd.org>
parents:
18891
diff
changeset
|
2579 if (_game_mode != GM_EDITOR && !_generating_world) return CMD_ERROR; |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2580 Town *t = Town::GetIfValid(p1); |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2581 if (t == NULL) return CMD_ERROR; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2582 |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2583 /* Stations refer to towns. */ |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2584 const Station *st; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2585 FOR_ALL_STATIONS(st) { |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2586 if (st->town == t) { |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2587 /* Non-oil rig stations are always a problem. */ |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2588 if (!(st->facilities & FACIL_AIRPORT) || st->airport.type != AT_OILRIG) return CMD_ERROR; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2589 /* We can only automatically delete oil rigs *if* there's no vehicle on them. */ |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2590 CommandCost ret = DoCommand(st->airport.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2591 if (ret.Failed()) return ret; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2592 } |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2593 } |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2594 |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2595 /* Depots refer to towns. */ |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2596 const Depot *d; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2597 FOR_ALL_DEPOTS(d) { |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2598 if (d->town == t) return CMD_ERROR; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2599 } |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2600 |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2601 /* Check all tiles for town ownership. */ |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2602 for (TileIndex tile = 0; tile < MapSize(); ++tile) { |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2603 bool try_clear = false; |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2604 switch (GetTileType(tile)) { |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2605 case MP_ROAD: |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2606 try_clear = HasTownOwnedRoad(tile) && GetTownIndex(tile) == t->index; |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2607 break; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2608 |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2609 case MP_TUNNELBRIDGE: |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2610 try_clear = IsTileOwner(tile, OWNER_TOWN) && ClosestTownFromTile(tile, UINT_MAX) == t; |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2611 break; |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2612 |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2613 case MP_HOUSE: |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2614 try_clear = GetTownIndex(tile) == t->index; |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2615 break; |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2616 |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2617 case MP_INDUSTRY: |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2618 try_clear = Industry::GetByTile(tile)->town == t; |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2619 break; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2620 |
15806
61ffff09a0a3
(svn r20481) -Fix: statues were not removed when towns would be removed
rubidium <rubidium@openttd.org>
parents:
15805
diff
changeset
|
2621 case MP_OBJECT: |
15807
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2622 if (Town::GetNumItems() == 1) { |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2623 /* No towns will be left, remove it! */ |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2624 try_clear = true; |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2625 } else { |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2626 Object *o = Object::GetByTile(tile); |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2627 if (o->town == t) { |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2628 if (GetObjectType(tile) == OBJECT_STATUE) { |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2629 /* Statue... always remove. */ |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2630 try_clear = true; |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2631 } else { |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2632 /* Tell to find a new town. */ |
17346
ab5a371a90dc
(svn r22087) -Fix: When deleting towns, only relocate objects during DC_EXEC.
terkhen <terkhen@openttd.org>
parents:
17326
diff
changeset
|
2633 if (flags & DC_EXEC) o->town = NULL; |
15807
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2634 } |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2635 } |
9561d91e0869
(svn r20482) -Codechange: move some object related information off the map and unify the relation objects have to towns
rubidium <rubidium@openttd.org>
parents:
15806
diff
changeset
|
2636 } |
15806
61ffff09a0a3
(svn r20481) -Fix: statues were not removed when towns would be removed
rubidium <rubidium@openttd.org>
parents:
15805
diff
changeset
|
2637 break; |
61ffff09a0a3
(svn r20481) -Fix: statues were not removed when towns would be removed
rubidium <rubidium@openttd.org>
parents:
15805
diff
changeset
|
2638 |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2639 default: |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2640 break; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2641 } |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2642 if (try_clear) { |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2643 CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2644 if (ret.Failed()) return ret; |
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2645 } |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2646 } |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2647 |
15805
81bab3f950ca
(svn r20480) -Codechange: make CmdDeleteTown responsible for actually clearing tiles and such; ~Town still checks it though.
rubidium <rubidium@openttd.org>
parents:
15798
diff
changeset
|
2648 /* The town destructor will delete the other things related to the town. */ |
15658
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2649 if (flags & DC_EXEC) delete t; |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2650 |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2651 return CommandCost(); |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2652 } |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2653 |
52010e085f5e
(svn r20323) -Codechange: Move Delete town code to a command.
terkhen <terkhen@openttd.org>
parents:
15657
diff
changeset
|
2654 /** |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
2655 * Factor in the cost of each town action. |
13082
9b6f556571eb
(svn r17582) -Codechange: Move TownActions and _town_action_costs[] to a header file to allow sharing.
alberth <alberth@openttd.org>
parents:
13079
diff
changeset
|
2656 * @see TownActions |
9b6f556571eb
(svn r17582) -Codechange: Move TownActions and _town_action_costs[] to a header file to allow sharing.
alberth <alberth@openttd.org>
parents:
13079
diff
changeset
|
2657 */ |
9b6f556571eb
(svn r17582) -Codechange: Move TownActions and _town_action_costs[] to a header file to allow sharing.
alberth <alberth@openttd.org>
parents:
13079
diff
changeset
|
2658 const byte _town_action_costs[TACT_COUNT] = { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2659 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
|
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 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2662 static CommandCost TownActionAdvertiseSmall(Town *t, 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
|
2663 { |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2664 if (flags & DC_EXEC) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2665 ModifyStationRatingAround(t->xy, _current_company, 0x40, 10); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2666 } |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2667 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
|
2668 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2669 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2670 static CommandCost TownActionAdvertiseMedium(Town *t, 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
|
2671 { |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2672 if (flags & DC_EXEC) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2673 ModifyStationRatingAround(t->xy, _current_company, 0x70, 15); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2674 } |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2675 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
|
2676 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2677 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2678 static CommandCost TownActionAdvertiseLarge(Town *t, 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
|
2679 { |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2680 if (flags & DC_EXEC) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2681 ModifyStationRatingAround(t->xy, _current_company, 0xA0, 20); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2682 } |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2683 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
|
2684 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2685 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2686 static CommandCost TownActionRoadRebuild(Town *t, 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
|
2687 { |
17234
08d6a07fe4ce
(svn r21974) -Feature: Add a setting to enable/disable funding local road reconstruction.
terkhen <terkhen@openttd.org>
parents:
17108
diff
changeset
|
2688 /* Check if the company is allowed to fund new roads. */ |
08d6a07fe4ce
(svn r21974) -Feature: Add a setting to enable/disable funding local road reconstruction.
terkhen <terkhen@openttd.org>
parents:
17108
diff
changeset
|
2689 if (!_settings_game.economy.fund_roads) return CMD_ERROR; |
08d6a07fe4ce
(svn r21974) -Feature: Add a setting to enable/disable funding local road reconstruction.
terkhen <terkhen@openttd.org>
parents:
17108
diff
changeset
|
2690 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2691 if (flags & DC_EXEC) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2692 t->road_build_months = 6; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2693 |
16681
3a1ac9bae6cc
(svn r21412) -Codechange: limit company name by amount of characters, not bytes
rubidium <rubidium@openttd.org>
parents:
16563
diff
changeset
|
2694 char company_name[MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH]; |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2695 SetDParam(0, _current_company); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2696 GetString(company_name, STR_COMPANY_NAME, lastof(company_name)); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2697 |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2698 char *cn = strdup(company_name); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2699 SetDParam(0, t->index); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2700 SetDParamStr(1, cn); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2701 |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2702 AddNewsItem(STR_NEWS_ROAD_REBUILDING, NS_GENERAL, NR_TOWN, t->index, NR_NONE, UINT32_MAX, cn); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2703 } |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2704 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
|
2705 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2706 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2707 /** |
19217
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2708 * Check whether the land can be cleared. |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2709 * @param tile Tile to check. |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2710 * @return The tile can be cleared. |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2711 */ |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2712 static bool TryClearTile(TileIndex tile) |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2713 { |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2714 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE); |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2715 CommandCost r = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR); |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2716 cur_company.Restore(); |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2717 return r.Succeeded(); |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2718 } |
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2719 |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2720 /** Structure for storing data while searching the best place to build a statue. */ |
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2721 struct StatueBuildSearchData { |
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2722 TileIndex best_position; ///< Best position found so far. |
19220
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2723 int tile_count; ///< Number of tiles tried. |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2724 |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2725 StatueBuildSearchData(TileIndex best_pos, int count) : best_position(best_pos), tile_count(count) { } |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2726 }; |
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2727 |
19217
f379f2281802
(svn r24102) -Codechange: Refactor tile clearability test out of the statue callback.
alberth <alberth@openttd.org>
parents:
19216
diff
changeset
|
2728 /** |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2729 * Search callback function for #TownActionBuildStatue. |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2730 * @param tile Tile on which to perform the search. |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2731 * @param user_data Reference to the statue search data. |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2732 * @return Result of the test. |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2733 */ |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2734 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
|
2735 { |
19220
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2736 static const int STATUE_NUMBER_INNER_TILES = 25; // Number of tiles int the center of the city, where we try to protect houses. |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2737 |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2738 StatueBuildSearchData *statue_data = (StatueBuildSearchData *)user_data; |
19220
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2739 statue_data->tile_count++; |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2740 |
7549
b202efd99ae5
(svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium <rubidium@openttd.org>
parents:
7545
diff
changeset
|
2741 /* Statues can be build on slopes, just like houses. Only the steep slopes is a no go. */ |
18257
b6026cba5dae
(svn r23093) -Codechange: add a default NULL for the Z of GetTileSlope and use it
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
2742 if (IsSteepSlope(GetTileSlope(tile))) 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
|
2743 /* 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
|
2744 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
|
2745 |
19218
e75b33bd86b4
(svn r24103) -Codechange: Handle clear tiles separately from house tiles.
alberth <alberth@openttd.org>
parents:
19217
diff
changeset
|
2746 /* A clear-able open space is always preferred. */ |
e75b33bd86b4
(svn r24103) -Codechange: Handle clear tiles separately from house tiles.
alberth <alberth@openttd.org>
parents:
19217
diff
changeset
|
2747 if ((IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) && TryClearTile(tile)) { |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2748 statue_data->best_position = tile; |
19218
e75b33bd86b4
(svn r24103) -Codechange: Handle clear tiles separately from house tiles.
alberth <alberth@openttd.org>
parents:
19217
diff
changeset
|
2749 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
|
2750 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2751 |
19218
e75b33bd86b4
(svn r24103) -Codechange: Handle clear tiles separately from house tiles.
alberth <alberth@openttd.org>
parents:
19217
diff
changeset
|
2752 bool house = IsTileType(tile, MP_HOUSE); |
e75b33bd86b4
(svn r24103) -Codechange: Handle clear tiles separately from house tiles.
alberth <alberth@openttd.org>
parents:
19217
diff
changeset
|
2753 |
19220
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2754 /* Searching inside the inner circle. */ |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2755 if (statue_data->tile_count <= STATUE_NUMBER_INNER_TILES) { |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2756 /* Save first house in inner circle. */ |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2757 if (house && statue_data->best_position == INVALID_TILE && TryClearTile(tile)) { |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2758 statue_data->best_position = tile; |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2759 } |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2760 |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2761 /* If we have reached the end of the inner circle, and have a saved house, terminate the search. */ |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2762 return statue_data->tile_count == STATUE_NUMBER_INNER_TILES && statue_data->best_position != INVALID_TILE; |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2763 } |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2764 |
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2765 /* Searching outside the circle, just pick the first possible spot. */ |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2766 statue_data->best_position = tile; // Is optimistic, the condition below must also hold. |
19218
e75b33bd86b4
(svn r24103) -Codechange: Handle clear tiles separately from house tiles.
alberth <alberth@openttd.org>
parents:
19217
diff
changeset
|
2767 return house && TryClearTile(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
|
2768 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2769 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2770 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2771 * 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
|
2772 * 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
|
2773 * @param t town to search in |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2774 * @param flags Used to check if the statue must be built or not. |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2775 * @return Empty cost or an 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
|
2776 */ |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2777 static CommandCost TownActionBuildStatue(Town *t, 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
|
2778 { |
17326
ed4333ee5e4b
(svn r22066) -Fix [FS#4502]: building a statue did not check whether the object pool is full
rubidium <rubidium@openttd.org>
parents:
17325
diff
changeset
|
2779 if (!Object::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_OBJECTS); |
ed4333ee5e4b
(svn r22066) -Fix [FS#4502]: building a statue did not check whether the object pool is full
rubidium <rubidium@openttd.org>
parents:
17325
diff
changeset
|
2780 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2781 TileIndex tile = t->xy; |
19220
87d0ea2d8725
(svn r24105) -Feature: Be more careful with the population of a small town while placing a statue.
alberth <alberth@openttd.org>
parents:
19219
diff
changeset
|
2782 StatueBuildSearchData statue_data(INVALID_TILE, 0); |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2783 if (!CircularTileSearch(&tile, 9, SearchTileForStatue, &statue_data)) return_cmd_error(STR_ERROR_STATUE_NO_SUITABLE_PLACE); |
19216
4b152b00ba27
(svn r24101) -Codechange: Reverse a condition for increased readability.
alberth <alberth@openttd.org>
parents:
19190
diff
changeset
|
2784 |
4b152b00ba27
(svn r24101) -Codechange: Reverse a condition for increased readability.
alberth <alberth@openttd.org>
parents:
19190
diff
changeset
|
2785 if (flags & DC_EXEC) { |
4b152b00ba27
(svn r24101) -Codechange: Reverse a condition for increased readability.
alberth <alberth@openttd.org>
parents:
19190
diff
changeset
|
2786 Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE); |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2787 DoCommand(statue_data.best_position, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
19216
4b152b00ba27
(svn r24101) -Codechange: Reverse a condition for increased readability.
alberth <alberth@openttd.org>
parents:
19190
diff
changeset
|
2788 cur_company.Restore(); |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2789 BuildObject(OBJECT_STATUE, statue_data.best_position, _current_company, t); |
19216
4b152b00ba27
(svn r24101) -Codechange: Reverse a condition for increased readability.
alberth <alberth@openttd.org>
parents:
19190
diff
changeset
|
2790 SetBit(t->statues, _current_company); // Once found and built, "inform" the Town. |
19219
b5a91589a5ae
(svn r24104) -Codechange: Output the resulting tile through the user data.
alberth <alberth@openttd.org>
parents:
19218
diff
changeset
|
2791 MarkTileDirtyByTile(statue_data.best_position); |
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
|
2792 } |
19216
4b152b00ba27
(svn r24101) -Codechange: Reverse a condition for increased readability.
alberth <alberth@openttd.org>
parents:
19190
diff
changeset
|
2793 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
|
2794 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2795 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2796 static CommandCost TownActionFundBuildings(Town *t, 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
|
2797 { |
18459
610fb049192c
(svn r23303) -Add: economy.fund_buildings, to disallow funding buildings
truebrain <truebrain@openttd.org>
parents:
18456
diff
changeset
|
2798 /* Check if it's allowed to buy the rights */ |
610fb049192c
(svn r23303) -Add: economy.fund_buildings, to disallow funding buildings
truebrain <truebrain@openttd.org>
parents:
18456
diff
changeset
|
2799 if (!_settings_game.economy.fund_buildings) return CMD_ERROR; |
610fb049192c
(svn r23303) -Add: economy.fund_buildings, to disallow funding buildings
truebrain <truebrain@openttd.org>
parents:
18456
diff
changeset
|
2800 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2801 if (flags & DC_EXEC) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2802 /* Build next tick */ |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2803 t->grow_counter = 1; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2804 /* If we were not already growing */ |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2805 SetBit(t->flags, TOWN_IS_FUNDED); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2806 /* And grow for 3 months */ |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2807 t->fund_buildings_months = 3; |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2808 |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2809 SetWindowDirty(WC_TOWN_VIEW, t->index); |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2810 } |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2811 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
|
2812 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2813 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2814 static CommandCost TownActionBuyRights(Town *t, 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
|
2815 { |
15604
ca959eb5d431
(svn r20266) -Doc: Mostly typo fixes, a few doxygen-related improvements.
alberth <alberth@openttd.org>
parents:
15567
diff
changeset
|
2816 /* Check if it's allowed to buy the rights */ |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2817 if (!_settings_game.economy.exclusive_rights) return CMD_ERROR; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2818 |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2819 if (flags & DC_EXEC) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2820 t->exclusive_counter = 12; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2821 t->exclusivity = _current_company; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2822 |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2823 ModifyStationRatingAround(t->xy, _current_company, 130, 17); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2824 } |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2825 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
|
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 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2828 static CommandCost TownActionBribe(Town *t, 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
|
2829 { |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2830 if (flags & DC_EXEC) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2831 if (Chance16(1, 14)) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2832 /* set as unwanted for 6 months */ |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2833 t->unwanted[_current_company] = 6; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2834 |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2835 /* set all close by station ratings to 0 */ |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2836 Station *st; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2837 FOR_ALL_STATIONS(st) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2838 if (st->town == t && st->owner == _current_company) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2839 for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2840 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2841 } |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2842 |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2843 /* only show errormessage to the executing player. All errors are handled command.c |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2844 * but this is special, because it can only 'fail' on a DC_EXEC */ |
18347
fdc15051da1c
(svn r23183) -Codechange: merge BRIBE_FAILED and BRIBE_FAILED_2 messages (monoid)
rubidium <rubidium@openttd.org>
parents:
18324
diff
changeset
|
2845 if (IsLocalCompany()) ShowErrorMessage(STR_ERROR_BRIBE_FAILED, INVALID_STRING_ID, WL_INFO); |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2846 |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2847 /* decrease by a lot! |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2848 * ChangeTownRating is only for stuff in demolishing. Bribe failure should |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2849 * be independent of any cheat settings |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2850 */ |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2851 if (t->ratings[_current_company] > RATING_BRIBE_DOWN_TO) { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2852 t->ratings[_current_company] = RATING_BRIBE_DOWN_TO; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2853 SetWindowDirty(WC_TOWN_AUTHORITY, t->index); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2854 } |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2855 } else { |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2856 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
|
2857 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2858 } |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2859 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
|
2860 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2861 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2862 typedef CommandCost TownActionProc(Town *t, DoCommandFlag flags); |
11376
b9b2391afd1a
(svn r15726) -Codechange: unify coding style for const pointers
smatz <smatz@openttd.org>
parents:
11368
diff
changeset
|
2863 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
|
2864 TownActionAdvertiseSmall, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2865 TownActionAdvertiseMedium, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2866 TownActionAdvertiseLarge, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2867 TownActionRoadRebuild, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2868 TownActionBuildStatue, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2869 TownActionFundBuildings, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2870 TownActionBuyRights, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2871 TownActionBribe |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2872 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2873 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
2874 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
2875 * Get a list of available actions to do at a town. |
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
|
2876 * @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
|
2877 * @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
|
2878 * @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
|
2879 * @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
|
2880 */ |
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
|
2881 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
|
2882 { |
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
|
2883 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
|
2884 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
|
2885 |
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
|
2886 /* 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
|
2887 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
|
2888 |
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
|
2889 /* Things worth more than this are not shown */ |
13486
f2535c5098a0
(svn r18005) -Codechange: Convert the Prices struct into an array and an enum.
frosch <frosch@openttd.org>
parents:
13419
diff
changeset
|
2890 Money avail = Company::Get(cid)->money + _price[PR_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
|
2891 |
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
|
2892 /* 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
|
2893 * 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
|
2894 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
|
2895 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
|
2896 |
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
|
2897 /* Is the company not able to bribe ? */ |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
2898 if (cur == TACT_BRIBE && (!_settings_game.economy.bribe || t->ratings[cid] >= RATING_BRIBE_MAXIMUM)) continue; |
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
|
2899 |
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
|
2900 /* Is the company not able to buy exclusive rights ? */ |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
2901 if (cur == TACT_BUY_RIGHTS && !_settings_game.economy.exclusive_rights) continue; |
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
|
2902 |
18459
610fb049192c
(svn r23303) -Add: economy.fund_buildings, to disallow funding buildings
truebrain <truebrain@openttd.org>
parents:
18456
diff
changeset
|
2903 /* Is the company not able to fund buildings ? */ |
610fb049192c
(svn r23303) -Add: economy.fund_buildings, to disallow funding buildings
truebrain <truebrain@openttd.org>
parents:
18456
diff
changeset
|
2904 if (cur == TACT_FUND_BUILDINGS && !_settings_game.economy.fund_buildings) continue; |
610fb049192c
(svn r23303) -Add: economy.fund_buildings, to disallow funding buildings
truebrain <truebrain@openttd.org>
parents:
18456
diff
changeset
|
2905 |
17234
08d6a07fe4ce
(svn r21974) -Feature: Add a setting to enable/disable funding local road reconstruction.
terkhen <terkhen@openttd.org>
parents:
17108
diff
changeset
|
2906 /* Is the company not able to fund local road reconstruction? */ |
08d6a07fe4ce
(svn r21974) -Feature: Add a setting to enable/disable funding local road reconstruction.
terkhen <terkhen@openttd.org>
parents:
17108
diff
changeset
|
2907 if (cur == TACT_ROAD_REBUILD && !_settings_game.economy.fund_roads) continue; |
08d6a07fe4ce
(svn r21974) -Feature: Add a setting to enable/disable funding local road reconstruction.
terkhen <terkhen@openttd.org>
parents:
17108
diff
changeset
|
2908 |
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
|
2909 /* Is the company not able to build a statue ? */ |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
2910 if (cur == TACT_BUILD_STATUE && HasBit(t->statues, cid)) continue; |
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
|
2911 |
13758
9a5050ee2cec
(svn r18283) -Feature: [NewGRF] Add new price bases for removing industries, building/removing unmovables (new objects), building/removing rail-waypoints/buoys, interacting with town-authority, building foundations, funding primary industries (when not prospecting) and towns.
frosch <frosch@openttd.org>
parents:
13756
diff
changeset
|
2912 if (avail >= _town_action_costs[i] * _price[PR_TOWN_ACTION] >> 8) { |
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
|
2913 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
|
2914 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
|
2915 } |
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
|
2916 } |
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
|
2917 } |
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
|
2918 |
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
|
2919 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
|
2920 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
|
2921 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2922 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
2923 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
2924 * Do a town action. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2925 * 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
|
2926 * 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
|
2927 * @param tile unused |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
2928 * @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
|
2929 * @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
|
2930 * @param p2 action to perform, @see _town_action_proc for the list of available actions |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13060
diff
changeset
|
2931 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13060
diff
changeset
|
2932 * @return the cost of this operation or an 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
|
2933 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11057
diff
changeset
|
2934 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
|
2935 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11926
diff
changeset
|
2936 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
|
2937 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
|
2938 |
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
|
2939 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
|
2940 |
13758
9a5050ee2cec
(svn r18283) -Feature: [NewGRF] Add new price bases for removing industries, building/removing unmovables (new objects), building/removing rail-waypoints/buoys, interacting with town-authority, building foundations, funding primary industries (when not prospecting) and towns.
frosch <frosch@openttd.org>
parents:
13756
diff
changeset
|
2941 CommandCost cost(EXPENSES_OTHER, _price[PR_TOWN_ACTION] * _town_action_costs[p2] >> 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
|
2942 |
15567
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2943 CommandCost ret = _town_action_proc[p2](t, flags); |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2944 if (ret.Failed()) return ret; |
328ec017c726
(svn r20227) -Fix [FS#3985]: Don't spend cash when building a statue fails.
terkhen <terkhen@openttd.org>
parents:
15552
diff
changeset
|
2945 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2946 if (flags & DC_EXEC) { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12999
diff
changeset
|
2947 SetWindowDirty(WC_TOWN_AUTHORITY, p1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2948 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2949 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2950 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
|
2951 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2952 |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2953 static void UpdateTownRating(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
|
2954 { |
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
|
2955 /* 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
|
2956 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
|
2957 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
|
2958 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
|
2959 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
|
2960 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2961 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2962 |
8816
d278baac2725
(svn r12562) -Cleanup: variable scope in terraform_cmd.cpp
smatz <smatz@openttd.org>
parents:
8815
diff
changeset
|
2963 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
|
2964 FOR_ALL_STATIONS(st) { |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
2965 if (DistanceSquare(st->xy, t->xy) <= t->cache.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
|
2966 if (st->time_since_load <= 20 || st->time_since_unload <= 20) { |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
2967 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
|
2968 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
|
2969 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
|
2970 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2971 } else { |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
2972 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
|
2973 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
|
2974 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
|
2975 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2976 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2977 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2978 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2979 |
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
|
2980 /* 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
|
2981 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
|
2982 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
|
2983 } |
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
|
2984 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12999
diff
changeset
|
2985 SetWindowDirty(WC_TOWN_AUTHORITY, t->index); |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2986 } |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2987 |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2988 static void UpdateTownGrowRate(Town *t) |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2989 { |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
2990 ClrBit(t->flags, TOWN_IS_FUNDED); |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2991 SetWindowDirty(WC_TOWN_VIEW, t->index); |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
2992 |
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
|
2993 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
|
2994 |
18479
4e8ed32f0d38
(svn r23323) -Fix: when you fund a town, it should grow; goals reached or not
truebrain <truebrain@openttd.org>
parents:
18475
diff
changeset
|
2995 if (t->fund_buildings_months == 0) { |
4e8ed32f0d38
(svn r23323) -Fix: when you fund a town, it should grow; goals reached or not
truebrain <truebrain@openttd.org>
parents:
18475
diff
changeset
|
2996 /* Check if all goals are reached for this town to grow (given we are not funding it) */ |
4e8ed32f0d38
(svn r23323) -Fix: when you fund a town, it should grow; goals reached or not
truebrain <truebrain@openttd.org>
parents:
18475
diff
changeset
|
2997 for (int i = TE_BEGIN; i < TE_END; i++) { |
18498
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
2998 switch (t->goal[i]) { |
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
2999 case TOWN_GROWTH_WINTER: |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
3000 if (TileHeight(t->xy) >= GetSnowLine() && t->received[i].old_act == 0 && t->cache.population > 90) return; |
18498
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
3001 break; |
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
3002 case TOWN_GROWTH_DESERT: |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
3003 if (GetTropicZone(t->xy) == TROPICZONE_DESERT && t->received[i].old_act == 0 && t->cache.population > 60) return; |
18498
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
3004 break; |
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
3005 default: |
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
3006 if (t->goal[i] > t->received[i].old_act) return; |
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
3007 break; |
8971d7064cbe
(svn r23342) -Fix (r23300): for arctic and desert towns you were required to deliver more than 4 billion units, instead of one or more units
rubidium <rubidium@openttd.org>
parents:
18479
diff
changeset
|
3008 } |
18479
4e8ed32f0d38
(svn r23323) -Fix: when you fund a town, it should grow; goals reached or not
truebrain <truebrain@openttd.org>
parents:
18475
diff
changeset
|
3009 } |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3010 } |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3011 |
18772
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
3012 if ((t->growth_rate & TOWN_GROW_RATE_CUSTOM) != 0) { |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
3013 SetBit(t->flags, TOWN_IS_FUNDED); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
3014 SetWindowDirty(WC_TOWN_VIEW, t->index); |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
3015 return; |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
3016 } |
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
3017 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
3018 /** |
17702
bcd20b97e0ee
(svn r22482) -Codechange: Add some contants for the number of ticks between certain cyclical tasks.
frosch <frosch@openttd.org>
parents:
17684
diff
changeset
|
3019 * Towns are processed every TOWN_GROWTH_TICKS ticks, and this is the |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
3020 * number of times towns are processed before a new building is built. |
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
3021 */ |
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
|
3022 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
|
3023 { 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
|
3024 { 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
|
3025 }; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3026 |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3027 int n = 0; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3028 |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3029 const Station *st; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3030 FOR_ALL_STATIONS(st) { |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
3031 if (DistanceSquare(st->xy, t->xy) <= t->cache.squared_town_zone_radius[0]) { |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3032 if (st->time_since_load <= 20 || st->time_since_unload <= 20) { |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3033 n++; |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3034 } |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3035 } |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3036 } |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3037 |
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
|
3038 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
|
3039 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3040 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
|
3041 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
|
3042 } 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
|
3043 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
|
3044 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
|
3045 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3046 |
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
|
3047 /* 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
|
3048 * 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
|
3049 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
|
3050 |
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
|
3051 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
|
3052 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
|
3053 |
19290
68bfe04ccd9a
(svn r24179) -Codechange: move some variables of Town to TownCache
rubidium <rubidium@openttd.org>
parents:
19220
diff
changeset
|
3054 t->growth_rate = m / (t->cache.num_houses / 50 + 1); |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
3055 if (m <= t->grow_counter) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3056 t->grow_counter = m; |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
3057 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3058 |
12218
6139eceff57c
(svn r16632) -Codechange: rename Town::flags12 to Town::flags
smatz <smatz@openttd.org>
parents:
12089
diff
changeset
|
3059 SetBit(t->flags, TOWN_IS_FUNDED); |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3060 SetWindowDirty(WC_TOWN_VIEW, 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
|
3061 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3062 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3063 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
|
3064 { |
18454
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
3065 for (CargoID i = 0; i < NUM_CARGO; i++) t->supplied[i].NewMonth(); |
b9e554b1d8a1
(svn r23298) -Add: track statistics of all incoming and outgoing goods. Incoming based on TownEffect, outgoing based on CargoType (based on patch by Terkhen)
truebrain <truebrain@openttd.org>
parents:
18397
diff
changeset
|
3066 for (int i = TE_BEGIN; i < TE_END; i++) t->received[i].NewMonth(); |
18772
ac0ceb4bc5f0
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
truebrain <truebrain@openttd.org>
parents:
18769
diff
changeset
|
3067 if (t->fund_buildings_months != 0) t->fund_buildings_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
|
3068 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12999
diff
changeset
|
3069 SetWindowDirty(WC_TOWN_VIEW, 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
|
3070 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3071 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3072 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
|
3073 { |
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
|
3074 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
|
3075 |
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
|
3076 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
|
3077 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
|
3078 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3079 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3080 |
10681
b232483d773c
(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.
frosch <frosch@openttd.org>
parents:
10656
diff
changeset
|
3081 /** |
b232483d773c
(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.
frosch <frosch@openttd.org>
parents:
10656
diff
changeset
|
3082 * 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
|
3083 * @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
|
3084 * @param flags Command flags. DC_NO_TEST_TOWN_RATING is tested. |
14696
d10e739d1e4c
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
alberth <alberth@openttd.org>
parents:
14690
diff
changeset
|
3085 * @return Succeeded or failed command. |
10681
b232483d773c
(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.
frosch <frosch@openttd.org>
parents:
10656
diff
changeset
|
3086 */ |
14696
d10e739d1e4c
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
alberth <alberth@openttd.org>
parents:
14690
diff
changeset
|
3087 CommandCost 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
|
3088 { |
14696
d10e739d1e4c
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
alberth <alberth@openttd.org>
parents:
14690
diff
changeset
|
3089 if (!Company::IsValidID(_current_company) || (flags & DC_NO_TEST_TOWN_RATING)) 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
|
3090 |
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
|
3091 Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); |
14696
d10e739d1e4c
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
alberth <alberth@openttd.org>
parents:
14690
diff
changeset
|
3092 if (t == NULL) return CommandCost(); |
d10e739d1e4c
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
alberth <alberth@openttd.org>
parents:
14690
diff
changeset
|
3093 |
d10e739d1e4c
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
alberth <alberth@openttd.org>
parents:
14690
diff
changeset
|
3094 if (t->ratings[_current_company] > RATING_VERYPOOR) return CommandCost(); |
d10e739d1e4c
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
alberth <alberth@openttd.org>
parents:
14690
diff
changeset
|
3095 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3096 SetDParam(0, t->index); |
14696
d10e739d1e4c
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
alberth <alberth@openttd.org>
parents:
14690
diff
changeset
|
3097 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
|
3098 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3099 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
3100 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15616
diff
changeset
|
3101 * Return the town closest to the given tile within \a threshold. |
14886
3128bb512766
(svn r19482) -Doc: Doxygen additions/updates.
alberth <alberth@openttd.org>
parents:
14883
diff
changeset
|
3102 * @param tile Starting point of the search. |
3128bb512766
(svn r19482) -Doc: Doxygen additions/updates.
alberth <alberth@openttd.org>
parents:
14883
diff
changeset
|
3103 * @param threshold Biggest allowed distance to the town. |
15616
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3104 * @return Closest town to \a tile within \a threshold, or \c NULL if there is no such town. |
14886
3128bb512766
(svn r19482) -Doc: Doxygen additions/updates.
alberth <alberth@openttd.org>
parents:
14883
diff
changeset
|
3105 * |
3128bb512766
(svn r19482) -Doc: Doxygen additions/updates.
alberth <alberth@openttd.org>
parents:
14883
diff
changeset
|
3106 * @note This function only uses distance, the #ClosestTownFromTile function also takes town ownership into account. |
3128bb512766
(svn r19482) -Doc: Doxygen additions/updates.
alberth <alberth@openttd.org>
parents:
14883
diff
changeset
|
3107 */ |
12326
c926b98c339d
(svn r16746) -Codechange: use Town::PostDestructor() instead of not very clean construct for invalidating nearest town for road tiles
smatz <smatz@openttd.org>
parents:
12297
diff
changeset
|
3108 Town *CalcClosestTownFromTile(TileIndex tile, uint 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
|
3109 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3110 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
|
3111 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
|
3112 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
|
3113 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3114 FOR_ALL_TOWNS(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
|
3115 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
|
3116 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
|
3117 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
|
3118 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
|
3119 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3120 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3121 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3122 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
|
3123 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3124 |
15616
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3125 /** |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3126 * Return the town closest (in distance or ownership) to a given tile, within a given threshold. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3127 * @param tile Starting point of the search. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3128 * @param threshold Biggest allowed distance to the town. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3129 * @return Closest town to \a tile within \a threshold, or \c NULL if there is no such town. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3130 * |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3131 * @note If you only care about distance, you can use the #CalcClosestTownFromTile function. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3132 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3133 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
|
3134 { |
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
|
3135 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
|
3136 case MP_ROAD: |
12999
07a634b14de8
(svn r17493) -Codechange: store the depot index on the map
rubidium <rubidium@openttd.org>
parents:
12951
diff
changeset
|
3137 if (IsRoadDepot(tile)) return CalcClosestTownFromTile(tile, threshold); |
07a634b14de8
(svn r17493) -Codechange: store the depot index on the map
rubidium <rubidium@openttd.org>
parents:
12951
diff
changeset
|
3138 |
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
|
3139 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
|
3140 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
|
3141 |
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
|
3142 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
|
3143 /* 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
|
3144 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
|
3145 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
|
3146 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
|
3147 } |
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
|
3148 |
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
|
3149 assert(Town::IsValidID(tid)); |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11908
diff
changeset
|
3150 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
|
3151 |
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
|
3152 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
|
3153 |
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
|
3154 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
|
3155 } |
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
|
3156 /* 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
|
3157 |
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
|
3158 case MP_HOUSE: |
12250
b2b9e7cd3be5
(svn r16665) -Codechange: replace GetTownByTile() by Town::GetByTile()
smatz <smatz@openttd.org>
parents:
12249
diff
changeset
|
3159 return Town::GetByTile(tile); |
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
|
3160 |
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
|
3161 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
|
3162 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
|
3163 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3164 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3165 |
15616
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3166 static bool _town_rating_test = false; ///< If \c true, town rating is in test-mode. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3167 static SmallMap<const Town *, int, 4> _town_test_ratings; ///< Map of towns to modified ratings, while in town rating test-mode. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3168 |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3169 /** |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3170 * Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3171 * The function is safe to use in nested calls. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3172 * @param mode Test mode switch (\c true means go to test-mode, \c false means leave test-mode). |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3173 */ |
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
|
3174 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
|
3175 { |
15616
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3176 static int ref_count = 0; // Number of times test-mode is switched on. |
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
|
3177 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
|
3178 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
|
3179 _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
|
3180 } |
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
|
3181 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
|
3182 } 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
|
3183 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
|
3184 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
|
3185 } |
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
|
3186 _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
|
3187 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3188 |
15616
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3189 /** |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3190 * Get the rating of a town for the #_current_company. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3191 * @param t Town to get the rating from. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3192 * @return Rating of the current company in the given town. |
d76890d16808
(svn r20279) -Doc: Doxygen additions/improvements.
alberth <alberth@openttd.org>
parents:
15604
diff
changeset
|
3193 */ |
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
|
3194 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
|
3195 { |
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
|
3196 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
|
3197 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
|
3198 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
|
3199 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
|
3200 } |
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
|
3201 } |
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
|
3202 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
|
3203 } |
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
|
3204 |
11106
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
3205 /** |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
3206 * 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
|
3207 * @param t Town to affect |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
3208 * @param add Value to add |
15655
0be6e9a4ca0b
(svn r20320) -Doc: Small Doxygen and normal comment fixes, and an missed addition.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
3209 * @param max Minimum (add < 0) resp. maximum (add > 0) rating that should be achievable with this change. |
11106
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
3210 * @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
|
3211 */ |
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
3212 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
|
3213 { |
15655
0be6e9a4ca0b
(svn r20320) -Doc: Small Doxygen and normal comment fixes, and an missed addition.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
3214 /* if magic_bulldozer cheat is active, town doesn't penalize for removing stuff */ |
11106
ada4c4d48050
(svn r15452) -Codechange: Add DC_NO_MODIFY_TOWN_RATING.
frosch <frosch@openttd.org>
parents:
11103
diff
changeset
|
3215 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
|
3216 !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
|
3217 (_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
|
3218 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3219 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3220 |
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
|
3221 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
|
3222 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
|
3223 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
|
3224 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
|
3225 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
|
3226 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3227 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3228 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
|
3229 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
|
3230 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
|
3231 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3232 } |
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
|
3233 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
|
3234 _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
|
3235 } 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
|
3236 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
|
3237 t->ratings[_current_company] = rating; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12999
diff
changeset
|
3238 SetWindowDirty(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
|
3239 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3240 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3241 |
14810
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3242 /** |
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3243 * Does the town authority allow the (destructive) action of the current company? |
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3244 * @param flags Checking flags of the command. |
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3245 * @param t Town that must allow the company action. |
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3246 * @param type Type of action that is wanted. |
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3247 * @return A succeeded command if the action is allowed, a failed command if it is not allowed. |
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3248 */ |
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3249 CommandCost 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
|
3250 { |
6422
fb10eafe2a26
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents:
6357
diff
changeset
|
3251 /* 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
|
3252 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
|
3253 _cheats.magic_bulldozer.value || (flags & DC_NO_TEST_TOWN_RATING)) { |
14810
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3254 return CommandCost(); |
11879
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
3255 } |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
3256 |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
3257 /* 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
|
3258 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
|
3259 /* 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
|
3260 { 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
|
3261 { 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
|
3262 { 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
|
3263 }; |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
3264 |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
3265 /* 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
|
3266 * 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
|
3267 * 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
|
3268 */ |
11879
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
3269 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
|
3270 |
0552f4ad7c9e
(svn r16277) -Codechange: enumerize values and remove unneeded values used for testing town rating
smatz <smatz@openttd.org>
parents:
11874
diff
changeset
|
3271 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
|
3272 SetDParam(0, t->index); |
14810
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3273 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
|
3274 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3275 |
14810
869ae7d2bad4
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
3276 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
|
3277 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3278 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6201
diff
changeset
|
3279 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
|
3280 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3281 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
|
3282 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3283 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
|
3284 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
|
3285 |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
3286 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
|
3287 if (--t->exclusive_counter == 0) t->exclusivity = INVALID_COMPANY; |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15533
diff
changeset
|
3288 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3289 |
18456
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3290 UpdateTownAmounts(t); |
83ceb002c6df
(svn r23300) -Add: show on the GUI when a town grows and make a general framework to store goals of a town
truebrain <truebrain@openttd.org>
parents:
18454
diff
changeset
|
3291 UpdateTownRating(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
|
3292 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
|
3293 UpdateTownUnwanted(t); |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18629
diff
changeset
|
3294 UpdateTownCargoes(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
|
3295 } |
18562
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
3296 |
799e3cfa2a65
(svn r23407) -Codechange: Keep a bitmap of all cargos accepted by towns.
terkhen <terkhen@openttd.org>
parents:
18560
diff
changeset
|
3297 UpdateTownCargoBitmap(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3298 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3299 |
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
|
3300 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
|
3301 { |
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
|
3302 /* 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
|
3303 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
|
3304 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
|
3305 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
|
3306 } |
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
|
3307 } |
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
|
3308 |
18271
f63c96a8cfb5
(svn r23107) -Codechange: let GetSlopePixelZ and TerraformTile tile type functions use int z as well
rubidium <rubidium@openttd.org>
parents:
18270
diff
changeset
|
3309 static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, int 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
|
3310 { |
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
|
3311 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
|
3312 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
|
3313 GetHouseNorthPart(house); // modifies house to the ID of the north tile |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
3314 const HouseSpec *hs = HouseSpec::Get(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
|
3315 |
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
|
3316 /* 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
|
3317 if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) && |
18264
e33480209002
(svn r23100) -Codechange: remove pointless multiplications by TILE_HEIGHT for the terraform code
rubidium <rubidium@openttd.org>
parents:
18260
diff
changeset
|
3318 (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) { |
13060
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3319 bool allow_terraform = true; |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3320 |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3321 /* Call the autosloping callback per tile, not for the whole building at once. */ |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3322 house = GetHouseType(tile); |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3323 hs = HouseSpec::Get(house); |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3324 if (HasBit(hs->callback_mask, CBM_HOUSE_AUTOSLOPE)) { |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3325 /* If the callback fails, allow autoslope. */ |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3326 uint16 res = GetHouseCallback(CBID_HOUSE_AUTOSLOPE, 0, 0, house, Town::GetByTile(tile), tile); |
18311
09cb5ec03259
(svn r23147) -Change: [NewGRF v8] Unify the return values of boolean callbacks, and check the results for validity.
frosch <frosch@openttd.org>
parents:
18306
diff
changeset
|
3327 if (res != CALLBACK_FAILED && ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_AUTOSLOPE, res)) allow_terraform = false; |
13060
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3328 } |
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3329 |
13758
9a5050ee2cec
(svn r18283) -Feature: [NewGRF] Add new price bases for removing industries, building/removing unmovables (new objects), building/removing rail-waypoints/buoys, interacting with town-authority, building foundations, funding primary industries (when not prospecting) and towns.
frosch <frosch@openttd.org>
parents:
13756
diff
changeset
|
3330 if (allow_terraform) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); |
13060
0ea9c5ed1b7a
(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
3331 } |
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
|
3332 } |
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
|
3333 |
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
|
3334 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
|
3335 } |
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
|
3336 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10259
diff
changeset
|
3337 /** 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
|
3338 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
|
3339 DrawTile_Town, // draw_tile_proc |
18255
b3cb40aab91b
(svn r23091) -Codechange: rename some Get*Z functions to Get*PixelZ functions if they return the Z in pixels (like TilePixelHeight)
rubidium <rubidium@openttd.org>
parents:
18246
diff
changeset
|
3340 GetSlopePixelZ_Town, // get_slope_z_proc |
10259
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
3341 ClearTile_Town, // clear_tile_proc |
12244
69298536ac76
(svn r16659) -Codechange: rename GetAcceptedCargo() to AddAcceptedCargo() and change its behaviour accordingly
smatz <smatz@openttd.org>
parents:
12218
diff
changeset
|
3342 AddAcceptedCargo_Town, // add_accepted_cargo_proc |
10259
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
3343 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
|
3344 GetTileTrackStatus_Town, // get_tile_track_status_proc |
12245
14ea827578da
(svn r16660) -Codechange: get rid of more dummy tile_type_procs
smatz <smatz@openttd.org>
parents:
12244
diff
changeset
|
3345 NULL, // click_tile_proc |
10259
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
3346 AnimateTile_Town, // animate_tile_proc |
18324
47c733513cae
(svn r23160) -Fix: wrong comments in a lot of TileTypeProcs definitions
yexo <yexo@openttd.org>
parents:
18311
diff
changeset
|
3347 TileLoop_Town, // tile_loop_proc |
47c733513cae
(svn r23160) -Fix: wrong comments in a lot of TileTypeProcs definitions
yexo <yexo@openttd.org>
parents:
18311
diff
changeset
|
3348 ChangeTileOwner_Town, // change_tile_owner_proc |
12258
269852ac9420
(svn r16673) -Codechange: rename GetProducedCargo() to AddProducedCargo() and change its behaviour accordingly
smatz <smatz@openttd.org>
parents:
12252
diff
changeset
|
3349 AddProducedCargo_Town, // add_produced_cargo_proc |
10259
17db0806ef6a
(svn r14490) -Codechange: fix comment style on a few locations (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
3350 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
|
3351 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
|
3352 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
|
3353 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
3354 |
12251
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
3355 |
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
3356 HouseSpec _house_specs[HOUSE_MAX]; |
0047ec1f61d2
(svn r16666) -Codechange: replace GetHouseSpecs() by HouseSpec::Get(), hide _house_specs[]
smatz <smatz@openttd.org>
parents:
12250
diff
changeset
|
3357 |
6332
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
3358 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
|
3359 { |
60486b0b3e39
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents:
6257
diff
changeset
|
3360 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
|
3361 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
|
3362 |
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
|
3363 /* 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
|
3364 _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
|
3365 } |