annotate src/town_cmd.cpp @ 7871:8dad3ff6a7a7 draft

(svn r11421) -Fix [FS#1431]: do not use a function that asserts when wrapping around the map's edge when you use the wrapping (and MP_VOID tiles) to determine whether the bridge can be build.
author rubidium <rubidium@openttd.org>
date Mon, 12 Nov 2007 19:21:33 +0000
parents e6ee8bfd9045
children 0c095a634caa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
3 /** @file town_cmd.cpp */
3b141366478a (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents: 6133
diff changeset
4
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
5 #include "stdafx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
6 #include "openttd.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
7 #include "functions.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
8 #include "debug.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
9 #include "strings.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
10 #include "road_map.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
11 #include "table/strings.h"
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 "table/sprites.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
13 #include "map.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
14 #include "landscape.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
15 #include "tile.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
16 #include "town_map.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
17 #include "tunnel_map.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
18 #include "viewport.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
19 #include "town.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
20 #include "command.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
21 #include "gfx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
22 #include "industry.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
23 #include "station.h"
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
24 #include "vehicle.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 "player.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
26 #include "news.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
27 #include "saveload.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
28 #include "economy.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
29 #include "gui.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
30 #include "unmovable_map.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
31 #include "water_map.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
32 #include "variables.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
33 #include "bridge.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34 #include "bridge_map.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
35 #include "date.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
36 #include "table/town_land.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
37 #include "genworld.h"
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
38 #include "newgrf.h"
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
39 #include "newgrf_callbacks.h"
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
40 #include "newgrf_house.h"
6629
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
41 #include "newgrf_commons.h"
6956
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
42 #include "newgrf_townname.h"
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
43 #include "misc/autoptr.hpp"
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
44 #include "autoslope.h"
7709
1859cffc251e (svn r11243) -Fix: update waypoint signs when renaming a town
glx <glx@openttd.org>
parents: 7684
diff changeset
45 #include "waypoint.h"
7849
e6ee8bfd9045 (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas <belugas@openttd.org>
parents: 7847
diff changeset
46 #include "transparency.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
47
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
48 /* Initialize the town-pool */
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
49 DEFINE_OLD_POOL_GENERIC(Town, Town)
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
50
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
51 Town::Town(TileIndex tile)
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
52 {
7410
1da8340185cb (svn r10787) -Fix r10755: _total_towns was not increased when placing town manually in scenario editor
glx <glx@openttd.org>
parents: 7401
diff changeset
53 if (tile != 0) _total_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
54 this->xy = tile;
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
55 }
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
56
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
57 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
58 {
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
59 DeleteName(this->townnametype);
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
60
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
61 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
62
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
63 Industry *i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
64
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
65 /* 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
66 * 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
67 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
68 _town_sort_dirty = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
69 _total_towns--;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
70
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
71 /* Delete all industries belonging to the town */
7390
9ae410265dce (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7386
diff changeset
72 FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
73
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
74 /* Go through all tiles and delete those belonging to the town */
7386
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
75 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
76 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
77 case MP_HOUSE:
7386
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
78 if (GetTownByTile(tile) == this) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
79 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
80
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
81 case MP_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
82 case MP_TUNNELBRIDGE:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
83 if (IsTileOwner(tile, OWNER_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
84 ClosestTownFromTile(tile, (uint)-1) == 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
85 DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
86 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
87
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
88 default:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
89 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
90 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
91 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
92
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
93 DeleteSubsidyWithTown(this->index);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
94
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
95 MarkWholeScreenDirty();
7386
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
96
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
97 this->xy = 0;
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
98 }
f9b4e970b14d (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7370
diff changeset
99
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
100 // Local
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
101 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
102
7684
ea99aeb26c95 (svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7666
diff changeset
103 /* 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
104 enum TownGrowthResult {
ea99aeb26c95 (svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7666
diff changeset
105 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
106 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
107 // 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
108 };
ea99aeb26c95 (svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7666
diff changeset
109
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
110 static bool BuildTownHouse(Town *t, TileIndex tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
111 static void DoBuildTownHouse(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
112
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
113 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
114 {
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
115 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
116 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
117
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
118 typedef void TownDrawTileProc(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
119 static TownDrawTileProc * const _town_draw_tile_procs[1] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
120 TownDrawHouseLift
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
121 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
122
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
123 uint OriginalTileRandomiser(uint x, uint y)
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
124 {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
125 uint variant;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
126 variant = x >> 4;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
127 variant ^= x >> 6;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
128 variant ^= y >> 4;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
129 variant -= y >> 6;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
130 variant &= 3;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
131 return variant;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
132 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
133
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
134 /**
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
135 * 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
136 *
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
137 * @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
138 */
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
139 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
140 {
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
141 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
142 }
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
143
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
144 /**
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
145 * 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
146 * 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
147 * @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
148 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
149 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
150 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
151 const DrawBuildingsTileStruct *dcts;
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
152 SpriteID image;
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
153 SpriteID pal;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
154 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
155
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
156 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
157 /* 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
158 * 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
159 * house id is drawn instead. */
02bfc4a81378 (svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents: 6341
diff changeset
160 if (GetHouseSpecs(house_id)->spritegroup != NULL) {
02bfc4a81378 (svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents: 6341
diff changeset
161 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
162 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
163 } else {
02bfc4a81378 (svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents: 6341
diff changeset
164 house_id = GetHouseSpecs(house_id)->substitute_id;
02bfc4a81378 (svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros <maedhros@openttd.org>
parents: 6341
diff changeset
165 }
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
166 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
167
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
168 /* Retrieve pointer to the draw town tile struct */
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
169 dcts = &_town_draw_tile_data[house_id << 4 | OriginalTileRandomiser(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
170
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
171 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
172
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
173 image = dcts->ground.sprite;
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
174 pal = dcts->ground.pal;
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
175 DrawGroundSprite(image, 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
176
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
177 /* Add a house on top of the ground? */
5668
3d6d9bff3dd8 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents: 5587
diff changeset
178 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
179 if (image != 0) {
7333
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7226
diff changeset
180 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
181 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
182 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
183 dcts->width,
a9acd5d86f94 (svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7566
diff changeset
184 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
185 dcts->dz,
7333
7110c41ab174 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium <rubidium@openttd.org>
parents: 7226
diff changeset
186 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
187 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
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
7849
e6ee8bfd9045 (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas <belugas@openttd.org>
parents: 7847
diff changeset
190 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
191 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
192
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 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
195
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
196 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
197 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
198 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
199
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
200 static uint GetSlopeZ_Town(TileIndex tile, uint x, uint y)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
201 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
202 return GetTileMaxZ(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
203 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
204
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
205 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
206 {
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
207 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
208 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
209
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
210 /**
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
211 * 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
212 * 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
213 * 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
214 * @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
215 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
216 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
217 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
218 int pos, dest;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
219
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
220 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
221 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
222 return;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
223 }
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 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
226
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
227 /* 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
228 * 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
229 * 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
230 * That bug seems to have been here since day 1?? */
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
231 if (!(GetHouseSpecs(GetHouseType(tile))->building_flags & BUILDING_IS_ANIMATED)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
232 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
233 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
234 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
235
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
236 if (!LiftHasDestination(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
237 int i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
238
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
239 /* Building has 6 floors, number 0 .. 6, where 1 is illegal.
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 * This is due to the fact that the first floor is, in the graphics,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
241 * the height of 2 'normal' floors.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
242 * Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
243 do {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
244 i = (Random() & 7) - 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
245 } while (i < 0 || i == 1 || i * 6 == GetLiftPosition(tile));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
246
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
247 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
248 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
249
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
250 pos = GetLiftPosition(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
251 dest = GetLiftDestination(tile) * 6;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
252 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
253 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
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 (pos == dest) HaltLift(tile);
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 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
258 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
259
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
260 static void UpdateTownRadius(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
261
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
262 /**
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
263 * 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
264 * @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
265 * @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
266 * @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
267 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
268 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
269 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
270 const 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
271
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
272 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
273 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
274 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
275 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
276 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
277
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
278 /**
7545
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7500
diff changeset
279 * Marks the town sign as needing a repaint.
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7500
diff changeset
280 *
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7500
diff changeset
281 * This function marks the area of the sign of a town as dirty for repaint.
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7500
diff changeset
282 *
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7500
diff changeset
283 * @param t Town requesting town sign for repaint
a84d70ad7876 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium <rubidium@openttd.org>
parents: 7500
diff changeset
284 * @ingroup dirty
6534
6cfb1cd027f8 (svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents: 6525
diff changeset
285 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
286 static void MarkTownSignDirty(Town *t)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
287 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
288 MarkAllViewportsDirty(
6491
696f0e1b046e (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents: 6486
diff changeset
289 t->sign.left - 6,
696f0e1b046e (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents: 6486
diff changeset
290 t->sign.top - 3,
696f0e1b046e (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents: 6486
diff changeset
291 t->sign.left + t->sign.width_1 * 4 + 12,
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
292 t->sign.top + 45
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
293 );
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
294 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
295
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
296 /**
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
297 * 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
298 * 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
299 * @param t Town to update
6cfb1cd027f8 (svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents: 6525
diff changeset
300 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
301 void UpdateTownVirtCoord(Town *t)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
302 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
303 Point pt;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
304
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
305 MarkTownSignDirty(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
306 pt = RemapCoords2(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
307 SetDParam(0, t->index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
308 SetDParam(1, t->population);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
309 UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
310 _patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
311 MarkTownSignDirty(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
312 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
313
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
314 /**
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
315 * 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
316 * @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
317 * @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
318 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
319 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
320 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
321 t->population += mod;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
322 InvalidateWindow(WC_TOWN_VIEW, t->index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
323 UpdateTownVirtCoord(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
324
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
325 if (_town_sort_order & 2) _town_sort_dirty = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
326 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
327
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
328 /**
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
329 * 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
330 * 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
331 * @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
332 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
333 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
334 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
335 uint32 pop;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
336 const 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
337
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
338 pop = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
339 FOR_ALL_TOWNS(t) pop += t->population;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
340 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
341 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
342
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
343 /**
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
344 * 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
345 * @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
346 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
347 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
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 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
350
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
351 /* means it is completed, get out. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
352 if (LiftHasDestination(tile)) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
353
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
354 /* 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
355 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
356 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
357
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
358 /* Check and/or */
7642
610b2a5d634a (svn r11173) -Codechange: rename some callback enums so they are more uniform.
rubidium <rubidium@openttd.org>
parents: 7641
diff changeset
359 if (HASBIT(GetHouseSpecs(GetHouseType(tile))->callback_mask, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE)) {
7215
ba8faf180ec2 (svn r10493) -Codechange: update some callback ID enums to reflect their changed usage, add a few and update the comments.
rubidium <rubidium@openttd.org>
parents: 7139
diff changeset
360 uint16 callback_res = GetHouseCallback(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, 0, 0, GetHouseType(tile), GetTownByTile(tile), 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
361 if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
362 }
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
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
364 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
365 /* 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
366 * building to the town. */
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
367 ChangePopulation(GetTownByTile(tile), GetHouseSpecs(GetHouseType(tile))->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
368 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
369 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
370 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
371
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
372 /** Make the house advances in its construction stages until completion
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
373 * @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
374 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
375 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
376 {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
377 uint flags = GetHouseSpecs(GetHouseType(tile))->building_flags;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
378 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
379 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
380 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
381 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
382 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
383
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
384 /**
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
385 * 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
386 * @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
387 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
388 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
389 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
390 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
391 uint32 r;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
392 HouseID house_id = GetHouseType(tile);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
393 HouseSpec *hs = GetHouseSpecs(house_id);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
394
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
395 /* 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
396 * 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
397 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
398
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
399 if (!IsHouseCompleted(tile)) {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
400 /* 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
401 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
402 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
403 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
404
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
405 /* 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
406 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
407 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
408 !LiftHasDestination(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
409 CHANCE16(1, 2))
6cfb1cd027f8 (svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents: 6525
diff changeset
410 AddAnimatedTile(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
411
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
412 t = GetTownByTile(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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
414 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
415
6645
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
416 if (HASBIT(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) {
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
417 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
418 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
419
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
420 if (callback == CALLBACK_FAILED) break;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
421 if (callback == 0x20FF) break;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
422
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
423 CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grffile);
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
424 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
425
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
426 uint amt = GB(callback, 0, 8);
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
427 uint moved = MoveGoodsToStation(tile, 1, 1, cargo, amt);
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
428
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
429 const CargoSpec *cs = GetCargo(cargo);
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
430 switch (cs->town_effect) {
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
431 case TE_PASSENGERS:
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
432 t->new_max_pass += amt;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
433 t->new_act_pass += moved;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
434 break;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
435
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
436 case TE_MAIL:
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
437 t->new_max_mail += amt;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
438 t->new_act_mail += moved;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
439 break;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
440
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
441 default:
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
442 break;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
443 }
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
444 }
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
445 } else {
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
446 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
447 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
448 uint moved;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
449
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
450 if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
451 t->new_max_pass += amt;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
452 moved = MoveGoodsToStation(tile, 1, 1, CT_PASSENGERS, amt);
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
453 t->new_act_pass += moved;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
454 }
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
455
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
456 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
457 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
458 uint moved;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
459
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
460 if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
461 t->new_max_mail += amt;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
462 moved = MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt);
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
463 t->new_act_mail += moved;
75841d480476 (svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138 <peter1138@openttd.org>
parents: 6642
diff changeset
464 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
465 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
466
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
467 _current_player = OWNER_TOWN;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
468
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
469 if (hs->building_flags & BUILDING_HAS_1_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
470 HASBIT(t->flags12, TOWN_IS_FUNDED) &&
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
471 CanDeleteHouse(tile) &&
6605
c3aef1e6e3e1 (svn r9823) -Feature: Add support for house property 1F - minimum life span.
maedhros <maedhros@openttd.org>
parents: 6571
diff changeset
472 max(_cur_year - GetHouseConstructionYear(tile), 0) >= 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
473 --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
474 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
475
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
476 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
477
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
478 /* Rebuild with another 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
479 if (GB(r, 24, 8) >= 12) DoBuildTownHouse(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
480 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
481
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
482 _current_player = OWNER_NONE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
483 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
484
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
485 /**
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
486 * Unused 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
487 * @param tile unused
6cfb1cd027f8 (svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas <belugas@openttd.org>
parents: 6525
diff changeset
488 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
489 static void ClickTile_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
490 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
491 /* 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
492 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
493
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
494 static CommandCost ClearTile_Town(TileIndex tile, byte 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
495 {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
496 int rating;
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
497 CommandCost 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
498 Town *t;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
499 HouseSpec *hs = GetHouseSpecs(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
500
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
501 if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_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
502 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
503
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6946
diff changeset
504 cost.AddCost(_price.remove_house * hs->removal_cost >> 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
505
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
506 rating = hs->remove_rating_decrease;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
507 _cleared_town_rating += rating;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
508 _cleared_town = t = GetTownByTile(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
509
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
510 if (IsValidPlayer(_current_player)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
511 if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
512 SetDParam(0, t->index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
513 return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
514 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
515 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
516
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
517 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
518 ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM);
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 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
521
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
522 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
523 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
524
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
525 static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
526 {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
527 HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
6525
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
528 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
529
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
530 /* 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
531 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
532 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
533 }
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
534
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
535 /* Check for custom 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
536 if (HASBIT(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) {
6642
1e9b34ce8000 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138 <peter1138@openttd.org>
parents: 6629
diff changeset
537 uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
6525
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
538 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
539 /* Replace accepted cargo types with translated values from callback */
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
540 accepts[0] = GetCargoTranslation(GB(callback, 0, 5), hs->grffile);
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
541 accepts[1] = GetCargoTranslation(GB(callback, 5, 5), hs->grffile);
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
542 accepts[2] = GetCargoTranslation(GB(callback, 10, 5), hs->grffile);
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
543 }
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
544 }
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
545
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
546 /* Check for custom cargo acceptance */
7642
610b2a5d634a (svn r11173) -Codechange: rename some callback enums so they are more uniform.
rubidium <rubidium@openttd.org>
parents: 7641
diff changeset
547 if (HASBIT(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) {
6642
1e9b34ce8000 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138 <peter1138@openttd.org>
parents: 6629
diff changeset
548 uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
6525
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
549 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
550 if (accepts[0] != CT_INVALID) ac[accepts[0]] = GB(callback, 0, 4);
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
551 if (accepts[1] != CT_INVALID) ac[accepts[1]] = GB(callback, 4, 4);
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
552 if (_opt.landscape != LT_TEMPERATE && HASBIT(callback, 12)) {
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
553 /* The 'S' bit indicates food instead of goods */
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
554 ac[CT_FOOD] = GB(callback, 8, 4);
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
555 } else {
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
556 if (accepts[2] != CT_INVALID) ac[accepts[2]] = GB(callback, 8, 4);
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
557 }
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
558 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
559 }
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
560 }
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
561
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
562 /* 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
563 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
564 if (accepts[i] != CT_INVALID) ac[accepts[i]] = hs->cargo_acceptance[i];
309fb9068af9 (svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138 <peter1138@openttd.org>
parents: 6491
diff changeset
565 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
566 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
567
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
568 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
569 {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
570 td->str = GetHouseSpecs(GetHouseType(tile))->building_name;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
571 if (!IsHouseCompleted(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
572 SetDParamX(td->dparam, 0, td->str);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
573 td->str = STR_2058_UNDER_CONSTRUCTION;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
574 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
575
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
576 td->owner = OWNER_TOWN;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
577 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
578
6683
6984c0dbbb07 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium <rubidium@openttd.org>
parents: 6661
diff changeset
579 static uint32 GetTileTrackStatus_Town(TileIndex tile, TransportType mode, uint sub_mode)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
580 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
581 /* 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
582 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
583 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
585 static void ChangeTileOwner_Town(TileIndex tile, PlayerID old_player, PlayerID new_player)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
586 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
587 /* 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
588 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
589
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
590 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
591
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
592 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
593 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
594 if (HASBIT(t->flags12, TOWN_IS_FUNDED)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
595 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
596 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
597 if (GrowTown(t)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
598 i = t->growth_rate;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
599 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
600 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
601 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
602 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
603 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
604 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
605
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
606 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
607 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
608
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
609 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
610 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
611 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
612
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
613 /* Make sure each town's tickhandler invocation frequency is about the
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
614 * same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
615 for (_cur_town_iter += GetMaxTownIndex() + 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
616 _cur_town_iter >= TOWN_GROWTH_FREQUENCY;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
617 _cur_town_iter -= TOWN_GROWTH_FREQUENCY) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
618 uint32 i = _cur_town_ctr;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
619
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
620 if (++_cur_town_ctr > GetMaxTownIndex())
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
621 _cur_town_ctr = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
622
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
623 if (IsValidTownID(i)) TownTickHandler(GetTown(i));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
624 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
625 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
626
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
627 /**
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
628 * 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
629 *
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
630 * @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
631 * @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
632 * @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
633 * @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
634 */
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
635 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
636 {
6661
5850ac8865e8 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium <rubidium@openttd.org>
parents: 6645
diff changeset
637 TrackBits b = GetAnyRoadTrackBits(tile, ROADTYPE_ROAD);
5587
c44c070c5032 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium <rubidium@openttd.org>
parents: 5584
diff changeset
638 RoadBits r = ROAD_NONE;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
639
7225
2d9785c79784 (svn r10504) -Codechange: Shorten the test if no track bit has been found
belugas <belugas@openttd.org>
parents: 7215
diff changeset
640 if (b == TRACK_BIT_NONE) return r;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
641 if (b & TRACK_BIT_X) r |= ROAD_X;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
642 if (b & TRACK_BIT_Y) r |= ROAD_Y;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
643 if (b & TRACK_BIT_UPPER) r |= ROAD_NE | ROAD_NW;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
644 if (b & TRACK_BIT_LOWER) r |= ROAD_SE | ROAD_SW;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
645 if (b & TRACK_BIT_LEFT) r |= ROAD_NW | ROAD_SW;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
646 if (b & TRACK_BIT_RIGHT) r |= ROAD_NE | ROAD_SE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
647 return r;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
648 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
649
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
650 /**
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
651 * Check if a neighboring tile has a 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
652 *
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
653 * @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
654 * @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
655 * @param dist_multi distance multiplyer
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
656 * @return true if one of the neighboring tiles at the
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
657 * given distance is a road tile else 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
658 */
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
659 static bool IsNeighborRoadTile(TileIndex tile, 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
660 {
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
661 static TileIndexDiff tid_lt[3]; // lookup table for the used diff values
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
662 tid_lt[0] = TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT));
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
663 tid_lt[1] = TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT));
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
664 tid_lt[2] = TileOffsByDiagDir(ReverseDiagDir(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
665
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
666 /* We add 1 to the distance because we want to get 1 for
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
667 * the min distance multiplyer and not 0.
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
668 * Therefore we start at 4. The 4 is used because
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
669 * there are 4 tiles per distance step to check.
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
670 */
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
671 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
672 for (uint pos = 4; pos < dist_multi; pos++) {
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
673 TileIndexDiff cur = 0;
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
674 /* For each even value of pos add the right TileIndexDiff
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
675 * for each uneven value the left TileIndexDiff
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
676 * for each with 2nd bit set (2,3,6,7,..) add the reversed TileIndexDiff
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
677 */
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
678 cur += tid_lt[(pos & 1) ? 0 : 1];
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
679 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
680
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
681 cur = (uint)(pos / 4) * cur; // Multiply for the fitting distance
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
682 if (GetTownRoadBits(TILE_ADD(tile, cur)) & DiagDirToRoadBits((pos & 2) ? dir : ReverseDiagDir(dir))) return true;
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
683 }
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
684 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
685 }
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
686
7566
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
687 /**
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
688 * 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
689 *
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
690 * @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
691 * @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
692 * @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
693 */
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
694 static bool IsRoadAllowedHere(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
695 {
7226
be81fa3595a2 (svn r10505) -Fix(r10249)[FS#1016]: Town was still trying to gather information for tiles on which it could not build. aising the values to 2 will prevent further invasion of the water-at-the-edge :)
belugas <belugas@openttd.org>
parents: 7225
diff changeset
696 if (TileX(tile) < 2 || TileY(tile) < 2 || MapMaxX() <= TileX(tile) || MapMaxY() <= TileY(tile)) 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
697
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
698 Slope cur_slope, desired_slope;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
699
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
700 /* If this assertion fails, it might be because the world contains
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
701 * land at the edges. This is not ok. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
702 TILE_ASSERT(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
703
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
704 for (;;) {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
705 /* Check if there already is a road at this point? */
7566
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
706 if (GetTownRoadBits(tile) == ROAD_NONE) {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
707 /* No, try to build one in the direction.
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
708 * if that fails clear the land, and if that fails exit.
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
709 * This is to make sure that we can build a road here later. */
7566
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
710 if (CmdFailed(DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) &&
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
711 CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
712 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
713 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
714
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
715 cur_slope = GetTileSlope(tile, NULL);
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
716 if (cur_slope == SLOPE_FLAT) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
717 no_slope:
6571
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
718 /* Tile has no slope */
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
719 switch (_patches.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
720 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
721
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
722 case TL_ORIGINAL: /* Disallow the road if any neighboring tile has a road (distance: 1) */
7566
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
723 return !IsNeighborRoadTile(tile, dir, 1);
6571
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
724
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
725 case TL_BETTER_ROADS: /* Disallow the road if any neighboring tile has a road (distance: 1 and 2). */
7566
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
726 return !IsNeighborRoadTile(tile, dir, 2);
6571
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
727 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
728 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
729
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
730 /* If the tile is not a slope in the right direction, then
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
731 * maybe terraform some. */
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
732 desired_slope = (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? SLOPE_NE : SLOPE_NW;
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
733 if (desired_slope != cur_slope && ComplementSlope(desired_slope) != cur_slope) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
734 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
735
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
736 if (CHANCE16I(1, 8, r)) {
f0585ed32dd3 (svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7762
diff changeset
737 CommandCost res = CMD_ERROR;
f0585ed32dd3 (svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7762
diff changeset
738 if (!_generating_world && CHANCE16I(1, 10, r >> 4)) {
7480
a430b752ee98 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium <rubidium@openttd.org>
parents: 7413
diff changeset
739 /* Note: Do not replace " ^ 0xF" with ComplementSlope(). The slope might be steep. */
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
740 res = DoCommand(tile, CHANCE16I(1, 16, r >> 8) ? cur_slope : cur_slope ^ 0xF, 0,
f0585ed32dd3 (svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7762
diff changeset
741 DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
742 }
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
743 if (CmdFailed(res) && CHANCE16I(1, 3, r >> 16)) {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
744 /* We can consider building on the slope, though. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
745 goto no_slope;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
746 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
747 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
748 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
749 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
750 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
751 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
752 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
753
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
754 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
755 {
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
756 CommandCost r;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
757
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
758 TILE_ASSERT(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
759
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
760 r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6946
diff changeset
761 if (CmdFailed(r) || r.GetCost() >= 126 * 16) 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
762 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
763 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
764 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
765
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
766 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
767 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
768 Slope tileh;
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 TILE_ASSERT(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
771
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
772 /* 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
773 if (IsTileType(tile, MP_HOUSE)) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
774 tileh = GetTileSlope(tile, NULL);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
775 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
776
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
777 /* First try up, then down */
5584
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 (!TerraformTownTile(tile, ~tileh & 0xF, 1)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
779 TerraformTownTile(tile, tileh & 0xF, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
780 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
781 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
782
6571
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
783 /**
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
784 * 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
785 *
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
786 * @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
787 * @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
788 * @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
789 * @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
790 * 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
791 */
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
792 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
793 {
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
794 /* 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
795 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
796 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
797
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
798 switch (_patches.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
799 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
800
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
801 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
802 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
803 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
804 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
805
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
806 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
807 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
808 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
809 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
810 }
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
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
812 /* 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
813 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
814
f0585ed32dd3 (svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7762
diff changeset
815 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
816
f0585ed32dd3 (svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7762
diff changeset
817 switch (GetTileSlope(tile, NULL)) {
f0585ed32dd3 (svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7762
diff changeset
818 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
819 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
820 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
821 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
822 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
823 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
824 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
825 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
826 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
827 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
828 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
829 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
830 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
831 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
832 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
833 }
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
834
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
835 /* 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
836 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
837 /* 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
838 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
839 }
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
840
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
841 /**
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
842 * 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
843 * 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
844 * 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
845 * 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
846 *
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
847 * @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
848 * @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
849 * @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
850 */
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
851 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
852 {
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
853 /* We can't look further than that. */
7641
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
854 if (TileX(tile) < 2 || TileY(tile) < 2 || MapMaxX() <= TileX(tile) || MapMaxY() <= TileY(tile)) return false;
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
855
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
856 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
857
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
858 /* 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
859 for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
860
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
861 if (IsTileType(TileAddByDiagDir(tile, dir), MP_HOUSE)) counter++;
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
862
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
863 /* 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
864 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
865 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
866 _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
867 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
868 }
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
869 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
870 }
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
871 }
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
872 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
873 }
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
874
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
875 /**
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
876 * 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
877 *
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
878 * @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
879 * @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
880 * @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
881 * @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
882 */
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
883 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
884 {
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
885 if (CmdSucceeded(DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) {
7684
ea99aeb26c95 (svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7666
diff changeset
886 _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
887 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
888 }
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
889 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
890 }
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
891
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
892 /**
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
893 * 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
894 * 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
895 * 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
896 *
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
897 * @param t The current town
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
898 * @param tile The 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
899 * @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
900 * @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
901 */
7845
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
902 static bool GrowTownWithBridge(const Town *t, TileIndex tile, 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
903 {
7845
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
904 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
905
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
906 const Slope slope = GetTileSlope(tile, NULL);
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
907 if (slope == SLOPE_FLAT) return false; // no slope, no bridge
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
908
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
909 /* Make sure the direction is compatible with the slope.
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
910 * If any of the following bits match, the slope is forbidden for
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
911 * that diagdir. This means 5 non-steep slopes, and 3 steep-slopes
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
912 * per diagdir.
7845
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
913 * 0 -> 0b1100
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
914 * 1 -> 0b0110
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
915 * 2 -> 0b0011
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
916 * 3 -> 0b1001
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
917 * 0xCC is 0b11001100, so we just shift it right with
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
918 * the direction to get the forbidden slope mask. */
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
919 if (HASBITS(slope & 0x0F, 0xCC >> 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
920
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
921 /* 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
922 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
923
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
924 /* We are in the right direction */
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
925 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
926 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
927
7871
8dad3ff6a7a7 (svn r11421) -Fix [FS#1431]: do not use a function that asserts when wrapping around the map's edge when you use the wrapping (and MP_VOID tiles) to determine whether the bridge can be build.
rubidium <rubidium@openttd.org>
parents: 7849
diff changeset
928 int delta = TileOffsByDiagDir(bridge_dir);
8dad3ff6a7a7 (svn r11421) -Fix [FS#1431]: do not use a function that asserts when wrapping around the map's edge when you use the wrapping (and MP_VOID tiles) to determine whether the bridge can be build.
rubidium <rubidium@openttd.org>
parents: 7849
diff changeset
929
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
930 do {
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
931 if (bridge_length++ >= 11) {
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
932 /* Max 11 tile long bridges */
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
933 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
934 }
7871
8dad3ff6a7a7 (svn r11421) -Fix [FS#1431]: do not use a function that asserts when wrapping around the map's edge when you use the wrapping (and MP_VOID tiles) to determine whether the bridge can be build.
rubidium <rubidium@openttd.org>
parents: 7849
diff changeset
935 bridge_tile += delta;
7739
3387a53e113f (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium <rubidium@openttd.org>
parents: 7709
diff changeset
936 } while (IsWaterTile(bridge_tile));
7641
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
937
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
938 /* 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
939 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
940
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
941 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
942 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
943
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
944 /* Can we actually build the 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
945 if (CmdSucceeded(DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_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
946 DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE);
7684
ea99aeb26c95 (svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7666
diff changeset
947 _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
948 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
949 }
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
950 }
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
951 /* 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
952 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
953 }
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
954
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
955 /**
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
956 * 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
957 * 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
958 * 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
959 * @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
960 * @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
961 * @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
962 * @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
963 * @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
964 * @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
965 * @li Forbid roads, only build 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
966 * @li TL_NO_ROADS
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
967 *
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
968 * @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
969 * @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
970 * @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
971 * @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
972 */
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
973 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
974 {
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
975 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
976 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
977
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
978 TILE_ASSERT(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
979
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
980 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
981 /* 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
982 * 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
983 _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
984
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
985 /* Remove hills etc */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
986 LevelTownLand(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
987
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
988 /* Is a road allowed here? */
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
989 switch (_patches.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
990 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
991
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
992 case TL_NO_ROADS: /* Disallow 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
993 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
994
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
995 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
996 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
997 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
998 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
999 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
1000
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1001 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
1002 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
1003 if (!IsRoadAllowedHere(tile, target_dir)) return;
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
1004
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
1005 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
1006
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
1007 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
1008 /* 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
1009 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
1010 }
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1011
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
1012 if (!IsRoadAllowedHere(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
1013 /* 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
1014 * 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
1015 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
1016
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1017 /* 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
1018 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
1019 !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
1020 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
1021 }
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1022
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1023 /* 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
1024 * 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
1025 }
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1026
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
1027 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
1028 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
1029 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1030
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
1031 } 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
1032 /* 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
1033 * 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
1034 * 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
1035 _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
1036
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1037 switch (_patches.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
1038 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
1039
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1040 case TL_NO_ROADS: /* Disallow 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
1041 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
1042
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1043 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
1044 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
1045 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
1046 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
1047
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1048 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
1049 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
1050 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
1051 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
1052 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1053 } else {
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
1054 bool allow_house = false; // 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
1055
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1056 /* Reached a tunnel/bridge? Then continue at the other side of it. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1057 if (IsTileType(tile, MP_TUNNELBRIDGE)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1058 if (IsTunnel(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1059 *tile_ptr = GetOtherTunnelEnd(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1060 } else if (IsBridge(tile) && GetBridgeTransportType(tile) == TRANSPORT_ROAD) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1061 *tile_ptr = GetOtherBridgeEnd(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1062 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1063 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1064 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1065
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1066 /* 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
1067 * 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
1068 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
1069 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
1070
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1071 /* 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
1072 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
1073
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
1074 /* Don't walk into water. */
7739
3387a53e113f (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium <rubidium@openttd.org>
parents: 7709
diff changeset
1075 if (IsWaterTile(house_tile)) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1076
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
1077 switch (_patches.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
1078 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
1079
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1080 case TL_NO_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
1081 allow_house = 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
1082 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
1083
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1084 case TL_3X3_GRID: /* Use 2x2 grid afterwards! */
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
1085 GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir));
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
1086 /* FALL THROUGH */
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
1087
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1088 case TL_2X2_GRID:
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
1089 rcmd = GetTownRoadGridElement(t1, house_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
1090 allow_house = (rcmd == ROAD_NONE);
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 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
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 case TL_BETTER_ROADS: /* Use original afterwards! */
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 GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir));
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
1095 /* FALL THROUGH */
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
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 case TL_ORIGINAL:
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 /* Allow a house at the edge. 60% chance or
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 * always ok if no road allowed. */
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
1100 rcmd = DiagDirToRoadBits(target_dir);
7641
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
1101 allow_house = (!IsRoadAllowedHere(house_tile, target_dir) || CHANCE16(6, 10));
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
1102 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
1103 }
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1104
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1105 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
1106 /* 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
1107 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
1108 /* Level the land if possible */
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
1109 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
1110
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1111 /* And build a house.
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1112 * 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
1113 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
1114 _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
1115 }
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 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1117 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1118 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1119
7684
ea99aeb26c95 (svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7666
diff changeset
1120 _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
1121 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1122
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1123 /* Return if a water tile */
7739
3387a53e113f (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium <rubidium@openttd.org>
parents: 7709
diff changeset
1124 if (IsWaterTile(tile)) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1125
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
1126 /* 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
1127 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
1128 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
1129
7845
469ee079ee16 (svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight <truelight@openttd.org>
parents: 7766
diff changeset
1130 /* 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
1131 * 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
1132 * 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
1133 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
1134
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
1135 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
1136 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1137
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1138 /** Returns "growth" if a house was built, or no if the build failed.
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1139 * @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
1140 * @param tile to inquiry
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1141 * @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
1142 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1143 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
1144 {
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
1145 /* 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
1146 * @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
1147 */
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
1148 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
1149
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1150 TILE_ASSERT(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1151
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 /* 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
1153 * 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
1154 * them a little handicap. */
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 switch (_patches.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
1156 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
1157 _grow_town_result = 10 + t->num_houses * 2 / 9;
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1158 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
1159
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1160 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
1161 case TL_2X2_GRID:
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1162 _grow_town_result = 10 + t->num_houses * 1 / 9;
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1163 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
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 default:
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1166 _grow_town_result = 10 + t->num_houses * 4 / 9;
6777295c2328 (svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas <belugas@openttd.org>
parents: 6560
diff changeset
1167 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
1168 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1169
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1170 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
1171 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
1172
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1173 /* 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
1174 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
1175
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1176 /* 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
1177 * 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
1178 cur_rb &= ~DiagDirToRoadBits(ReverseDiagDir(target_dir));
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
1179 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
1180 return _grow_town_result;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1181
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1182 /* Select a random bit from the blockmask, walk a step
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1183 * and continue the search from there. */
7566
9da968584674 (svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas <belugas@openttd.org>
parents: 7549
diff changeset
1184 do target_dir = RandomDiagDir(); while (!(cur_rb & DiagDirToRoadBits(target_dir)));
7641
5e3cd60f89c4 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7603
diff changeset
1185 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
1186
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
1187 if (IsTileType(tile, MP_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
1188 /* Don't allow building over roads of other cities */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1189 if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t) {
7684
ea99aeb26c95 (svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium <rubidium@openttd.org>
parents: 7666
diff changeset
1190 _grow_town_result = GROWTH_SUCCEED;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1191 } else if (_game_mode == GM_EDITOR) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1192 /* 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
1193 * owner :) (happy happy happy road now) */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1194 SetTileOwner(tile, OWNER_TOWN);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1195 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
1196 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1197 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1198
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1199 /* 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
1200 } 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
1201
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1202 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
1203 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1204
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
1205 /**
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
1206 * 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
1207 * 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
1208 * 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
1209 *
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
1210 * @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
1211 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
1212 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
1213 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1214 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
1215 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
1216 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
1217 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
1218 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
1219 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1220
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1221 /** Grow the town
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1222 * @Return true if a house was built, or no if the build 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
1223 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
1224 {
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
1225
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
1226 /* Let the town be a ghost 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
1227 * The player wanted it in such a way. Thus there he has it. ;)
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
1228 * Never reached in editor mode. */
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
1229 if (_patches.town_layout == TL_NO_ROADS && _generating_world) {
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
1230 return 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
1231 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1232
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1233 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
1234 {-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
1235 { 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
1236 { 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
1237 {-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
1238 {-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
1239 { 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
1240 { 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
1241 { 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
1242 {-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
1243 {-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
1244 { 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
1245 { 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
1246 { 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
1247 };
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
1248 const TileIndexDiffC *ptr;
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
1249
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1250 /* Current player is a 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
1251 PlayerID old_player = _current_player;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1252 _current_player = OWNER_TOWN;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1253
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
1254 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
1255
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1256 /* Find a road that we can base the construction on. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1257 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
1258 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
1259 int r = GrowTownAtRoad(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
1260 _current_player = old_player;
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
1261 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
1262 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1263 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
1264 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1265
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1266 /* 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
1267 * clearing some land and then building a road there. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1268 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
1269 for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1270 /* Only work with plain land that not already has a house */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1271 if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) {
6946
803e29b0584e (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1272 if (CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1273 DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1274 _current_player = old_player;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1275 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
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 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1278 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
1279 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1280
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1281 _current_player = old_player;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1282 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
1283 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1284
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1285 static void UpdateTownRadius(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
1286 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1287 static const uint16 _town_radius_data[23][5] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1288 { 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
1289 { 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
1290 { 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
1291 { 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
1292 { 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
1293 { 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
1294 { 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
1295 { 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
1296 { 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
1297 { 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
1298 { 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
1299 { 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
1300 { 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
1301 { 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
1302 { 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
1303 { 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
1304 { 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
1305 { 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
1306 {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
1307 {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
1308 {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
1309 {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
1310 {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
1311 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1312
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1313 if (t->num_houses < 92) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1314 memcpy(t->radius, _town_radius_data[t->num_houses / 4], sizeof(t->radius));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1315 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1316 int mass = t->num_houses / 8;
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1317 /* At least very roughly extrapolate. Empirical numbers dancing between
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1318 * overwhelming by cottages and skyscrapers outskirts. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1319 t->radius[0] = mass * mass;
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1320 /* Actually we are proportional to sqrt() but that's right because
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1321 * we are covering an area. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1322 t->radius[1] = mass * 7;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1323 t->radius[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
1324 t->radius[3] = mass * 4;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1325 t->radius[4] = mass * 3;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1326 //debug("%d (->%d): %d %d %d %d\n", t->num_houses, mass, t->radius[0], t->radius[1], t->radius[3], t->radius[4]);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1327 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1328 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1329
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1330 static bool CreateTownName(uint32 *townnameparts)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1331 {
6956
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1332 extern int _nb_orig_names;
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 Town *t2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1334 char buf1[64];
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1335 char buf2[64];
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1336 uint32 r;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1337 /* Do not set too low tries, since when we run out of names, we loop
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1338 * for #tries only one time anyway - then we stop generating more
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1339 * towns. Do not show it too high neither, since looping through all
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1340 * the other towns may take considerable amount of time (10000 is
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1341 * too much). */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1342 int tries = 1000;
6956
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1343 bool grf = (_opt.town_name >= _nb_orig_names);
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1344 uint32 grfid = grf ? GetGRFTownNameId(_opt.town_name - _nb_orig_names) : 0;
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1345 uint16 townnametype = grf ? GetGRFTownNameType(_opt.town_name - _nb_orig_names) : SPECSTR_TOWNNAME_START + _opt.town_name;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1346
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1347 assert(townnameparts);
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 for (;;) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1350 restart:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1351 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
1352
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1353 SetDParam(0, r);
6956
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1354 if (grf && grfid != 0) {
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1355 GRFTownNameGenerate(buf1, grfid, townnametype, r, lastof(buf1));
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1356 } else {
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1357 GetString(buf1, townnametype, lastof(buf1));
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1358 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1359
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1360 /* Check size and width */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1361 if (strlen(buf1) >= 31 || GetStringBoundingBox(buf1).width > 130) continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1362
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1363 FOR_ALL_TOWNS(t2) {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1364 /* We can't just compare the numbers since
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1365 * several numbers may map to a single name. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1366 SetDParam(0, t2->index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1367 GetString(buf2, STR_TOWN, lastof(buf2));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1368 if (strcmp(buf1, buf2) == 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1369 if (tries-- < 0) 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
1370 goto restart;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1371 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1372 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1373 *townnameparts = r;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1374 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
1375 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1376 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1377
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1378 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
1379 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1380 t->max_pass = t->population >> 3;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1381 t->max_mail = t->population >> 4;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1382 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1383
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1384 /**
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1385 * 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
1386 *
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1387 * @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
1388 * @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
1389 * @param townnameparts The town name
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1390 * @param size_mode How the size should be determined
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1391 * @param size Parameter for size determination
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1392 */
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1393 static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSizeMode size_mode, uint 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
1394 {
6956
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1395 extern int _nb_orig_names;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1396 int x, i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1397
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1398 t->xy = tile;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1399 t->num_houses = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1400 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
1401 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
1402 t->flags12 = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1403 t->population = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1404 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
1405 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
1406 t->new_max_pass = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1407 t->new_max_mail = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1408 t->new_act_pass = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1409 t->new_act_mail = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1410 t->max_pass = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1411 t->max_mail = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1412 t->act_pass = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1413 t->act_mail = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1414
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1415 t->pct_pass_transported = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1416 t->pct_mail_transported = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1417 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
1418 t->new_act_food = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1419 t->new_act_water = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1420 t->act_food = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1421 t->act_water = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
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 for (i = 0; i != MAX_PLAYERS; i++)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1424 t->ratings[i] = 500;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1425
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1426 t->have_ratings = 0;
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
1427 t->exclusivity = INVALID_PLAYER;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1428 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
1429 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
1430
6956
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1431 if (_opt.town_name < _nb_orig_names) {
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1432 /* Original town name */
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1433 t->townnamegrfid = 0;
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1434 t->townnametype = SPECSTR_TOWNNAME_START + _opt.town_name;
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1435 } else {
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1436 /* Newgrf town name */
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1437 t->townnamegrfid = GetGRFTownNameId(_opt.town_name - _nb_orig_names);
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1438 t->townnametype = GetGRFTownNameType(_opt.town_name - _nb_orig_names);
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
1439 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1440 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
1441
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1442 UpdateTownVirtCoord(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1443 _town_sort_dirty = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1444
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1445 /* Random town size. */
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1446 x = (Random() & 0xF) + 8;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1447
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1448 switch (size_mode) {
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1449 default: NOT_REACHED();
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1450
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1451 case TSM_RANDOM:
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1452 t->larger_town = false;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1453 break;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1454
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1455 case TSM_FIXED:
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1456 x = size * 16 + 3;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1457 t->larger_town = false;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1458 break;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1459
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1460 case TSM_CITY:
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1461 x *= _patches.initial_city_size;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1462 t->larger_town = true;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1463 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
1464 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1465
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1466 t->num_houses += x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1467 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
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 i = x * 4;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1470 do {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1471 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
1472 } 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
1473
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1474 t->num_houses -= x;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1475 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
1476 UpdateTownMaxPass(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1477 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1478
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1479 /** Create a new town.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1480 * This obviously only works in the scenario editor. Function not removed
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1481 * as it might be possible in the future to fund your own town :)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1482 * @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
1483 * @param flags type of operation
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1484 * @param p1 size of the town (0 = small, 1 = medium, 2 = large)
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1485 * @param p2 size mode (@see TownSizeMode)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1486 */
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
1487 CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1488 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1489 uint32 townnameparts;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1490
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1491 /* Only in the scenario editor */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1492 if (_game_mode != GM_EDITOR) return CMD_ERROR;
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1493 if (p2 > TSM_CITY) 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
1494
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1495 SET_EXPENSES_TYPE(EXPENSES_OTHER);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1496
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1497 /* Check if too close to the edge of map */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1498 if (DistanceFromEdge(tile) < 12)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1499 return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1500
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1501 /* Can only build on clear flat areas, possibly with trees. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1502 if ((!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES)) || GetTileSlope(tile, NULL) != SLOPE_FLAT) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1503 return_cmd_error(STR_0239_SITE_UNSUITABLE);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1504 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1505
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1506 /* Check distance to all other 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
1507 if (IsCloseToTown(tile, 20))
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1508 return_cmd_error(STR_0238_TOO_CLOSE_TO_ANOTHER_TOWN);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1509
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1510 /* Get a unique name for 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
1511 if (!CreateTownName(&townnameparts))
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1512 return_cmd_error(STR_023A_TOO_MANY_TOWNS);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1513
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1514 /* Allocate town struct */
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
1515 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
1516 if (t == NULL) return_cmd_error(STR_023A_TOO_MANY_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
1517 AutoPtrT<Town> t_auto_delete = 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
1518
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1519 /* 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
1520 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
1521 _generating_world = true;
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1522 DoCreateTown(t, tile, townnameparts, (TownSizeMode)p2, 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
1523 _generating_world = false;
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
1524 t_auto_delete.Detach();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1525 }
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6946
diff changeset
1526 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
1527 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1528
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1529 Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint 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
1530 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1531 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
1532 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
1533 uint32 townnameparts;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1534
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1535 do {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1536 /* Generate a tile index not too close from the edge */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1537 tile = RandomTile();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1538 if (DistanceFromEdge(tile) < 20) continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1539
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1540 /* Make sure the tile is plain */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1541 if (!IsTileType(tile, MP_CLEAR) || GetTileSlope(tile, NULL) != SLOPE_FLAT) continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1542
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1543 /* Check not too close to a 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
1544 if (IsCloseToTown(tile, 20)) continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1545
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1546 /* Get a unique name for 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
1547 if (!CreateTownName(&townnameparts)) break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1548
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1549 /* Allocate a town struct */
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
1550 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
1551 if (t == NULL) break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1552
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1553 DoCreateTown(t, tile, townnameparts, mode, 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
1554 return t;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1555 } while (--attempts);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1556 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
1557 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1558
6560
838badc858d3 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas <belugas@openttd.org>
parents: 6547
diff changeset
1559 static const byte _num_initial_towns[4] = {5, 11, 23, 46};
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1560
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
1561 bool GenerateTowns()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1562 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1563 uint num = 0;
6061
c1fc6b10db93 (svn r8791) -Revert: r8790 Committed too much in last commit
miham <miham@openttd.org>
parents: 6060
diff changeset
1564 uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1565 uint num_cities = _patches.larger_towns == 0 ? 0 : n / _patches.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
1566
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1567 SetGeneratingWorldProgress(GWP_TOWN, n);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1568
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1569 do {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1570 IncreaseGeneratingWorldProgress(GWP_TOWN);
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1571 /* try 20 times to create a random-sized town for the first loop. */
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1572 TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1573 if (CreateRandomTown(20, mode, _patches.initial_city_size) != NULL) num++;
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1574 if (num_cities > 0) num_cities--;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1575 } while (--n);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1576
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1577 /* give it a last try, but now more aggressive */
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
1578 if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0) == NULL) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1579 if (GetNumTowns() == 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1580 /* XXX - can we handle that more gracefully? */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1581 if (_game_mode != GM_EDITOR) error("Could not generate any town");
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1582
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1583 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
1584 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1585 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1586
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1587 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
1588 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1589
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1590 static bool CheckBuildHouseMode(TileIndex tile, Slope tileh, int mode)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1591 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1592 int b;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1593 Slope slope;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1594
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1595 static const byte _masks[8] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1596 0xC,0x3,0x9,0x6,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1597 0x3,0xC,0x6,0x9,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1598 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1599
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1600 slope = GetTileSlope(tile, NULL);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1601 if (IsSteepSlope(slope)) 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
1602
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1603 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) 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
1604
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1605 b = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1606 if ((slope != SLOPE_FLAT && ~slope & _masks[mode])) b = ~b;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1607 if ((tileh != SLOPE_FLAT && ~tileh & _masks[mode+4])) b = ~b;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1608 if (b)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1609 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
1610
6946
803e29b0584e (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1611 return CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1612 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1613
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1614
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1615 uint GetTownRadiusGroup(const 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
1616 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1617 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
1618 uint smallest;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1619 uint i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1620
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1621 if (t->fund_buildings_months && dist <= 25) return 4;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1622
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1623 smallest = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1624 for (i = 0; i != lengthof(t->radius); i++) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1625 if (dist < t->radius[i]) smallest = i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1626 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1627
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1628 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
1629 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1630
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1631 static bool CheckFree2x2Area(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
1632 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1633 int i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1634
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1635 static const TileIndexDiffC _tile_add[] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1636 {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
1637 {0 - 0, 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
1638 {1 - 0, 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
1639 {1 - 1, 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
1640 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1641
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1642 for (i = 0; i != 4; i++) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1643 tile += ToTileIndexDiff(_tile_add[i]);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1644
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1645 if (GetTileSlope(tile, NULL) != SLOPE_FLAT) 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
1646
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1647 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) 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
1648
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1649 if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_FORCETEST, CMD_LANDSCAPE_CLEAR)))
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1650 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
1651 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1652
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1653 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
1654 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1655
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1656 static void DoBuildTownHouse(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
1657 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1658 int i;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1659 uint bitmask;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1660 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
1661 Slope slope;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1662 uint z;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1663 uint oneof = 0;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1664 HouseSpec *hs;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1665
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1666 /* Above snow? */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1667 slope = GetTileSlope(tile, &z);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1668
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1669 /* Get the town zone 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
1670 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1671 uint rad = GetTownRadiusGroup(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
1672
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1673 int land = _opt.landscape;
6357
96b1652c6011 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas <belugas@openttd.org>
parents: 6350
diff changeset
1674 if (land == LT_ARCTIC && z >= _opt.snow_line) land = -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
1675
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1676 bitmask = (1 << rad) + (1 << (land + 12));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1677 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1678
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1679 /* 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
1680 * 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
1681 * bits 5-10 are not used. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1682 {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1683 HouseID houses[HOUSE_MAX];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1684 int num = 0;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1685 uint cumulative_probs[HOUSE_MAX];
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1686 uint probability_max = 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
1687
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1688 /* Generate a list of all possible houses that can be built. */
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1689 for (i = 0; i < HOUSE_MAX; i++) {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1690 hs = GetHouseSpecs(i);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1691 if ((~hs->building_availability & bitmask) == 0 && hs->enabled) {
6914
d4c8b81ac7e4 (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas <belugas@openttd.org>
parents: 6842
diff changeset
1692 if (_loaded_newgrf_features.has_newhouses) {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1693 probability_max += hs->probability;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1694 cumulative_probs[num] = probability_max;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1695 }
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1696 houses[num++] = (HouseID)i;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1697 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1698 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1699
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1700 for (;;) {
6914
d4c8b81ac7e4 (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas <belugas@openttd.org>
parents: 6842
diff changeset
1701 if (_loaded_newgrf_features.has_newhouses) {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1702 uint r = RandomRange(probability_max);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1703 for (i = 0; i < num; i++) if (cumulative_probs[i] >= r) break;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1704
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1705 house = houses[i];
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1706 } else {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1707 house = houses[RandomRange(num)];
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1708 }
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1709
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1710 hs = GetHouseSpecs(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
1711
6914
d4c8b81ac7e4 (svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas <belugas@openttd.org>
parents: 6842
diff changeset
1712 if (_loaded_newgrf_features.has_newhouses) {
7762
15549e3a048b (svn r11308) -Fix (r9315): Change the house id as well as the house spec when using an overridden town building, since the house id is the one that's used to actually build the house.
maedhros <maedhros@openttd.org>
parents: 7739
diff changeset
1713 if (hs->override != 0) {
15549e3a048b (svn r11308) -Fix (r9315): Change the house id as well as the house spec when using an overridden town building, since the house id is the one that's used to actually build the house.
maedhros <maedhros@openttd.org>
parents: 7739
diff changeset
1714 house = hs->override;
15549e3a048b (svn r11308) -Fix (r9315): Change the house id as well as the house spec when using an overridden town building, since the house id is the one that's used to actually build the house.
maedhros <maedhros@openttd.org>
parents: 7739
diff changeset
1715 hs = GetHouseSpecs(house);
15549e3a048b (svn r11308) -Fix (r9315): Change the house id as well as the house spec when using an overridden town building, since the house id is the one that's used to actually build the house.
maedhros <maedhros@openttd.org>
parents: 7739
diff changeset
1716 }
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1717
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1718 if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1719
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1720 if (HASBIT(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) {
6642
1e9b34ce8000 (svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138 <peter1138@openttd.org>
parents: 6629
diff changeset
1721 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, 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
1722 if (callback_res != CALLBACK_FAILED && callback_res == 0) continue;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1723 }
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1724 }
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1725
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1726 if (_cur_year < hs->min_date || _cur_year > hs->max_date) 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
1727
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1728 /* Special houses that there can be only one of. */
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1729 if (hs->building_flags & BUILDING_IS_CHURCH) {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1730 SETBIT(oneof, TOWN_HAS_CHURCH);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1731 } else if (hs->building_flags & BUILDING_IS_STADIUM) {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1732 SETBIT(oneof, TOWN_HAS_STADIUM);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1733 } else {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1734 oneof = 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
1735 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1736
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1737 if (HASBITS(t->flags12 , oneof)) continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1738
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1739 /* Make sure there is no slope? */
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1740 if (hs->building_flags & TILE_NOT_SLOPED && slope != SLOPE_FLAT) 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
1741
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1742 if (hs->building_flags & TILE_SIZE_2x2) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1743 if (CheckFree2x2Area(tile) ||
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1744 CheckFree2x2Area(tile += TileDiffXY(-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
1745 CheckFree2x2Area(tile += TileDiffXY( 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
1746 CheckFree2x2Area(tile += TileDiffXY( 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
1747 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1748 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1749 tile += TileDiffXY(0, 1);
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1750 } else if (hs->building_flags & TILE_SIZE_2x1) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1751 if (CheckBuildHouseMode(tile + TileDiffXY(1, 0), slope, 0)) break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1752
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1753 if (CheckBuildHouseMode(tile + TileDiffXY(-1, 0), slope, 1)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1754 tile += TileDiffXY(-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
1755 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1756 }
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1757 } else if (hs->building_flags & TILE_SIZE_1x2) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1758 if (CheckBuildHouseMode(tile + TileDiffXY(0, 1), slope, 2)) break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1759
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1760 if (CheckBuildHouseMode(tile + TileDiffXY(0, -1), slope, 3)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1761 tile += TileDiffXY(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
1762 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1763 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1764 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1765 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1766 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1767 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1768 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1769
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1770 t->num_houses++;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1771 IncreaseBuildingCount(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
1772
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1773 /* Special houses that there can be only one of. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1774 t->flags12 |= oneof;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1775
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1776 {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1777 byte construction_counter = 0, construction_stage = 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
1778
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1779 if (_generating_world) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1780 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
1781
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1782 construction_stage = TOWN_HOUSE_COMPLETED;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1783 if (CHANCE16(1, 7)) construction_stage = 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
1784
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1785 if (construction_stage == TOWN_HOUSE_COMPLETED) {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1786 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
1787 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1788 construction_counter = GB(r, 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
1789 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1790 }
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1791 MakeTownHouse(tile, t->index, construction_counter, construction_stage, house, VehicleRandomBits());
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1792 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1793 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1794
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1795 static bool BuildTownHouse(Town *t, TileIndex tile)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1796 {
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
1797 CommandCost r;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1798
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1799 if (IsSteepSlope(GetTileSlope(tile, NULL))) 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
1800 if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) 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
1801
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1802 r = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1803 if (CmdFailed(r)) return false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1804
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1805 DoBuildTownHouse(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
1806 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
1807 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1808
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1809
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1810 static void DoClearTownHouseHelper(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
1811 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1812 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
1813 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
1814 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
1815 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1816
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1817 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
1818 {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1819 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
1820 uint eflags;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1821 HouseSpec *hs;
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1823 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
1824
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1825 /* need to align the tile to point to the upper left corner of the 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
1826 if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks.
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1827 if (GetHouseSpecs(house-1)->building_flags & TILE_SIZE_2x1) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1828 house--;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1829 tile += TileDiffXY(-1, 0);
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1830 } else if (GetHouseSpecs(house-1)->building_flags & BUILDING_2_TILES_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
1831 house--;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1832 tile += TileDiffXY(0, -1);
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1833 } else if (GetHouseSpecs(house-2)->building_flags & BUILDING_HAS_4_TILES) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1834 house-=2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1835 tile += TileDiffXY(-1, 0);
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1836 } else if (GetHouseSpecs(house-3)->building_flags & BUILDING_HAS_4_TILES) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1837 house-=3;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1838 tile += TileDiffXY(-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
1839 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1840 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1841
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1842 hs = GetHouseSpecs(house);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1843
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1844 /* 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
1845 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
1846 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
1847 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1848
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1849 t->num_houses--;
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1850 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
1851
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1852 /* 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
1853 if (hs->building_flags & BUILDING_IS_CHURCH) {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1854 CLRBIT(t->flags12, TOWN_HAS_CHURCH);
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1855 } else if (hs->building_flags & BUILDING_IS_STADIUM) {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1856 CLRBIT(t->flags12, TOWN_HAS_STADIUM);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1857 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1858
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1859 /* Do the actual clearing of tiles */
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
1860 eflags = hs->building_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
1861 DoClearTownHouseHelper(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
1862 if (eflags & BUILDING_2_TILES_X) DoClearTownHouseHelper(tile + TileDiffXY(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
1863 if (eflags & BUILDING_2_TILES_Y) DoClearTownHouseHelper(tile + TileDiffXY(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
1864 if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(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
1865 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1866
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
1867 static bool IsUniqueTownName(const char *name)
5c2889ace3ac (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents: 7058
diff changeset
1868 {
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
1869 const Town *t;
5c2889ace3ac (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents: 7058
diff changeset
1870 char buf[512];
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
1871
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
1872 FOR_ALL_TOWNS(t) {
5c2889ace3ac (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents: 7058
diff changeset
1873 SetDParam(0, t->index);
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
1874 GetString(buf, STR_TOWN, lastof(buf));
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
1875 if (strcmp(buf, name) == 0) return false;
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
1876 }
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
1877
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
1878 return true;
5c2889ace3ac (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents: 7058
diff changeset
1879 }
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
1880
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1881 /** Rename a town (server-only).
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1882 * @param tile unused
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1883 * @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
1884 * @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
1885 * @param p2 unused
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1886 */
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
1887 CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1888 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1889 StringID str;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1890 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
1891
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
1892 if (!IsValidTownID(p1) || StrEmpty(_cmd_text)) 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
1893
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1894 t = GetTown(p1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1895
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
1896 if (!IsUniqueTownName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
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
1897
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
1898 str = AllocateName(_cmd_text, 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
1899 if (str == 0) return CMD_ERROR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1900
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1901 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
1902 DeleteName(t->townnametype);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1903 t->townnametype = str;
7139
7edda6eb4f3f (svn r10413) -Fix r10211: t->townnamegrfid was not cleared when renaming a town
glx <glx@openttd.org>
parents: 7097
diff changeset
1904 t->townnamegrfid = 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
1905
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1906 UpdateTownVirtCoord(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1907 _town_sort_dirty = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1908 UpdateAllStationVirtCoord();
7709
1859cffc251e (svn r11243) -Fix: update waypoint signs when renaming a town
glx <glx@openttd.org>
parents: 7684
diff changeset
1909 UpdateAllWaypointSigns();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1910 MarkWholeScreenDirty();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1911 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1912 DeleteName(str);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1913 }
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6946
diff changeset
1914 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
1915 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1916
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
1917 /** Called from GUI */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1918 void ExpandTown(Town *t)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1919 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1920 int amount, n;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1921
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1922 _generating_world = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1923
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1924 /* The more houses, the faster we grow */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1925 amount = RandomRange(t->num_houses / 10) + 3;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1926 t->num_houses += amount;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1927 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
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 n = amount * 10;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1930 do GrowTown(t); while (--n);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1931
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1932 t->num_houses -= amount;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1933 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
1934
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1935 UpdateTownMaxPass(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1936 _generating_world = false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1937 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1938
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
1939 extern const byte _town_action_costs[8] = {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1940 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
1941 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1942
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1943 static void TownActionAdvertiseSmall(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
1944 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1945 ModifyStationRatingAround(t->xy, _current_player, 0x40, 10);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1946 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1947
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1948 static void TownActionAdvertiseMedium(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
1949 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1950 ModifyStationRatingAround(t->xy, _current_player, 0x70, 15);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1951 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1952
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1953 static void TownActionAdvertiseLarge(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
1954 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1955 ModifyStationRatingAround(t->xy, _current_player, 0xA0, 20);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1956 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1957
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1958 static void TownActionRoadRebuild(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
1959 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1960 t->road_build_months = 6;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1961
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1962 SetDParam(0, t->index);
7058
74d401c66902 (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138 <peter1138@openttd.org>
parents: 6997
diff changeset
1963 SetDParam(1, _current_player);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1964
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1965 AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1966 NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1967 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1968
6257
d7d39048e2ee (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight <truelight@openttd.org>
parents: 6247
diff changeset
1969 static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1970 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1971 PlayerID old;
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
1972 CommandCost r;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1973
7549
b202efd99ae5 (svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium <rubidium@openttd.org>
parents: 7545
diff changeset
1974 /* Statues can be build on slopes, just like houses. Only the steep slopes is a no go. */
b202efd99ae5 (svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium <rubidium@openttd.org>
parents: 7545
diff changeset
1975 if (IsSteepSlope(GetTileSlope(tile, NULL))) 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
1976
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1977 if (!IsTileType(tile, MP_HOUSE) &&
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1978 !IsTileType(tile, MP_CLEAR) &&
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1979 !IsTileType(tile, MP_TREES)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1980 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
1981 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1982
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1983 old = _current_player;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1984 _current_player = OWNER_NONE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1985 r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1986 _current_player = old;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1987
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1988 if (CmdFailed(r)) return false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1989
6257
d7d39048e2ee (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight <truelight@openttd.org>
parents: 6247
diff changeset
1990 MakeStatue(tile, _current_player, town_id);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1991 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
1992
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1993 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
1994 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1995
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1996 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1997 * Search callback function for TownActionBuildStatue
6484
17fdaec13730 (svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas <belugas@openttd.org>
parents: 6455
diff changeset
1998 * @param tile on which to perform the search
6257
d7d39048e2ee (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight <truelight@openttd.org>
parents: 6247
diff changeset
1999 * @param town_id The town_id for which we want a statue
6201
3b141366478a (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents: 6133
diff changeset
2000 * @return the result of the test
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2001 */
6257
d7d39048e2ee (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight <truelight@openttd.org>
parents: 6247
diff changeset
2002 static bool SearchTileForStatue(TileIndex tile, uint32 town_id)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2003 {
6257
d7d39048e2ee (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight <truelight@openttd.org>
parents: 6247
diff changeset
2004 return DoBuildStatueOfCompany(tile, town_id);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2005 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2006
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2007 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2008 * 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
2009 * 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
2010 * @param t town to search in
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2011 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2012 static void TownActionBuildStatue(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
2013 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2014 TileIndex tile = t->xy;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2015
6257
d7d39048e2ee (svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight <truelight@openttd.org>
parents: 6247
diff changeset
2016 if (CircularTileSearch(tile, 9, SearchTileForStatue, t->index))
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2017 SETBIT(t->statues, _current_player); // Once found and built, "inform" 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
2018 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2019
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2020 static void TownActionFundBuildings(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
2021 {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2022 /* Build next tick */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2023 t->grow_counter = 1;
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2024 /* If we were not already growing */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2025 SETBIT(t->flags12, TOWN_IS_FUNDED);
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2026 /* And grow for 3 months */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2027 t->fund_buildings_months = 3;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2028 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2029
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2030 static void TownActionBuyRights(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
2031 {
7657
65ad965cd225 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium <rubidium@openttd.org>
parents: 7642
diff changeset
2032 /* Check if it's allowed to by the rights */
65ad965cd225 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium <rubidium@openttd.org>
parents: 7642
diff changeset
2033 if (!_patches.exclusive_rights) return;
65ad965cd225 (svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium <rubidium@openttd.org>
parents: 7642
diff changeset
2034
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2035 t->exclusive_counter = 12;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2036 t->exclusivity = _current_player;
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 ModifyStationRatingAround(t->xy, _current_player, 130, 17);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2039 }
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 static void TownActionBribe(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
2042 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2043 if (!RandomRange(15)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2044 Station *st;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2045
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2046 /* set as unwanted for 6 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
2047 t->unwanted[_current_player] = 6;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2048
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2049 /* set all close by station ratings to 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
2050 FOR_ALL_STATIONS(st) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2051 if (st->town == t && st->owner == _current_player) {
6350
8132258640be (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138 <peter1138@openttd.org>
parents: 6343
diff changeset
2052 for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2053 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2054 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2055
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2056 /* only show errormessage to the executing player. All errors are handled command.c
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2057 * but this is special, because it can only 'fail' on a 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
2058 if (IsLocalPlayer()) ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 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
2059
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2060 /* decrease by a lot!
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2061 * ChangeTownRating is only for stuff in demolishing. Bribe failure should
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2062 * be independent of any cheat settings
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2063 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2064 if (t->ratings[_current_player] > RATING_BRIBE_DOWN_TO) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2065 t->ratings[_current_player] = RATING_BRIBE_DOWN_TO;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2066 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2067 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2068 ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2069 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2070 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2071
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2072 typedef void TownActionProc(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
2073 static TownActionProc * const _town_action_proc[] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2074 TownActionAdvertiseSmall,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2075 TownActionAdvertiseMedium,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2076 TownActionAdvertiseLarge,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2077 TownActionRoadRebuild,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2078 TownActionBuildStatue,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2079 TownActionFundBuildings,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2080 TownActionBuyRights,
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2081 TownActionBribe
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2082 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2083
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2084 extern uint GetMaskOfTownActions(int *nump, PlayerID pid, const 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
2085
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2086 /** Do a town action.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2087 * 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
2088 * 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
2089 * @param tile unused
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2090 * @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
2091 * @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
2092 * @param p2 action to perform, @see _town_action_proc for the list of available actions
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2093 */
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
2094 CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2095 {
6943
fd42cb9816c6 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents: 6914
diff changeset
2096 CommandCost 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
2097 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
2098
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2099 if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2100
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2101 t = GetTown(p1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2102
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2103 if (!HASBIT(GetMaskOfTownActions(NULL, _current_player, t), p2)) return CMD_ERROR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2104
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2105 SET_EXPENSES_TYPE(EXPENSES_OTHER);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2106
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6946
diff changeset
2107 cost.AddCost((_price.build_industry >> 8) * _town_action_costs[p2]);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2108
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2109 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
2110 _town_action_proc[p2](t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2111 InvalidateWindow(WC_TOWN_AUTHORITY, p1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2112 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2113
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2114 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
2115 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2116
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2117 static void UpdateTownGrowRate(Town *t)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2118 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2119 int n;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2120 Station *st;
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
2121 uint16 m;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2122 Player *p;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2123
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2124 /* Reset player ratings if they're low */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2125 FOR_ALL_PLAYERS(p) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2126 if (p->is_active && t->ratings[p->index] <= 200) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2127 t->ratings[p->index] += 5;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2128 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2129 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2130
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2131 n = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2132 FOR_ALL_STATIONS(st) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2133 if (DistanceSquare(st->xy, t->xy) <= t->radius[0]) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2134 if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2135 n++;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2136 if (IsValidPlayer(st->owner) && t->ratings[st->owner] <= 1000-12)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2137 t->ratings[st->owner] += 12;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2138 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2139 if (IsValidPlayer(st->owner) && t->ratings[st->owner] >= -1000+15)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2140 t->ratings[st->owner] -= 15;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2141 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2142 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2143 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2144
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2145 CLRBIT(t->flags12, TOWN_IS_FUNDED);
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
2146 if (_patches.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
2147
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2148 /** Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2149 * number of times towns are processed before a new building is built. */
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2150 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
2151 { 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
2152 { 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
2153 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2154
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2155 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
2156 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
2157 t->fund_buildings_months--;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2158 } 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
2159 m = _grow_count_values[1][min(n, 5)];
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2160 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
2161 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2162
6357
96b1652c6011 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas <belugas@openttd.org>
parents: 6350
diff changeset
2163 if (_opt.landscape == LT_ARCTIC) {
6343
f75b72d9fc98 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros <maedhros@openttd.org>
parents: 6342
diff changeset
2164 if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2165 return;
6357
96b1652c6011 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas <belugas@openttd.org>
parents: 6350
diff changeset
2166 } else if (_opt.landscape == LT_TROPIC) {
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 if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food==0 || t->act_water==0) && t->population > 60)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2168 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2169 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2170
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
2171 /* 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
2172 * this town and the growth rate is set to none. */
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
2173 uint growth_multiplier = _patches.town_growth_rate != 0 ? _patches.town_growth_rate - 1 : 1;
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
2174
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
2175 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
2176 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
2177
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2178 t->growth_rate = m / (t->num_houses / 50 + 1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2179 if (m <= t->grow_counter)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2180 t->grow_counter = m;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2181
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2182 SETBIT(t->flags12, TOWN_IS_FUNDED);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2183 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2184
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2185 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
2186 {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2187 /* Using +1 here to prevent overflow and division by zero */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2188 t->pct_pass_transported = t->new_act_pass * 256 / (t->new_max_pass + 1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2189
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2190 t->max_pass = t->new_max_pass; t->new_max_pass = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2191 t->act_pass = t->new_act_pass; t->new_act_pass = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2192 t->act_food = t->new_act_food; t->new_act_food = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2193 t->act_water = t->new_act_water; t->new_act_water = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2194
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2195 /* Using +1 here to prevent overflow and division by zero */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2196 t->pct_mail_transported = t->new_act_mail * 256 / (t->new_max_mail + 1);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2197 t->max_mail = t->new_max_mail; t->new_max_mail = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2198 t->act_mail = t->new_act_mail; t->new_act_mail = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2199
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2200 InvalidateWindow(WC_TOWN_VIEW, t->index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2201 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2202
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2203 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
2204 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2205 const Player* p;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2206
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2207 FOR_ALL_PLAYERS(p) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2208 if (t->unwanted[p->index] > 0) t->unwanted[p->index]--;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2209 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2210 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2211
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2212 bool CheckIfAuthorityAllows(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
2213 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2214 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
2215
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2216 if (!IsValidPlayer(_current_player)) 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
2217
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2218 t = ClosestTownFromTile(tile, _patches.dist_local_authority);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2219 if (t == NULL) return true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2220
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2221 if (t->ratings[_current_player] > -200) 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
2222
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2223 _error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2224 SetDParam(0, t->index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2225
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2226 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
2227 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2228
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2229
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2230 Town* CalcClosestTownFromTile(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
2231 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2232 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
2233 uint dist, best = threshold;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2234 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
2235
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2236 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
2237 dist = DistanceManhattan(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
2238 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
2239 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
2240 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
2241 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2242 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2243
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2244 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
2245 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2246
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2247
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2248 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
2249 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2250 if (IsTileType(tile, MP_HOUSE) || (
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
2251 IsTileType(tile, MP_ROAD) &&
6661
5850ac8865e8 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium <rubidium@openttd.org>
parents: 6645
diff changeset
2252 GetRoadOwner(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
2253 )) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2254 return GetTownByTile(tile);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2255 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2256 return CalcClosestTownFromTile(tile, threshold);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2257 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2258 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2259
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2260
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2261 void ChangeTownRating(Town *t, int add, int max)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2262 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2263 int rating;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2264
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2265 /* if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2266 if (t == NULL ||
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2267 !IsValidPlayer(_current_player) ||
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2268 (_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
2269 return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2270 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2271
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2272 SETBIT(t->have_ratings, _current_player);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2273
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2274 rating = t->ratings[_current_player];
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2275
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2276 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
2277 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
2278 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
2279 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
2280 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2281 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2282 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
2283 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
2284 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
2285 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2286 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2287 t->ratings[_current_player] = rating;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2288 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2289
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2290 /* penalty for removing town-owned stuff */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2291 static const int _default_rating_settings [3][3] = {
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2292 /* ROAD_REMOVE, TUNNELBRIDGE_REMOVE, INDUSTRY_REMOVE */
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
2293 { 0, 128, 384}, // Permissive
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
2294 { 48, 192, 480}, // Neutral
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
2295 { 96, 384, 768}, // Hostile
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2296 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2297
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2298 bool CheckforTownRating(uint32 flags, Town *t, byte type)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2299 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2300 int modemod;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2301
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2302 /* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2303 if (t == NULL || !IsValidPlayer(_current_player) || _cheats.magic_bulldozer.value)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2304 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
2305
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2306 /* check if you're allowed to remove the street/bridge/tunnel/industry
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2307 * 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
2308 * 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
2309 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2310 modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type];
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2311
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2312 if (t->ratings[_current_player] < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2313 SetDParam(0, t->index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2314 _error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2315 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
2316 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2317
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2318 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
2319 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2320
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
2321 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
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 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
2324
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2325 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
2326 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
2327
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2328 if (t->exclusive_counter != 0)
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
2329 if (--t->exclusive_counter == 0) t->exclusivity = INVALID_PLAYER;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2330
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2331 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
2332 UpdateTownAmounts(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2333 UpdateTownUnwanted(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2334 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2335 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2336
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
2337 void InitializeTowns()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2338 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2339 Subsidy *s;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2340
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2341 /* Clean the town pool and create 1 block in it */
7401
1e97c047c9f6 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium <rubidium@openttd.org>
parents: 7390
diff changeset
2342 _Town_pool.CleanPool();
1e97c047c9f6 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium <rubidium@openttd.org>
parents: 7390
diff changeset
2343 _Town_pool.AddBlockToPool();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2344
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2345 memset(_subsidies, 0, sizeof(_subsidies));
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2346 for (s=_subsidies; s != endof(_subsidies); s++)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2347 s->cargo_type = CT_INVALID;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2348
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2349 _cur_town_ctr = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2350 _cur_town_iter = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2351 _total_towns = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2352 _town_sort_dirty = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2353 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2354
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
2355 static CommandCost TerraformTile_Town(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
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
2356 {
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
2357 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
2358 HouseID house = GetHouseType(tile);
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
2359 HouseSpec *hs = GetHouseSpecs(house);
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
2360
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
2361 /* 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
2362 if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
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
2363 (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return _price.terraform;
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
2364 }
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
2365
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
2366 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
2367 }
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
2368
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
2369 extern const TileTypeProcs _tile_type_town_procs = {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2370 DrawTile_Town, /* draw_tile_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2371 GetSlopeZ_Town, /* get_slope_z_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2372 ClearTile_Town, /* clear_tile_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2373 GetAcceptedCargo_Town, /* get_accepted_cargo_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2374 GetTileDesc_Town, /* get_tile_desc_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2375 GetTileTrackStatus_Town, /* get_tile_track_status_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2376 ClickTile_Town, /* click_tile_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2377 AnimateTile_Town, /* animate_tile_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2378 TileLoop_Town, /* tile_loop_clear */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2379 ChangeTileOwner_Town, /* change_tile_owner_clear */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2380 NULL, /* get_produced_cargo_proc */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2381 NULL, /* vehicle_enter_tile_proc */
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
2382 GetFoundation_Town, /* get_foundation_proc */
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
2383 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
2384 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2385
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2386
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2387 /** Save and load of 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
2388 static const SaveLoad _town_desc[] = {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2389 SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2390 SLE_CONDVAR(Town, xy, SLE_UINT32, 6, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2391
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2392 SLE_CONDVAR(Town, population, SLE_FILE_U16 | SLE_VAR_U32, 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
2393 SLE_CONDVAR(Town, population, SLE_UINT32, 3, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2394
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2395
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2396 SLE_VAR(Town, num_houses, SLE_UINT16),
6956
6d300d04ac5e (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx <glx@openttd.org>
parents: 6950
diff changeset
2397 SLE_CONDVAR(Town, townnamegrfid, SLE_UINT32, 66, SL_MAX_VERSION),
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 SLE_VAR(Town, townnametype, SLE_UINT16),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2399 SLE_VAR(Town, townnameparts, SLE_UINT32),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2400
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2401 SLE_VAR(Town, flags12, SLE_UINT8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2402 SLE_VAR(Town, statues, SLE_UINT8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2403
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2404 /* sort_index_obsolete was stored here in savegame format 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
2405 SLE_CONDNULL(1, 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
2406
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2407 SLE_VAR(Town, have_ratings, SLE_UINT8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2408 SLE_ARR(Town, ratings, SLE_INT16, 8),
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2409 /* failed bribe attempts are stored since savegame format 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
2410 SLE_CONDARR(Town, unwanted, SLE_INT8, 8, 4,SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2411
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2412 SLE_CONDVAR(Town, max_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2413 SLE_CONDVAR(Town, max_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2414 SLE_CONDVAR(Town, new_max_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2415 SLE_CONDVAR(Town, new_max_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2416 SLE_CONDVAR(Town, act_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2417 SLE_CONDVAR(Town, act_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2418 SLE_CONDVAR(Town, new_act_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2419 SLE_CONDVAR(Town, new_act_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2420
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2421 SLE_CONDVAR(Town, max_pass, SLE_UINT32, 9, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2422 SLE_CONDVAR(Town, max_mail, SLE_UINT32, 9, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2423 SLE_CONDVAR(Town, new_max_pass, SLE_UINT32, 9, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2424 SLE_CONDVAR(Town, new_max_mail, SLE_UINT32, 9, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2425 SLE_CONDVAR(Town, act_pass, SLE_UINT32, 9, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2426 SLE_CONDVAR(Town, act_mail, SLE_UINT32, 9, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2427 SLE_CONDVAR(Town, new_act_pass, SLE_UINT32, 9, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2428 SLE_CONDVAR(Town, new_act_mail, SLE_UINT32, 9, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2429
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2430 SLE_VAR(Town, pct_pass_transported, SLE_UINT8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2431 SLE_VAR(Town, pct_mail_transported, SLE_UINT8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2432
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2433 SLE_VAR(Town, act_food, SLE_UINT16),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2434 SLE_VAR(Town, act_water, SLE_UINT16),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2435 SLE_VAR(Town, new_act_food, SLE_UINT16),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2436 SLE_VAR(Town, new_act_water, SLE_UINT16),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2437
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
2438 SLE_CONDVAR(Town, time_until_rebuild, SLE_UINT8, 0, 53),
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2439 SLE_CONDVAR(Town, grow_counter, SLE_UINT8, 0, 53),
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2440 SLE_CONDVAR(Town, growth_rate, SLE_UINT8, 0, 53),
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2441
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2442 SLE_CONDVAR(Town, time_until_rebuild, SLE_UINT16, 54, SL_MAX_VERSION),
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2443 SLE_CONDVAR(Town, grow_counter, SLE_UINT16, 54, SL_MAX_VERSION),
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2444 SLE_CONDVAR(Town, growth_rate, SLE_INT16, 54, SL_MAX_VERSION),
b0788d6496a9 (svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros <maedhros@openttd.org>
parents: 6427
diff changeset
2445
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2446 SLE_VAR(Town, fund_buildings_months, SLE_UINT8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2447 SLE_VAR(Town, road_build_months, SLE_UINT8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2448
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2449 SLE_VAR(Town, exclusivity, SLE_UINT8),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2450 SLE_VAR(Town, exclusive_counter, SLE_UINT8),
6486
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
2451
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
2452 SLE_CONDVAR(Town, larger_town, SLE_BOOL, 56, SL_MAX_VERSION),
12262d0c44ed (svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros <maedhros@openttd.org>
parents: 6484
diff changeset
2453
6422
fb10eafe2a26 (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas <belugas@openttd.org>
parents: 6357
diff changeset
2454 /* reserve extra space in savegame here. (currently 30 bytes) */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2455 SLE_CONDNULL(30, 2, SL_MAX_VERSION),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2456
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2457 SLE_END()
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2458 };
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2459
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2460 /* Save and load the mapping between the house id on the map, and the grf file
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2461 * it came from. */
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2462 static const SaveLoad _house_id_mapping_desc[] = {
6629
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2463 SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2464 SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2465 SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2466 SLE_END()
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2467 };
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2468
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2469 static void Save_HOUSEIDS()
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2470 {
6629
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2471 uint j = _house_mngr.GetMaxMapping();
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2472
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2473 for (uint i = 0; i < j; i++) {
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2474 SlSetArrayIndex(i);
6629
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2475 SlObject(&_house_mngr.mapping_ID[i], _house_id_mapping_desc);
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2476 }
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2477 }
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2478
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2479 static void Load_HOUSEIDS()
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2480 {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2481 int index;
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2482
6629
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2483 _house_mngr.ResetMapping();
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2484 uint max_id = _house_mngr.GetMaxMapping();
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2485
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2486 while ((index = SlIterateArray()) != -1) {
6629
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2487 if ((uint)index >= max_id) break;
188437dffcff (svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas <belugas@openttd.org>
parents: 6610
diff changeset
2488 SlObject(&_house_mngr.mapping_ID[index], _house_id_mapping_desc);
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2489 }
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2490 }
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2491
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
2492 static void Save_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
2493 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2494 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
2495
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2496 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
2497 SlSetArrayIndex(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
2498 SlObject(t, _town_desc);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2499 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2500 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2501
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
2502 static void Load_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
2503 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2504 int index;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2505
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2506 _total_towns = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2507
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2508 while ((index = SlIterateArray()) != -1) {
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
2509 Town *t = new (index) 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
2510 SlObject(t, _town_desc);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2511
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2512 _total_towns++;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2513 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2514
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2515 /* This is to ensure all pointers are within the limits of
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2516 * the size of the TownPool */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2517 if (_cur_town_ctr > GetMaxTownIndex())
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2518 _cur_town_ctr = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2519 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2520
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6201
diff changeset
2521 void AfterLoadTown()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2522 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2523 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
2524 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
2525 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
2526 UpdateTownVirtCoord(t);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2527 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2528 _town_sort_dirty = true;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2529 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2530
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2531 extern const ChunkHandler _town_chunk_handlers[] = {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2532 { 'HIDS', Save_HOUSEIDS, Load_HOUSEIDS, CH_ARRAY },
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2533 { 'CITY', Save_TOWN, Load_TOWN, CH_ARRAY | CH_LAST},
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2534 };
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2535
6332
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2536 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
2537 {
60486b0b3e39 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros <maedhros@openttd.org>
parents: 6257
diff changeset
2538 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
2539 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
2540
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
2541 /* 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
2542 _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
2543 }