author | rubidium |
Thu, 27 Dec 2007 13:35:39 +0000 | |
changeset 8144 | 65cec0877b78 |
parent 8140 | 0d0d8c94f84b |
child 8186 | 6ebffac017be |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6133
diff
changeset
|
3 |
/** @file town_cmd.cpp */ |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6133
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
8119
52b48108425a
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents:
8116
diff
changeset
|
7 |
#include "tile_cmd.h" |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
8 |
#include "debug.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3071
diff
changeset
|
9 |
#include "road_map.h" |
8102
906a3d3b6df1
(svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents:
8088
diff
changeset
|
10 |
#include "road_internal.h" /* Cleaning up road bits */ |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
11 |
#include "table/strings.h" |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
12 |
#include "table/sprites.h" |
6343
76d17f784c13
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6342
diff
changeset
|
13 |
#include "landscape.h" |
3319
16c0f06829a5
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3310
diff
changeset
|
14 |
#include "town_map.h" |
3154 | 15 |
#include "tunnel_map.h" |
0 | 16 |
#include "viewport.h" |
17 |
#include "town.h" |
|
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
18 |
#include "command_func.h" |
0 | 19 |
#include "industry.h" |
20 |
#include "station.h" |
|
21 |
#include "player.h" |
|
22 |
#include "news.h" |
|
23 |
#include "saveload.h" |
|
24 |
#include "gui.h" |
|
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3282
diff
changeset
|
25 |
#include "unmovable_map.h" |
3433
4e0d2ea104b3
(svn r4262) -Codechange: use IsClearWaterTile instead of some "home-brewn" marco. town_cmd is now map access free
celestar
parents:
3432
diff
changeset
|
26 |
#include "water_map.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
27 |
#include "variables.h" |
3359
633290bf1117
(svn r4154) -Moved MAX_BRIDGES in bridge.h and made it an enum. This makes two drops ...
celestar
parents:
3319
diff
changeset
|
28 |
#include "bridge.h" |
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5378
diff
changeset
|
29 |
#include "bridge_map.h" |
3654
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
30 |
#include "table/town_land.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
31 |
#include "genworld.h" |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
32 |
#include "newgrf.h" |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
33 |
#include "newgrf_callbacks.h" |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
34 |
#include "newgrf_house.h" |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
35 |
#include "newgrf_commons.h" |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
36 |
#include "newgrf_townname.h" |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
37 |
#include "misc/autoptr.hpp" |
7582
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
38 |
#include "autoslope.h" |
7709
439dcda6d74b
(svn r11243) -Fix: update waypoint signs when renaming a town
glx
parents:
7684
diff
changeset
|
39 |
#include "waypoint.h" |
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7847
diff
changeset
|
40 |
#include "transparency.h" |
8083
ad22eade501f
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents:
7969
diff
changeset
|
41 |
#include "tunnelbridge_map.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8108
diff
changeset
|
42 |
#include "strings_func.h" |
8124
59aee7f98ff9
(svn r11685) -Codechange: remove a few 'useless' includes.
rubidium
parents:
8121
diff
changeset
|
43 |
#include "string.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8124
diff
changeset
|
44 |
#include "window_func.h" |
8083
ad22eade501f
(svn r11644) -Codechange: merge some functions from tunnel_map.h and bridge_map.h into tunnelbridge_map.h
smatz
parents:
7969
diff
changeset
|
45 |
|
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
46 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
47 |
/* Initialize the town-pool */ |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
48 |
DEFINE_OLD_POOL_GENERIC(Town, Town) |
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
49 |
|
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
50 |
Town::Town(TileIndex tile) |
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
51 |
{ |
7410
14dc251e7ddb
(svn r10787) -Fix r10755: _total_towns was not increased when placing town manually in scenario editor
glx
parents:
7401
diff
changeset
|
52 |
if (tile != 0) _total_towns++; |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
53 |
this->xy = tile; |
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
54 |
} |
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
55 |
|
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
56 |
Town::~Town() |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
57 |
{ |
7413
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7410
diff
changeset
|
58 |
DeleteName(this->townnametype); |
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7410
diff
changeset
|
59 |
|
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7410
diff
changeset
|
60 |
if (CleaningPool()) return; |
a590f7f0edb3
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents:
7410
diff
changeset
|
61 |
|
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
62 |
Industry *i; |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
63 |
|
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
64 |
/* Delete town authority window |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
65 |
* and remove from list of sorted towns */ |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
66 |
DeleteWindowById(WC_TOWN_VIEW, this->index); |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
67 |
_town_sort_dirty = true; |
5298
46eabcb5c2b2
(svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents:
5247
diff
changeset
|
68 |
_total_towns--; |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
69 |
|
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
70 |
/* Delete all industries belonging to the town */ |
7390
16fb97ba8133
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents:
7386
diff
changeset
|
71 |
FOR_ALL_INDUSTRIES(i) if (i->town == this) delete i; |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
72 |
|
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
73 |
/* Go through all tiles and delete those belonging to the town */ |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
74 |
for (TileIndex tile = 0; tile < MapSize(); ++tile) { |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
75 |
switch (GetTileType(tile)) { |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
76 |
case MP_HOUSE: |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
77 |
if (GetTownByTile(tile) == this) DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
78 |
break; |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
79 |
|
7370
41adc721b1fa
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7335
diff
changeset
|
80 |
case MP_ROAD: |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
81 |
case MP_TUNNELBRIDGE: |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
82 |
if (IsTileOwner(tile, OWNER_TOWN) && |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
83 |
ClosestTownFromTile(tile, (uint)-1) == this) |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
84 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
85 |
break; |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
86 |
|
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
87 |
default: |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
88 |
break; |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
89 |
} |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
90 |
} |
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
91 |
|
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
92 |
DeleteSubsidyWithTown(this->index); |
4396
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
93 |
|
28cfaf264db6
(svn r6149) -Codechange: DeleteTown removes a town from the pool
truelight
parents:
4384
diff
changeset
|
94 |
MarkWholeScreenDirty(); |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
95 |
|
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
96 |
this->xy = 0; |
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
97 |
} |
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
98 |
|
0 | 99 |
// Local |
100 |
static int _grow_town_result; |
|
101 |
||
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
102 |
/* Describe the possible states */ |
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
103 |
enum TownGrowthResult { |
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
104 |
GROWTH_SUCCEED = -1, |
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
105 |
GROWTH_SEARCH_STOPPED = 0 |
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
106 |
// GROWTH_SEARCH_RUNNING >= 1 |
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
107 |
}; |
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
108 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
109 |
static bool BuildTownHouse(Town *t, TileIndex tile); |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
110 |
static void DoBuildTownHouse(Town *t, TileIndex tile); |
0 | 111 |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2430
diff
changeset
|
112 |
static void TownDrawHouseLift(const TileInfo *ti) |
0 | 113 |
{ |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
114 |
AddChildSpriteScreen(SPR_LIFT, PAL_NONE, 14, 60 - GetLiftPosition(ti->tile)); |
0 | 115 |
} |
116 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2430
diff
changeset
|
117 |
typedef void TownDrawTileProc(const TileInfo *ti); |
0 | 118 |
static TownDrawTileProc * const _town_draw_tile_procs[1] = { |
2065
c3810847175d
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
119 |
TownDrawHouseLift |
0 | 120 |
}; |
121 |
||
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
122 |
uint OriginalTileRandomiser(uint x, uint y) |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
123 |
{ |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
124 |
uint variant; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
125 |
variant = x >> 4; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
126 |
variant ^= x >> 6; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
127 |
variant ^= y >> 4; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
128 |
variant -= y >> 6; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
129 |
variant &= 3; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
130 |
return variant; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
131 |
} |
0 | 132 |
|
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
133 |
/** |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
134 |
* Return a random direction |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
135 |
* |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
136 |
* @return a random direction |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
137 |
*/ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
138 |
static inline DiagDirection RandomDiagDir() |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
139 |
{ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
140 |
return (DiagDirection)(3 & Random()); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
141 |
} |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
142 |
|
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
143 |
/** |
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
144 |
* House Tile drawing handler. |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
145 |
* Part of the tile loop process |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
146 |
* @param ti TileInfo of the tile to draw |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
147 |
*/ |
0 | 148 |
static void DrawTile_Town(TileInfo *ti) |
149 |
{ |
|
3654
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
150 |
const DrawBuildingsTileStruct *dcts; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
151 |
SpriteID image; |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
152 |
SpriteID pal; |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
153 |
HouseID house_id = GetHouseType(ti->tile); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
154 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
155 |
if (house_id >= NEW_HOUSE_OFFSET) { |
6342
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
156 |
/* Houses don't necessarily need new graphics. If they don't have a |
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
157 |
* spritegroup associated with them, then the sprite for the substitute |
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
158 |
* house id is drawn instead. */ |
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
159 |
if (GetHouseSpecs(house_id)->spritegroup != NULL) { |
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
160 |
DrawNewHouseTile(ti, house_id); |
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
161 |
return; |
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
162 |
} else { |
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
163 |
house_id = GetHouseSpecs(house_id)->substitute_id; |
a44ad9acf82a
(svn r9367) -Fix (r9315): If a new house doesn't have a corresponding action 3, the
maedhros
parents:
6341
diff
changeset
|
164 |
} |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
165 |
} |
0 | 166 |
|
167 |
/* Retrieve pointer to the draw town tile struct */ |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
168 |
dcts = &_town_draw_tile_data[house_id << 4 | OriginalTileRandomiser(ti->x, ti->y) << 2 | GetHouseBuildingStage(ti->tile)]; |
0 | 169 |
|
7335
141c6b86ec1f
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7333
diff
changeset
|
170 |
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
171 |
|
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
172 |
image = dcts->ground.sprite; |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
173 |
pal = dcts->ground.pal; |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
174 |
DrawGroundSprite(image, pal); |
0 | 175 |
|
176 |
/* Add a house on top of the ground? */ |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
177 |
image = dcts->building.sprite; |
2639 | 178 |
if (image != 0) { |
7333
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7226
diff
changeset
|
179 |
AddSortableSpriteToDraw(image, dcts->building.pal, |
482 | 180 |
ti->x + dcts->subtile_x, |
181 |
ti->y + dcts->subtile_y, |
|
7577
ab000224166b
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents:
7566
diff
changeset
|
182 |
dcts->width, |
ab000224166b
(svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents:
7566
diff
changeset
|
183 |
dcts->height, |
0 | 184 |
dcts->dz, |
7333
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7226
diff
changeset
|
185 |
ti->z, |
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7847
diff
changeset
|
186 |
IsTransparencySet(TO_HOUSES) |
4053 | 187 |
); |
0 | 188 |
|
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7847
diff
changeset
|
189 |
if (IsTransparencySet(TO_HOUSES)) return; |
0 | 190 |
} |
191 |
||
192 |
{ |
|
3654
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
193 |
int proc = dcts->draw_proc - 1; |
2639 | 194 |
|
195 |
if (proc >= 0) _town_draw_tile_procs[proc](ti); |
|
0 | 196 |
} |
197 |
} |
|
198 |
||
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
199 |
static uint GetSlopeZ_Town(TileIndex tile, uint x, uint y) |
0 | 200 |
{ |
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
201 |
return GetTileMaxZ(tile); |
0 | 202 |
} |
203 |
||
7335
141c6b86ec1f
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7333
diff
changeset
|
204 |
static Foundation GetFoundation_Town(TileIndex tile, Slope tileh) |
39 | 205 |
{ |
7335
141c6b86ec1f
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7333
diff
changeset
|
206 |
return FlatteningFoundation(tileh); |
39 | 207 |
} |
208 |
||
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
209 |
/** |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
210 |
* Animate a tile for a town |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
211 |
* Only certain houses can be animated |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
212 |
* The newhouses animation superseeds regular ones |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
213 |
* @param tile TileIndex of the house to animate |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
214 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
215 |
static void AnimateTile_Town(TileIndex tile) |
0 | 216 |
{ |
3426
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
217 |
int pos, dest; |
0 | 218 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
219 |
if (GetHouseType(tile) >= NEW_HOUSE_OFFSET) { |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
220 |
AnimateNewHouseTile(tile); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
221 |
return; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
222 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
223 |
|
2639 | 224 |
if (_tick_counter & 3) return; |
0 | 225 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
226 |
/* If the house is not one with a lift anymore, then stop this animating. |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
227 |
* Not exactly sure when this happens, but probably when a house changes. |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
228 |
* Before this was just a return...so it'd leak animated tiles.. |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
229 |
* That bug seems to have been here since day 1?? */ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
230 |
if (!(GetHouseSpecs(GetHouseType(tile))->building_flags & BUILDING_IS_ANIMATED)) { |
2065
c3810847175d
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
231 |
DeleteAnimatedTile(tile); |
c3810847175d
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
232 |
return; |
c3810847175d
(svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents:
2061
diff
changeset
|
233 |
} |
0 | 234 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
235 |
if (!LiftHasDestination(tile)) { |
2639 | 236 |
int i; |
237 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
238 |
/* Building has 6 floors, number 0 .. 6, where 1 is illegal. |
2891
7a9dbadd3f28
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
239 |
* This is due to the fact that the first floor is, in the graphics, |
7a9dbadd3f28
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
240 |
* the height of 2 'normal' floors. |
7a9dbadd3f28
(svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents:
2817
diff
changeset
|
241 |
* Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */ |
0 | 242 |
do { |
2639 | 243 |
i = (Random() & 7) - 1; |
3426
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
244 |
} while (i < 0 || i == 1 || i * 6 == GetLiftPosition(tile)); |
0 | 245 |
|
3426
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
246 |
SetLiftDestination(tile, i); |
0 | 247 |
} |
248 |
||
3426
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
249 |
pos = GetLiftPosition(tile); |
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
250 |
dest = GetLiftDestination(tile) * 6; |
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
251 |
pos += (pos < dest) ? 1 : -1; |
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
252 |
SetLiftPosition(tile, pos); |
0 | 253 |
|
3426
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
254 |
if (pos == dest) HaltLift(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
255 |
|
0 | 256 |
MarkTileDirtyByTile(tile); |
257 |
} |
|
258 |
||
259 |
static void UpdateTownRadius(Town *t); |
|
260 |
||
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
261 |
/** |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
262 |
* Determines if a town is close to a tile |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
263 |
* @param tile TileIndex of the tile to query |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
264 |
* @param dist maximum distance to be accepted |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
265 |
* @returns true if the tile correspond to the distance criteria |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
266 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
267 |
static bool IsCloseToTown(TileIndex tile, uint dist) |
0 | 268 |
{ |
2630 | 269 |
const Town* t; |
0 | 270 |
|
271 |
FOR_ALL_TOWNS(t) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
272 |
if (DistanceManhattan(tile, t->xy) < dist) return true; |
0 | 273 |
} |
274 |
return false; |
|
275 |
} |
|
276 |
||
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
277 |
/** |
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7500
diff
changeset
|
278 |
* Marks the town sign as needing a repaint. |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7500
diff
changeset
|
279 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7500
diff
changeset
|
280 |
* This function marks the area of the sign of a town as dirty for repaint. |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7500
diff
changeset
|
281 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7500
diff
changeset
|
282 |
* @param t Town requesting town sign for repaint |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7500
diff
changeset
|
283 |
* @ingroup dirty |
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
284 |
*/ |
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
285 |
static void MarkTownSignDirty(Town *t) |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
286 |
{ |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
287 |
MarkAllViewportsDirty( |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6486
diff
changeset
|
288 |
t->sign.left - 6, |
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6486
diff
changeset
|
289 |
t->sign.top - 3, |
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6486
diff
changeset
|
290 |
t->sign.left + t->sign.width_1 * 4 + 12, |
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
291 |
t->sign.top + 45 |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
292 |
); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
293 |
} |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
294 |
|
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
295 |
/** |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
296 |
* Resize the sign(label) of the town after changes in |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
297 |
* population (creation or growth or else) |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
298 |
* @param t Town to update |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
299 |
*/ |
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
300 |
void UpdateTownVirtCoord(Town *t) |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
301 |
{ |
836 | 302 |
Point pt; |
303 |
||
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
304 |
MarkTownSignDirty(t); |
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3418
diff
changeset
|
305 |
pt = RemapCoords2(TileX(t->xy) * TILE_SIZE, TileY(t->xy) * TILE_SIZE); |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2065
diff
changeset
|
306 |
SetDParam(0, t->index); |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2065
diff
changeset
|
307 |
SetDParam(1, t->population); |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2065
diff
changeset
|
308 |
UpdateViewportSignPos(&t->sign, pt.x, pt.y - 24, |
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2065
diff
changeset
|
309 |
_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL); |
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
310 |
MarkTownSignDirty(t); |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
311 |
} |
0 | 312 |
|
7969
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
313 |
/** Update the virtual coords needed to draw the town sign for all towns. */ |
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
314 |
void UpdateAllTownVirtCoords() |
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
315 |
{ |
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
316 |
Town *t; |
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
317 |
FOR_ALL_TOWNS(t) { |
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
318 |
UpdateTownVirtCoord(t); |
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
319 |
} |
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
320 |
} |
5f1292aa867f
(svn r11525) -Fix: do not do all kinds of 'updates' for town, waypoint, station and other signs when you haven't converted the map to the 'current' format as that means you are going to read data in the 'old' format when you assume that it is in the 'current' format.
rubidium
parents:
7967
diff
changeset
|
321 |
|
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
322 |
/** |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
323 |
* Change the towns population |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
324 |
* @param t Town which polulation has changed |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
325 |
* @param mod polulation change (can be positive or negative) |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
326 |
*/ |
0 | 327 |
static void ChangePopulation(Town *t, int mod) |
328 |
{ |
|
329 |
t->population += mod; |
|
330 |
InvalidateWindow(WC_TOWN_VIEW, t->index); |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
331 |
UpdateTownVirtCoord(t); |
0 | 332 |
|
333 |
if (_town_sort_order & 2) _town_sort_dirty = true; |
|
334 |
} |
|
335 |
||
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
336 |
/** |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
337 |
* Determines the world population |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
338 |
* Basically, count population of all towns, one by one |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
339 |
* @return uint32 the calculated population of the world |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
340 |
*/ |
6247 | 341 |
uint32 GetWorldPopulation() |
1080
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
342 |
{ |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
343 |
uint32 pop; |
2630 | 344 |
const Town* t; |
345 |
||
1080
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
346 |
pop = 0; |
2639 | 347 |
FOR_ALL_TOWNS(t) pop += t->population; |
1080
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
348 |
return pop; |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
349 |
} |
23797dda4792
(svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents:
1041
diff
changeset
|
350 |
|
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
351 |
/** |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
352 |
* Helper function for house completion stages progression |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
353 |
* @param tile TileIndex of the house (or parts of it) to "grow" |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
354 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
355 |
static void MakeSingleHouseBigger(TileIndex tile) |
0 | 356 |
{ |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
357 |
assert(IsTileType(tile, MP_HOUSE)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
358 |
|
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
359 |
/* means it is completed, get out. */ |
3426
451a6367552d
(svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents:
3422
diff
changeset
|
360 |
if (LiftHasDestination(tile)) return; |
0 | 361 |
|
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
362 |
/* progress in construction stages */ |
3432
650dd1972479
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
363 |
IncHouseConstructionTick(tile); |
650dd1972479
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
364 |
if (GetHouseConstructionTick(tile) != 0) return; |
0 | 365 |
|
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
366 |
/* Check and/or */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
367 |
if (HasBit(GetHouseSpecs(GetHouseType(tile))->callback_mask, CBM_HOUSE_CONSTRUCTION_STATE_CHANGE)) { |
7215
7f90af37655d
(svn r10493) -Codechange: update some callback ID enums to reflect their changed usage, add a few and update the comments.
rubidium
parents:
7139
diff
changeset
|
368 |
uint16 callback_res = GetHouseCallback(CBID_HOUSE_CONSTRUCTION_STATE_CHANGE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
369 |
if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
370 |
} |
0 | 371 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
372 |
if (IsHouseCompleted(tile)) { |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
373 |
/* Now that construction is complete, we can add the population of the |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
374 |
* building to the town. */ |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
375 |
ChangePopulation(GetTownByTile(tile), GetHouseSpecs(GetHouseType(tile))->population); |
0 | 376 |
} |
377 |
MarkTileDirtyByTile(tile); |
|
378 |
} |
|
379 |
||
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
380 |
/** Make the house advances in its construction stages until completion |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
381 |
* @param tile TileIndex of house |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
382 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
383 |
static void MakeTownHouseBigger(TileIndex tile) |
0 | 384 |
{ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
385 |
uint flags = GetHouseSpecs(GetHouseType(tile))->building_flags; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
386 |
if (flags & BUILDING_HAS_1_TILE) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0)); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
387 |
if (flags & BUILDING_2_TILES_Y) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1)); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
388 |
if (flags & BUILDING_2_TILES_X) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0)); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
389 |
if (flags & BUILDING_HAS_4_TILES) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1)); |
0 | 390 |
} |
391 |
||
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
392 |
/** |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
393 |
* Periodic tic handler for houses and town |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
394 |
* @param tile been asked to do its stuff |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
395 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
396 |
static void TileLoop_Town(TileIndex tile) |
0 | 397 |
{ |
398 |
Town *t; |
|
399 |
uint32 r; |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
400 |
HouseID house_id = GetHouseType(tile); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
401 |
HouseSpec *hs = GetHouseSpecs(house_id); |
0 | 402 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
403 |
/* NewHouseTileLoop returns false if Callback 21 succeeded, i.e. the house |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
404 |
* doesn't exist any more, so don't continue here. */ |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
405 |
if (house_id >= NEW_HOUSE_OFFSET && !NewHouseTileLoop(tile)) return; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
406 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
407 |
if (!IsHouseCompleted(tile)) { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
408 |
/* Construction is not completed. See if we can go further in construction*/ |
0 | 409 |
MakeTownHouseBigger(tile); |
410 |
return; |
|
411 |
} |
|
412 |
||
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
413 |
/* If the lift has a destination, it is already an animated tile. */ |
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
414 |
if ((hs->building_flags & BUILDING_IS_ANIMATED) && |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
415 |
house_id < NEW_HOUSE_OFFSET && |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
416 |
!LiftHasDestination(tile) && |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
417 |
Chance16(1, 2)) |
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
418 |
AddAnimatedTile(tile); |
0 | 419 |
|
3319
16c0f06829a5
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3310
diff
changeset
|
420 |
t = GetTownByTile(tile); |
0 | 421 |
|
422 |
r = Random(); |
|
423 |
||
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
424 |
if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) { |
6645
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
425 |
for (uint i = 0; i < 256; i++) { |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
426 |
uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, r, house_id, t, tile); |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
427 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
428 |
if (callback == CALLBACK_FAILED) break; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
429 |
if (callback == 0x20FF) break; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
430 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
431 |
CargoID cargo = GetCargoTranslation(GB(callback, 8, 7), hs->grffile); |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
432 |
if (cargo == CT_INVALID) continue; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
433 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
434 |
uint amt = GB(callback, 0, 8); |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
435 |
uint moved = MoveGoodsToStation(tile, 1, 1, cargo, amt); |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
436 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
437 |
const CargoSpec *cs = GetCargo(cargo); |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
438 |
switch (cs->town_effect) { |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
439 |
case TE_PASSENGERS: |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
440 |
t->new_max_pass += amt; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
441 |
t->new_act_pass += moved; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
442 |
break; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
443 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
444 |
case TE_MAIL: |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
445 |
t->new_max_mail += amt; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
446 |
t->new_act_mail += moved; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
447 |
break; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
448 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
449 |
default: |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
450 |
break; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
451 |
} |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
452 |
} |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
453 |
} else { |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
454 |
if (GB(r, 0, 8) < hs->population) { |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
455 |
uint amt = GB(r, 0, 8) / 8 + 1; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
456 |
uint moved; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
457 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
458 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
459 |
t->new_max_pass += amt; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
460 |
moved = MoveGoodsToStation(tile, 1, 1, CT_PASSENGERS, amt); |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
461 |
t->new_act_pass += moved; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
462 |
} |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
463 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
464 |
if (GB(r, 8, 8) < hs->mail_generation) { |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
465 |
uint amt = GB(r, 8, 8) / 8 + 1; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
466 |
uint moved; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
467 |
|
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
468 |
if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
469 |
t->new_max_mail += amt; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
470 |
moved = MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt); |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
471 |
t->new_act_mail += moved; |
289779d21015
(svn r9876) -Codechange: [NewHouses] Add support for callback 2E (cargo production)
peter1138
parents:
6642
diff
changeset
|
472 |
} |
0 | 473 |
} |
474 |
||
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
475 |
_current_player = OWNER_TOWN; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
476 |
|
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
477 |
if (hs->building_flags & BUILDING_HAS_1_TILE && |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
478 |
HasBit(t->flags12, TOWN_IS_FUNDED) && |
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
479 |
CanDeleteHouse(tile) && |
6605
d92f454a00a6
(svn r9823) -Feature: Add support for house property 1F - minimum life span.
maedhros
parents:
6571
diff
changeset
|
480 |
max(_cur_year - GetHouseConstructionYear(tile), 0) >= hs->minimum_life && |
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
481 |
--t->time_until_rebuild == 0) { |
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
482 |
t->time_until_rebuild = GB(r, 16, 8) + 192; |
0 | 483 |
|
484 |
ClearTownHouse(t, tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
485 |
|
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
486 |
/* Rebuild with another house? */ |
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
487 |
if (GB(r, 24, 8) >= 12) DoBuildTownHouse(t, tile); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
488 |
} |
314 | 489 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
490 |
_current_player = OWNER_NONE; |
0 | 491 |
} |
492 |
||
6534
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
493 |
/** |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
494 |
* Unused handler |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
495 |
* @param tile unused |
cbfd00fc5d88
(svn r9722) -Documentation: Document some functions of town_cmd.cpp. Loosely based on work from TheJosh
belugas
parents:
6525
diff
changeset
|
496 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
497 |
static void ClickTile_Town(TileIndex tile) |
0 | 498 |
{ |
499 |
/* not used */ |
|
500 |
} |
|
501 |
||
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
502 |
static CommandCost ClearTile_Town(TileIndex tile, byte flags) |
0 | 503 |
{ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
504 |
int rating; |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
505 |
CommandCost cost; |
0 | 506 |
Town *t; |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
507 |
HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
0 | 508 |
|
509 |
if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED); |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
510 |
if (!CanDeleteHouse(tile)) return CMD_ERROR; |
0 | 511 |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
512 |
cost.AddCost(_price.remove_house * hs->removal_cost >> 8); |
0 | 513 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
514 |
rating = hs->remove_rating_decrease; |
0 | 515 |
_cleared_town_rating += rating; |
3319
16c0f06829a5
(svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
3310
diff
changeset
|
516 |
_cleared_town = t = GetTownByTile(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
517 |
|
4850
93095755db8c
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
518 |
if (IsValidPlayer(_current_player)) { |
0 | 519 |
if (rating > t->ratings[_current_player] && !(flags & DC_NO_TOWN_RATING) && !_cheats.magic_bulldozer.value) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
520 |
SetDParam(0, t->index); |
0 | 521 |
return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
522 |
} |
0 | 523 |
} |
524 |
||
525 |
if (flags & DC_EXEC) { |
|
1005 | 526 |
ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM); |
0 | 527 |
ClearTownHouse(t, tile); |
528 |
} |
|
529 |
||
530 |
return cost; |
|
531 |
} |
|
532 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
533 |
static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac) |
0 | 534 |
{ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
535 |
HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
6525
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
536 |
CargoID accepts[3]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
537 |
|
6525
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
538 |
/* Set the initial accepted cargo types */ |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
539 |
for (uint8 i = 0; i < lengthof(accepts); i++) { |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
540 |
accepts[i] = hs->accepts_cargo[i]; |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
541 |
} |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
542 |
|
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
543 |
/* Check for custom accepted cargo types */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
544 |
if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) { |
6642
ced51f7c19aa
(svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents:
6629
diff
changeset
|
545 |
uint16 callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
6525
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
546 |
if (callback != CALLBACK_FAILED) { |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
547 |
/* Replace accepted cargo types with translated values from callback */ |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
548 |
accepts[0] = GetCargoTranslation(GB(callback, 0, 5), hs->grffile); |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
549 |
accepts[1] = GetCargoTranslation(GB(callback, 5, 5), hs->grffile); |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
550 |
accepts[2] = GetCargoTranslation(GB(callback, 10, 5), hs->grffile); |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
551 |
} |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
552 |
} |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
553 |
|
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
554 |
/* Check for custom cargo acceptance */ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
555 |
if (HasBit(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) { |
6642
ced51f7c19aa
(svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents:
6629
diff
changeset
|
556 |
uint16 callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
6525
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
557 |
if (callback != CALLBACK_FAILED) { |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
558 |
if (accepts[0] != CT_INVALID) ac[accepts[0]] = GB(callback, 0, 4); |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
559 |
if (accepts[1] != CT_INVALID) ac[accepts[1]] = GB(callback, 4, 4); |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
560 |
if (_opt.landscape != LT_TEMPERATE && HasBit(callback, 12)) { |
6525
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
561 |
/* The 'S' bit indicates food instead of goods */ |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
562 |
ac[CT_FOOD] = GB(callback, 8, 4); |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
563 |
} else { |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
564 |
if (accepts[2] != CT_INVALID) ac[accepts[2]] = GB(callback, 8, 4); |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
565 |
} |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
566 |
return; |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
567 |
} |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
568 |
} |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
569 |
|
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
570 |
/* No custom acceptance, so fill in with the default values */ |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
571 |
for (uint8 i = 0; i < lengthof(accepts); i++) { |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
572 |
if (accepts[i] != CT_INVALID) ac[accepts[i]] = hs->cargo_acceptance[i]; |
a21429c6f16f
(svn r9712) -Codechange: Implement accepted cargo types and cargo acceptance (there is a difference) callbacks for newhouses.
peter1138
parents:
6491
diff
changeset
|
573 |
} |
0 | 574 |
} |
575 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
576 |
static void GetTileDesc_Town(TileIndex tile, TileDesc *td) |
0 | 577 |
{ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
578 |
td->str = GetHouseSpecs(GetHouseType(tile))->building_name; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
579 |
if (!IsHouseCompleted(tile)) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
580 |
SetDParamX(td->dparam, 0, td->str); |
0 | 581 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
582 |
} |
|
583 |
||
584 |
td->owner = OWNER_TOWN; |
|
585 |
} |
|
586 |
||
6683
b88ae30866ce
(svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents:
6661
diff
changeset
|
587 |
static uint32 GetTileTrackStatus_Town(TileIndex tile, TransportType mode, uint sub_mode) |
0 | 588 |
{ |
589 |
/* not used */ |
|
590 |
return 0; |
|
591 |
} |
|
592 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2430
diff
changeset
|
593 |
static void ChangeTileOwner_Town(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 594 |
{ |
595 |
/* not used */ |
|
596 |
} |
|
597 |
||
2817 | 598 |
static bool GrowTown(Town *t); |
599 |
||
0 | 600 |
static void TownTickHandler(Town *t) |
601 |
{ |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
602 |
if (HasBit(t->flags12, TOWN_IS_FUNDED)) { |
0 | 603 |
int i = t->grow_counter - 1; |
604 |
if (i < 0) { |
|
605 |
if (GrowTown(t)) { |
|
606 |
i = t->growth_rate; |
|
607 |
} else { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
608 |
i = 0; |
0 | 609 |
} |
610 |
} |
|
611 |
t->grow_counter = i; |
|
612 |
} |
|
613 |
||
614 |
UpdateTownRadius(t); |
|
615 |
} |
|
616 |
||
6247 | 617 |
void OnTick_Town() |
0 | 618 |
{ |
2639 | 619 |
if (_game_mode == GM_EDITOR) return; |
0 | 620 |
|
1451
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
621 |
/* Make sure each town's tickhandler invocation frequency is about the |
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
622 |
* same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */ |
5247
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
623 |
for (_cur_town_iter += GetMaxTownIndex() + 1; |
1529
3a8196d15b01
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
624 |
_cur_town_iter >= TOWN_GROWTH_FREQUENCY; |
3a8196d15b01
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
625 |
_cur_town_iter -= TOWN_GROWTH_FREQUENCY) { |
1517
596d52828893
(svn r2021) Fix: Enlarge _cur_town_ctr from byte to uint32 so that all the towns are considered when growing them even for big maps, where much more than 256 towns are around; reported by Tomasz Dubi?ski <uboottd@hydra.polsl.gliwice.pl>. The savegame still saves just the lowest 8 bits but that doesn't hurt so much.
pasky
parents:
1500
diff
changeset
|
626 |
uint32 i = _cur_town_ctr; |
1451
eb24b5a58340
(svn r1955) Fix: Make the town growth frequency scale properly both up and down. The scaling is now also based on the number of towns instead of the map size. (In cooperation with HackyKid.)
pasky
parents:
1448
diff
changeset
|
627 |
|
5247
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
628 |
if (++_cur_town_ctr > GetMaxTownIndex()) |
1448
472b3b3855e7
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
629 |
_cur_town_ctr = 0; |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
630 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
631 |
if (IsValidTownID(i)) TownTickHandler(GetTown(i)); |
1448
472b3b3855e7
(svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents:
1421
diff
changeset
|
632 |
} |
0 | 633 |
} |
634 |
||
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
635 |
/** |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
636 |
* Return the RoadBits of a tile |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
637 |
* |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
638 |
* @note There are many other functions doing things like that. |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
639 |
* @note Needs to be checked for needlessness. |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
640 |
* @param tile The tile we want to analyse |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
641 |
* @return The roadbits of the given tile |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
642 |
*/ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
643 |
static RoadBits GetTownRoadBits(TileIndex tile) |
0 | 644 |
{ |
6661
1716fce5ad29
(svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents:
6645
diff
changeset
|
645 |
TrackBits b = GetAnyRoadTrackBits(tile, ROADTYPE_ROAD); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
646 |
RoadBits r = ROAD_NONE; |
2639 | 647 |
|
7225
9d9a1e554903
(svn r10504) -Codechange: Shorten the test if no track bit has been found
belugas
parents:
7215
diff
changeset
|
648 |
if (b == TRACK_BIT_NONE) return r; |
3150
729951cb5448
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
649 |
if (b & TRACK_BIT_X) r |= ROAD_X; |
729951cb5448
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
650 |
if (b & TRACK_BIT_Y) r |= ROAD_Y; |
729951cb5448
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
651 |
if (b & TRACK_BIT_UPPER) r |= ROAD_NE | ROAD_NW; |
729951cb5448
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
652 |
if (b & TRACK_BIT_LOWER) r |= ROAD_SE | ROAD_SW; |
729951cb5448
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
653 |
if (b & TRACK_BIT_LEFT) r |= ROAD_NW | ROAD_SW; |
729951cb5448
(svn r3773) Shove some semantics down ottd's throat by replacing ints and magic numbers by enums and some related changes
tron
parents:
3144
diff
changeset
|
654 |
if (b & TRACK_BIT_RIGHT) r |= ROAD_NE | ROAD_SE; |
0 | 655 |
return r; |
656 |
} |
|
657 |
||
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
658 |
/** |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
659 |
* Check if a neighboring tile has a road |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
660 |
* |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
661 |
* @param tile curent tile |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
662 |
* @param dir target direction |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
663 |
* @param dist_multi distance multiplyer |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
664 |
* @return true if one of the neighboring tiles at the |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
665 |
* given distance is a road tile else false |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
666 |
*/ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
667 |
static bool IsNeighborRoadTile(TileIndex tile, DiagDirection dir, uint dist_multi) |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
668 |
{ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
669 |
static TileIndexDiff tid_lt[3]; // lookup table for the used diff values |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
670 |
tid_lt[0] = TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT)); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
671 |
tid_lt[1] = TileOffsByDiagDir(ChangeDiagDir(dir, DIAGDIRDIFF_90LEFT)); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
672 |
tid_lt[2] = TileOffsByDiagDir(ReverseDiagDir(dir)); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
673 |
|
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
674 |
/* We add 1 to the distance because we want to get 1 for |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
675 |
* the min distance multiplyer and not 0. |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
676 |
* Therefore we start at 4. The 4 is used because |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
677 |
* there are 4 tiles per distance step to check. |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
678 |
*/ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
679 |
dist_multi = (dist_multi + 1) * 4; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
680 |
for (uint pos = 4; pos < dist_multi; pos++) { |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
681 |
TileIndexDiff cur = 0; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
682 |
/* For each even value of pos add the right TileIndexDiff |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
683 |
* for each uneven value the left TileIndexDiff |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
684 |
* for each with 2nd bit set (2,3,6,7,..) add the reversed TileIndexDiff |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
685 |
*/ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
686 |
cur += tid_lt[(pos & 1) ? 0 : 1]; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
687 |
if (pos & 2) cur += tid_lt[2]; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
688 |
|
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
689 |
cur = (uint)(pos / 4) * cur; // Multiply for the fitting distance |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
690 |
if (GetTownRoadBits(TILE_ADD(tile, cur)) & DiagDirToRoadBits((pos & 2) ? dir : ReverseDiagDir(dir))) return true; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
691 |
} |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
692 |
return false; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
693 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
694 |
|
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
695 |
/** |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
696 |
* Check if a Road is allowed on a given tile |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
697 |
* |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
698 |
* @param tile The target tile |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
699 |
* @param dir The direction in which we want to extend the town |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
700 |
* @return true if it is allowed else false |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
701 |
*/ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
702 |
static bool IsRoadAllowedHere(TileIndex tile, DiagDirection dir) |
0 | 703 |
{ |
7226
3e15150d5a23
(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
parents:
7225
diff
changeset
|
704 |
if (TileX(tile) < 2 || TileY(tile) < 2 || MapMaxX() <= TileX(tile) || MapMaxY() <= TileY(tile)) return false; |
6993
96260dbb34d6
(svn r10249) -Fix [FS#906]: town tried to gather information about the neighbourhood of a tile when it couldn't even *ever* build on that tile.
rubidium
parents:
6956
diff
changeset
|
705 |
|
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
706 |
Slope cur_slope, desired_slope; |
0 | 707 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
708 |
/* If this assertion fails, it might be because the world contains |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
709 |
* land at the edges. This is not ok. */ |
0 | 710 |
TILE_ASSERT(tile); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
711 |
|
2639 | 712 |
for (;;) { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
713 |
/* Check if there already is a road at this point? */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
714 |
if (GetTownRoadBits(tile) == ROAD_NONE) { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
715 |
/* No, try to build one in the direction. |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
716 |
* if that fails clear the land, and if that fails exit. |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
717 |
* This is to make sure that we can build a road here later. */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
718 |
if (CmdFailed(DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) && |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
719 |
CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) |
0 | 720 |
return false; |
721 |
} |
|
722 |
||
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
723 |
cur_slope = GetTileSlope(tile, NULL); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
724 |
if (cur_slope == SLOPE_FLAT) { |
465
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
725 |
no_slope: |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
726 |
/* Tile has no slope */ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
727 |
switch (_patches.town_layout) { |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
728 |
default: NOT_REACHED(); |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
729 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
730 |
case TL_ORIGINAL: /* Disallow the road if any neighboring tile has a road (distance: 1) */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
731 |
return !IsNeighborRoadTile(tile, dir, 1); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
732 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
733 |
case TL_BETTER_ROADS: /* Disallow the road if any neighboring tile has a road (distance: 1 and 2). */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
734 |
return !IsNeighborRoadTile(tile, dir, 2); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
735 |
} |
0 | 736 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
737 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
738 |
/* If the tile is not a slope in the right direction, then |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
739 |
* maybe terraform some. */ |
7885
706462b6f293
(svn r11436) -Fix [FS#1439]: Towns would not build roads on slopes. Patch by divide.
rubidium
parents:
7880
diff
changeset
|
740 |
desired_slope = (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? SLOPE_NW : SLOPE_NE; |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
741 |
if (desired_slope != cur_slope && ComplementSlope(desired_slope) != cur_slope) { |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
742 |
if (Chance16(1, 8)) { |
7766
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
743 |
CommandCost res = CMD_ERROR; |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
744 |
if (!_generating_world && Chance16(1, 10)) { |
7480
1ae973d5f341
(svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents:
7413
diff
changeset
|
745 |
/* Note: Do not replace " ^ 0xF" with ComplementSlope(). The slope might be steep. */ |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
746 |
res = DoCommand(tile, Chance16(1, 16) ? cur_slope : cur_slope ^ 0xF, 0, |
7766
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
747 |
DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
2639 | 748 |
} |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
749 |
if (CmdFailed(res) && Chance16(1, 3)) { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
750 |
/* We can consider building on the slope, though. */ |
465
21f9985e12d1
(svn r694) Make the town sometimes build streets on slopes.
pasky
parents:
314
diff
changeset
|
751 |
goto no_slope; |
2646
c01dfbc7b7e3
(svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents:
2639
diff
changeset
|
752 |
} |
0 | 753 |
} |
754 |
return false; |
|
755 |
} |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
756 |
return true; |
0 | 757 |
} |
758 |
} |
|
759 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
760 |
static bool TerraformTownTile(TileIndex tile, int edges, int dir) |
0 | 761 |
{ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
762 |
CommandCost r; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
763 |
|
0 | 764 |
TILE_ASSERT(tile); |
765 |
||
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
766 |
r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND); |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
767 |
if (CmdFailed(r) || r.GetCost() >= 126 * 16) return false; |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
768 |
DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND); |
0 | 769 |
return true; |
770 |
} |
|
771 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
772 |
static void LevelTownLand(TileIndex tile) |
0 | 773 |
{ |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
774 |
Slope tileh; |
0 | 775 |
|
776 |
TILE_ASSERT(tile); |
|
777 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
778 |
/* Don't terraform if land is plain or if there's a house there. */ |
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
779 |
if (IsTileType(tile, MP_HOUSE)) return; |
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
780 |
tileh = GetTileSlope(tile, NULL); |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
781 |
if (tileh == SLOPE_FLAT) return; |
0 | 782 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
783 |
/* First try up, then down */ |
3055
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
784 |
if (!TerraformTownTile(tile, ~tileh & 0xF, 1)) { |
ed20cba49858
(svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents:
3047
diff
changeset
|
785 |
TerraformTownTile(tile, tileh & 0xF, 0); |
0 | 786 |
} |
787 |
} |
|
788 |
||
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
789 |
/** |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
790 |
* Generate the RoadBits of a grid tile |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
791 |
* |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
792 |
* @param t current town |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
793 |
* @param tile tile in reference to the town |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
794 |
* @param dir The direction to which we are growing ATM |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
795 |
* @return the RoadBit of the current tile regarding |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
796 |
* the selected town layout |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
797 |
*/ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
798 |
static RoadBits GetTownRoadGridElement(Town* t, TileIndex tile, DiagDirection dir) |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
799 |
{ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
800 |
/* align the grid to the downtown */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
801 |
TileIndexDiffC grid_pos = TileIndexToTileIndexDiffC(t->xy, tile); // Vector from downtown to the tile |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
802 |
RoadBits rcmd = ROAD_NONE; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
803 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
804 |
switch (_patches.town_layout) { |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
805 |
default: NOT_REACHED(); |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
806 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
807 |
case TL_2X2_GRID: |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
808 |
if ((grid_pos.x % 3) == 0) rcmd |= ROAD_Y; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
809 |
if ((grid_pos.y % 3) == 0) rcmd |= ROAD_X; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
810 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
811 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
812 |
case TL_3X3_GRID: |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
813 |
if ((grid_pos.x % 4) == 0) rcmd |= ROAD_Y; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
814 |
if ((grid_pos.y % 4) == 0) rcmd |= ROAD_X; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
815 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
816 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
817 |
|
7603
1f067a18eb61
(svn r11130) -Fix [FS#1207]: towns build roads that weren't connected to any other road.
rubidium
parents:
7582
diff
changeset
|
818 |
/* Optimise only X-junctions */ |
7766
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
819 |
if (rcmd != ROAD_ALL) return rcmd; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
820 |
|
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
821 |
RoadBits rb_template; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
822 |
|
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
823 |
switch (GetTileSlope(tile, NULL)) { |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
824 |
default: rb_template = ROAD_ALL; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
825 |
case SLOPE_W: rb_template = ROAD_NW | ROAD_SW; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
826 |
case SLOPE_SW: rb_template = ROAD_Y | ROAD_SW; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
827 |
case SLOPE_S: rb_template = ROAD_SW | ROAD_SE; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
828 |
case SLOPE_SE: rb_template = ROAD_X | ROAD_SE; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
829 |
case SLOPE_E: rb_template = ROAD_SE | ROAD_NE; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
830 |
case SLOPE_NE: rb_template = ROAD_Y | ROAD_NE; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
831 |
case SLOPE_N: rb_template = ROAD_NE | ROAD_NW; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
832 |
case SLOPE_NW: rb_template = ROAD_X | ROAD_NW; break; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
833 |
case SLOPE_STEEP_W: |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
834 |
case SLOPE_STEEP_S: |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
835 |
case SLOPE_STEEP_E: |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
836 |
case SLOPE_STEEP_N: |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
837 |
rb_template = ROAD_NONE; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
838 |
break; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
839 |
} |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
840 |
|
7766
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
841 |
/* Stop if the template is compatible to the growth dir */ |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
842 |
if (DiagDirToRoadBits(ReverseDiagDir(dir)) & rb_template) return rb_template; |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
843 |
/* If not generate a straight road in the direction of the growth */ |
4b94147f4bfa
(svn r11315) -Fix [FS#1353]: towns are not growing beyond height differences. Patch by skidd13.
rubidium
parents:
7762
diff
changeset
|
844 |
return DiagDirToRoadBits(dir) | DiagDirToRoadBits(ReverseDiagDir(dir)); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
845 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
846 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
847 |
/** |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
848 |
* Grows the town with an extra house. |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
849 |
* Check if there are enough neighbor house tiles |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
850 |
* next to the current tile. If there are enough |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
851 |
* add another house. |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
852 |
* |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
853 |
* @param t The current town |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
854 |
* @param tile The target tile for the extra house |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
855 |
* @return true if an extra house has been added |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
856 |
*/ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
857 |
static bool GrowTownWithExtraHouse(Town *t, TileIndex tile) |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
858 |
{ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
859 |
/* We can't look further than that. */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
860 |
if (TileX(tile) < 2 || TileY(tile) < 2 || MapMaxX() <= TileX(tile) || MapMaxY() <= TileY(tile)) return false; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
861 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
862 |
uint counter = 0; // counts the house neighbor tiles |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
863 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
864 |
/* Check the tiles E,N,W and S of the current tile for houses */ |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
865 |
for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
866 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
867 |
if (IsTileType(TileAddByDiagDir(tile, dir), MP_HOUSE)) counter++; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
868 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
869 |
/* If there are enough neighbors stop here */ |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
870 |
if (counter >= 3) { |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
871 |
if (BuildTownHouse(t, tile)) { |
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
872 |
_grow_town_result = GROWTH_SUCCEED; |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
873 |
return true; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
874 |
} |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
875 |
return false; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
876 |
} |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
877 |
} |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
878 |
return false; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
879 |
} |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
880 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
881 |
/** |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
882 |
* Grows the town with a road piece. |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
883 |
* |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
884 |
* @param t The current town |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
885 |
* @param tile The current tile |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
886 |
* @param rcmd The RoadBits we want to build on the tile |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
887 |
* @return true if the RoadBits have been added else false |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
888 |
*/ |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
889 |
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd) |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
890 |
{ |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
891 |
if (CmdSucceeded(DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) { |
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
892 |
_grow_town_result = GROWTH_SUCCEED; |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
893 |
return true; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
894 |
} |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
895 |
return false; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
896 |
} |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
897 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
898 |
/** |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
899 |
* Grows the town with a bridge. |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
900 |
* At first we check if a bridge is reasonable. |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
901 |
* If so we check if we are able to build it. |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
902 |
* |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
903 |
* @param t The current town |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
904 |
* @param tile The current tile |
7845
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
905 |
* @param bridge_dir The valid direction in which to grow a bridge |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
906 |
* @return true if a bridge has been build else false |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
907 |
*/ |
7845
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
908 |
static bool GrowTownWithBridge(const Town *t, TileIndex tile, DiagDirection bridge_dir) |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
909 |
{ |
7845
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
910 |
assert(bridge_dir < DIAGDIR_END); |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
911 |
|
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
912 |
const Slope slope = GetTileSlope(tile, NULL); |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
913 |
if (slope == SLOPE_FLAT) return false; // no slope, no bridge |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
914 |
|
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
915 |
/* Make sure the direction is compatible with the slope. |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
916 |
* If any of the following bits match, the slope is forbidden for |
7847
76271a2885d5
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
7845
diff
changeset
|
917 |
* that diagdir. This means 5 non-steep slopes, and 3 steep-slopes |
76271a2885d5
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
7845
diff
changeset
|
918 |
* per diagdir. |
7845
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
919 |
* 0 -> 0b1100 |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
920 |
* 1 -> 0b0110 |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
921 |
* 2 -> 0b0011 |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
922 |
* 3 -> 0b1001 |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
923 |
* 0xCC is 0b11001100, so we just shift it right with |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
924 |
* the direction to get the forbidden slope mask. */ |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
925 |
if (HASBITS(slope & 0x0F, 0xCC >> bridge_dir)) return false; |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
926 |
|
7847
76271a2885d5
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
7845
diff
changeset
|
927 |
/* Assure that the bridge is connectable to the start side */ |
76271a2885d5
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
7845
diff
changeset
|
928 |
if (!(GetTownRoadBits(TileAddByDiagDir(tile, ReverseDiagDir(bridge_dir))) & DiagDirToRoadBits(bridge_dir))) return false; |
76271a2885d5
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
7845
diff
changeset
|
929 |
|
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
930 |
/* We are in the right direction */ |
7847
76271a2885d5
(svn r11397) -Fix r11395: some minor fixes for better town-bridge results (and better comments) (skidd13 / TrueLight)
truelight
parents:
7845
diff
changeset
|
931 |
uint8 bridge_length = 0; // This value stores the length of the possible bridge |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
932 |
TileIndex bridge_tile = tile; // Used to store the other waterside |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
933 |
|
7871
4e5b81629881
(svn r11421) -Fix [FS#1431]: do not use a function that asserts when wrapping around the map's edge when you use the wrapping (and MP_VOID tiles) to determine whether the bridge can be build.
rubidium
parents:
7849
diff
changeset
|
934 |
int delta = TileOffsByDiagDir(bridge_dir); |
4e5b81629881
(svn r11421) -Fix [FS#1431]: do not use a function that asserts when wrapping around the map's edge when you use the wrapping (and MP_VOID tiles) to determine whether the bridge can be build.
rubidium
parents:
7849
diff
changeset
|
935 |
|
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
936 |
do { |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
937 |
if (bridge_length++ >= 11) { |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
938 |
/* Max 11 tile long bridges */ |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
939 |
return false; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
940 |
} |
7871
4e5b81629881
(svn r11421) -Fix [FS#1431]: do not use a function that asserts when wrapping around the map's edge when you use the wrapping (and MP_VOID tiles) to determine whether the bridge can be build.
rubidium
parents:
7849
diff
changeset
|
941 |
bridge_tile += delta; |
7880
f2815bd2ae83
(svn r11430) -Fix (r11421) [FS#1421]: there was still one case that would cause a crash...
rubidium
parents:
7871
diff
changeset
|
942 |
} while (TileX(bridge_tile) != 0 && TileY(bridge_tile) != 0 && IsWaterTile(bridge_tile) && TileX(bridge_tile) != 0); |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
943 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
944 |
/* no water tiles in between? */ |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
945 |
if (bridge_length == 1) return false; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
946 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
947 |
for (uint8 times = 0; times <= 22; times++) { |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
948 |
byte bridge_type = RandomRange(MAX_BRIDGES - 1); |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
949 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
950 |
/* Can we actually build the bridge? */ |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
951 |
if (CmdSucceeded(DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE))) { |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
952 |
DoCommand(tile, bridge_tile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE); |
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
953 |
_grow_town_result = GROWTH_SUCCEED; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
954 |
return true; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
955 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
956 |
} |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
957 |
/* Quit if it selecting an appropiate bridge type fails a large number of times. */ |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
958 |
return false; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
959 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
960 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
961 |
/** |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
962 |
* Grows the given town. |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
963 |
* There are at the moment 3 possible way's for |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
964 |
* the town expansion: |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
965 |
* @li Generate a random tile and check if there is a road allowed |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
966 |
* @li TL_ORIGINAL |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
967 |
* @li TL_BETTER_ROADS |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
968 |
* @li Check if the town geometry allows a road and which one |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
969 |
* @li TL_2X2_GRID |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
970 |
* @li TL_3X3_GRID |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
971 |
* @li Forbid roads, only build houses |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
972 |
* @li TL_NO_ROADS |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
973 |
* |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
974 |
* @param tile_ptr The current tile |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
975 |
* @param cur_rb The current tiles RoadBits |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
976 |
* @param target_dir The target road dir |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
977 |
* @param t1 The current town |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
978 |
*/ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
979 |
static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection target_dir, Town *t1) |
0 | 980 |
{ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
981 |
RoadBits rcmd = ROAD_NONE; // RoadBits for the road construction command |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
982 |
TileIndex tile = *tile_ptr; // The main tile on which we base our growth |
0 | 983 |
|
984 |
TILE_ASSERT(tile); |
|
985 |
||
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
986 |
if (cur_rb == ROAD_NONE) { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
987 |
/* Tile has no road. First reset the status counter |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
988 |
* to say that this is the last iteration. */ |
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
989 |
_grow_town_result = GROWTH_SEARCH_STOPPED; |
0 | 990 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
991 |
/* Remove hills etc */ |
0 | 992 |
LevelTownLand(tile); |
993 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
994 |
/* Is a road allowed here? */ |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
995 |
switch (_patches.town_layout) { |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
996 |
default: NOT_REACHED(); |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
997 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
998 |
case TL_NO_ROADS: /* Disallow Roads */ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
999 |
return; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1000 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1001 |
case TL_3X3_GRID: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1002 |
case TL_2X2_GRID: |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1003 |
rcmd = GetTownRoadGridElement(t1, tile, target_dir); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1004 |
if (rcmd == ROAD_NONE) return; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1005 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1006 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1007 |
case TL_BETTER_ROADS: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1008 |
case TL_ORIGINAL: |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1009 |
if (!IsRoadAllowedHere(tile, target_dir)) return; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1010 |
|
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1011 |
DiagDirection source_dir = ReverseDiagDir(target_dir); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1012 |
|
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
1013 |
if (Chance16(1, 4)) { |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1014 |
/* Randomize a new target dir */ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1015 |
do target_dir = RandomDiagDir(); while (target_dir == source_dir); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1016 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1017 |
|
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1018 |
if (!IsRoadAllowedHere(TileAddByDiagDir(tile, target_dir), target_dir)) { |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1019 |
/* A road is not allowed to continue the randomized road, |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1020 |
* return if the road we're trying to build is curved. */ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1021 |
if (target_dir != ReverseDiagDir(source_dir)) return; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1022 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1023 |
/* Return if neither side of the new road is a house */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1024 |
if (!IsTileType(TileAddByDiagDir(tile, ChangeDiagDir(target_dir, DIAGDIRDIFF_90RIGHT)), MP_HOUSE) && |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1025 |
!IsTileType(TileAddByDiagDir(tile, ChangeDiagDir(target_dir, DIAGDIRDIFF_90LEFT)), MP_HOUSE)) { |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1026 |
return; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1027 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1028 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1029 |
/* That means that the road is only allowed if there is a house |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1030 |
* at any side of the new road. */ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1031 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1032 |
|
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1033 |
rcmd = DiagDirToRoadBits(target_dir) | DiagDirToRoadBits(source_dir); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1034 |
break; |
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2635
diff
changeset
|
1035 |
} |
0 | 1036 |
|
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1037 |
} else if (target_dir < DIAGDIR_END && !(cur_rb & DiagDirToRoadBits(ReverseDiagDir(target_dir)))) { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1038 |
/* Continue building on a partial road. |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1039 |
* Should be allways OK, so we only generate |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1040 |
* the fitting RoadBits */ |
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
1041 |
_grow_town_result = GROWTH_SEARCH_STOPPED; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1042 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1043 |
switch (_patches.town_layout) { |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1044 |
default: NOT_REACHED(); |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1045 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1046 |
case TL_NO_ROADS: /* Disallow Roads */ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1047 |
return; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1048 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1049 |
case TL_3X3_GRID: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1050 |
case TL_2X2_GRID: |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1051 |
rcmd = GetTownRoadGridElement(t1, tile, target_dir); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1052 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1053 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1054 |
case TL_BETTER_ROADS: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1055 |
case TL_ORIGINAL: |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1056 |
rcmd = DiagDirToRoadBits(ReverseDiagDir(target_dir)); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1057 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1058 |
} |
0 | 1059 |
} else { |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1060 |
bool allow_house = false; // Value which decides if we want to construct a house |
0 | 1061 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1062 |
/* Reached a tunnel/bridge? Then continue at the other side of it. */ |
5445
0e8698f61eeb
(svn r7698) -Fix (r7573): towns did not grow beyond bridges.
rubidium
parents:
5385
diff
changeset
|
1063 |
if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
8088
92fca5b09665
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents:
8083
diff
changeset
|
1064 |
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) { |
92fca5b09665
(svn r11649) -Codechange: some code can be simplified thanks to changes in r11642
smatz
parents:
8083
diff
changeset
|
1065 |
*tile_ptr = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile); |
5445
0e8698f61eeb
(svn r7698) -Fix (r7573): towns did not grow beyond bridges.
rubidium
parents:
5385
diff
changeset
|
1066 |
} |
0 | 1067 |
return; |
1068 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1069 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1070 |
/* Possibly extend the road in a direction. |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1071 |
* Randomize a direction and if it has a road, bail out. */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1072 |
target_dir = RandomDiagDir(); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1073 |
if (cur_rb & DiagDirToRoadBits(target_dir)) return; |
0 | 1074 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1075 |
/* This is the tile we will reach if we extend to this direction. */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1076 |
TileIndex house_tile = TileAddByDiagDir(tile, target_dir); // position of a possible house |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1077 |
|
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1078 |
/* Don't walk into water. */ |
7739
0b6f3da5c083
(svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents:
7709
diff
changeset
|
1079 |
if (IsWaterTile(house_tile)) return; |
0 | 1080 |
|
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1081 |
switch (_patches.town_layout) { |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1082 |
default: NOT_REACHED(); |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1083 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1084 |
case TL_NO_ROADS: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1085 |
allow_house = true; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1086 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1087 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1088 |
case TL_3X3_GRID: /* Use 2x2 grid afterwards! */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1089 |
GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir)); |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1090 |
/* FALL THROUGH */ |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1091 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1092 |
case TL_2X2_GRID: |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1093 |
rcmd = GetTownRoadGridElement(t1, house_tile, target_dir); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1094 |
allow_house = (rcmd == ROAD_NONE); |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1095 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1096 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1097 |
case TL_BETTER_ROADS: /* Use original afterwards! */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1098 |
GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir)); |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1099 |
/* FALL THROUGH */ |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1100 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1101 |
case TL_ORIGINAL: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1102 |
/* Allow a house at the edge. 60% chance or |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1103 |
* always ok if no road allowed. */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1104 |
rcmd = DiagDirToRoadBits(target_dir); |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
1105 |
allow_house = (!IsRoadAllowedHere(house_tile, target_dir) || Chance16(6, 10)); |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1106 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1107 |
} |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1108 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1109 |
if (allow_house) { |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1110 |
/* Build a house, but not if there already is a house there. */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1111 |
if (!IsTileType(house_tile, MP_HOUSE)) { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1112 |
/* Level the land if possible */ |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
1113 |
if (Chance16(1, 6)) LevelTownLand(house_tile); |
0 | 1114 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1115 |
/* And build a house. |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1116 |
* Set result to -1 if we managed to build it. */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1117 |
if (BuildTownHouse(t1, house_tile)) { |
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
1118 |
_grow_town_result = GROWTH_SUCCEED; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1119 |
} |
0 | 1120 |
} |
1121 |
return; |
|
1122 |
} |
|
1123 |
||
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
1124 |
_grow_town_result = GROWTH_SEARCH_STOPPED; |
0 | 1125 |
} |
1126 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1127 |
/* Return if a water tile */ |
7739
0b6f3da5c083
(svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents:
7709
diff
changeset
|
1128 |
if (IsWaterTile(tile)) return; |
0 | 1129 |
|
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1130 |
/* Make the roads look nicer */ |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1131 |
rcmd = CleanUpRoadBits(tile, rcmd); |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1132 |
if (rcmd == ROAD_NONE) return; |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1133 |
|
7845
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
1134 |
/* Only use the target direction for bridges to ensure they're connected. |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
1135 |
* The target_dir is as computed previously according to town layout, so |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
1136 |
* it will match it perfectly. */ |
4e5c90c389ca
(svn r11395) -Fix: allow town-bridges to be build on slopes (Rafal Rzepecki)
truelight
parents:
7766
diff
changeset
|
1137 |
if (GrowTownWithBridge(t1, tile, target_dir)) return; |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1138 |
|
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1139 |
GrowTownWithRoad(t1, tile, rcmd); |
0 | 1140 |
} |
1141 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1142 |
/** Returns "growth" if a house was built, or no if the build failed. |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1143 |
* @param t town to inquiry |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1144 |
* @param tile to inquiry |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1145 |
* @return something other than zero(0)if town expansion was possible |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1146 |
*/ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1147 |
static int GrowTownAtRoad(Town *t, TileIndex tile) |
0 | 1148 |
{ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1149 |
/* Special case. |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1150 |
* @see GrowTownInTile Check the else if |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1151 |
*/ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1152 |
DiagDirection target_dir = DIAGDIR_END; // The direction in which we want to extend the town |
0 | 1153 |
|
1154 |
TILE_ASSERT(tile); |
|
1155 |
||
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1156 |
/* Number of times to search. |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1157 |
* Better roads, 2X2 and 3X3 grid grow quite fast so we give |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1158 |
* them a little handicap. */ |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1159 |
switch (_patches.town_layout) { |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1160 |
case TL_BETTER_ROADS: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1161 |
_grow_town_result = 10 + t->num_houses * 2 / 9; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1162 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1163 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1164 |
case TL_3X3_GRID: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1165 |
case TL_2X2_GRID: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1166 |
_grow_town_result = 10 + t->num_houses * 1 / 9; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1167 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1168 |
|
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1169 |
default: |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1170 |
_grow_town_result = 10 + t->num_houses * 4 / 9; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1171 |
break; |
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1172 |
} |
0 | 1173 |
|
1174 |
do { |
|
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1175 |
RoadBits cur_rb = GetTownRoadBits(tile); // The RoadBits of the current tile |
0 | 1176 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1177 |
/* Try to grow the town from this point */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1178 |
GrowTownInTile(&tile, cur_rb, target_dir, t); |
0 | 1179 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1180 |
/* Exclude the source position from the bitmask |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1181 |
* and return if no more road blocks available */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1182 |
cur_rb &= ~DiagDirToRoadBits(ReverseDiagDir(target_dir)); |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1183 |
if (cur_rb == ROAD_NONE) |
0 | 1184 |
return _grow_town_result; |
1185 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1186 |
/* Select a random bit from the blockmask, walk a step |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1187 |
* and continue the search from there. */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1188 |
do target_dir = RandomDiagDir(); while (!(cur_rb & DiagDirToRoadBits(target_dir))); |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1189 |
tile = TileAddByDiagDir(tile, target_dir); |
0 | 1190 |
|
7370
41adc721b1fa
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7335
diff
changeset
|
1191 |
if (IsTileType(tile, MP_ROAD)) { |
1327
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
1192 |
/* Don't allow building over roads of other cities */ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4053
diff
changeset
|
1193 |
if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t) { |
7684
a79c09246c27
(svn r11215) -Codechange: replace magic constants with less magic symbols. Patch by skidd13.
rubidium
parents:
7666
diff
changeset
|
1194 |
_grow_town_result = GROWTH_SUCCEED; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4053
diff
changeset
|
1195 |
} else if (_game_mode == GM_EDITOR) { |
1327
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
1196 |
/* If we are in the SE, and this road-piece has no town owner yet, it just found an |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
1197 |
* owner :) (happy happy happy road now) */ |
1902 | 1198 |
SetTileOwner(tile, OWNER_TOWN); |
3432
650dd1972479
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1199 |
SetTownIndex(tile, t->index); |
1327
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
1200 |
} |
6e507eb10edd
(svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents:
1309
diff
changeset
|
1201 |
} |
1280
33a251c30758
(svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents:
1264
diff
changeset
|
1202 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1203 |
/* Max number of times is checked. */ |
0 | 1204 |
} while (--_grow_town_result >= 0); |
1205 |
||
1206 |
return (_grow_town_result == -2); |
|
1207 |
} |
|
1208 |
||
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1209 |
/** |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1210 |
* Generate a random road block. |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1211 |
* The probability of a straight road |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1212 |
* is somewhat higher than a curved. |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1213 |
* |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1214 |
* @return A RoadBits value with 2 bits set |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1215 |
*/ |
6247 | 1216 |
static RoadBits GenRandomRoadBits() |
0 | 1217 |
{ |
1218 |
uint32 r = Random(); |
|
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2070
diff
changeset
|
1219 |
uint a = GB(r, 0, 2); |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2070
diff
changeset
|
1220 |
uint b = GB(r, 8, 2); |
0 | 1221 |
if (a == b) b ^= 2; |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1222 |
return (RoadBits)((ROAD_NW << a) + (ROAD_NW << b)); |
0 | 1223 |
} |
1224 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1225 |
/** Grow the town |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1226 |
* @Return true if a house was built, or no if the build failed. */ |
2817 | 1227 |
static bool GrowTown(Town *t) |
0 | 1228 |
{ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1229 |
|
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1230 |
/* Let the town be a ghost town |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1231 |
* The player wanted it in such a way. Thus there he has it. ;) |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1232 |
* Never reached in editor mode. */ |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1233 |
if (_patches.town_layout == TL_NO_ROADS && _generating_world) { |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1234 |
return false; |
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1235 |
} |
0 | 1236 |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1237 |
static const TileIndexDiffC _town_coord_mod[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1238 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1239 |
{ 1, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1240 |
{ 1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1241 |
{-1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1242 |
{-1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1243 |
{ 0, 2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1244 |
{ 2, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1245 |
{ 0, -2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1246 |
{-1, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1247 |
{-2, 2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1248 |
{ 2, 2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1249 |
{ 2, -2}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1250 |
{ 0, 0} |
0 | 1251 |
}; |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1252 |
const TileIndexDiffC *ptr; |
6571
6a8a1d0835d9
(svn r9779) -Feature: Add the possiblity to choose different road patterns for towns to use.
belugas
parents:
6560
diff
changeset
|
1253 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1254 |
/* Current player is a town */ |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1255 |
PlayerID old_player = _current_player; |
0 | 1256 |
_current_player = OWNER_TOWN; |
1257 |
||
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
1258 |
TileIndex tile = t->xy; // The tile we are working with ATM |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1259 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1260 |
/* Find a road that we can base the construction on. */ |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1261 |
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
7566
a8dd64b03224
(svn r11091) -Codechange: Partial rewrite of the road management code of towns, in order to make it more readable and with improved performance. (FS#1161 by skidd13)
belugas
parents:
7549
diff
changeset
|
1262 |
if (GetTownRoadBits(tile) != ROAD_NONE) { |
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
1263 |
int r = GrowTownAtRoad(t, tile); |
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
1264 |
_current_player = old_player; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1265 |
return r != 0; |
0 | 1266 |
} |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1267 |
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1268 |
} |
0 | 1269 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1270 |
/* No road available, try to build a random road block by |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1271 |
* clearing some land and then building a road there. */ |
0 | 1272 |
tile = t->xy; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1273 |
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { |
4317
19c5108cd0ec
(svn r5970) -Fix [FS#49]: town-growth removed houses under construction to make way for road. Not wanted behavoir (Rubidium)
truelight
parents:
4300
diff
changeset
|
1274 |
/* Only work with plain land that not already has a house */ |
19c5108cd0ec
(svn r5970) -Fix [FS#49]: town-growth removed houses under construction to make way for road. Not wanted behavoir (Rubidium)
truelight
parents:
4300
diff
changeset
|
1275 |
if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) { |
6946
a48b23f1cc8a
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
6943
diff
changeset
|
1276 |
if (CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) { |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1277 |
DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); |
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
1278 |
_current_player = old_player; |
0 | 1279 |
return true; |
1280 |
} |
|
1281 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1282 |
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1283 |
} |
0 | 1284 |
|
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
193
diff
changeset
|
1285 |
_current_player = old_player; |
0 | 1286 |
return false; |
1287 |
} |
|
1288 |
||
1289 |
static void UpdateTownRadius(Town *t) |
|
1290 |
{ |
|
1291 |
static const uint16 _town_radius_data[23][5] = { |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1292 |
{ 4, 0, 0, 0, 0}, // 0 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1293 |
{ 16, 0, 0, 0, 0}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1294 |
{ 25, 0, 0, 0, 0}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1295 |
{ 36, 0, 0, 0, 0}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1296 |
{ 49, 0, 4, 0, 0}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1297 |
{ 64, 0, 4, 0, 0}, // 20 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1298 |
{ 64, 0, 9, 0, 1}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1299 |
{ 64, 0, 9, 0, 4}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1300 |
{ 64, 0, 16, 0, 4}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1301 |
{ 81, 0, 16, 0, 4}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1302 |
{ 81, 0, 16, 0, 4}, // 40 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1303 |
{ 81, 0, 25, 0, 9}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1304 |
{ 81, 36, 25, 0, 9}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1305 |
{ 81, 36, 25, 16, 9}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1306 |
{ 81, 49, 0, 25, 9}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1307 |
{ 81, 64, 0, 25, 9}, // 60 |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1308 |
{ 81, 64, 0, 36, 9}, |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
1309 |
{ 81, 64, 0, 36, 16}, |
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1310 |
{100, 81, 0, 49, 16}, |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1311 |
{100, 81, 0, 49, 25}, |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1312 |
{121, 81, 0, 49, 25}, // 80 |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1313 |
{121, 81, 0, 49, 25}, |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1314 |
{121, 81, 0, 49, 36}, // 88 |
0 | 1315 |
}; |
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1316 |
|
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1317 |
if (t->num_houses < 92) { |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1318 |
memcpy(t->radius, _town_radius_data[t->num_houses / 4], sizeof(t->radius)); |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1319 |
} else { |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1320 |
int mass = t->num_houses / 8; |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1321 |
/* At least very roughly extrapolate. Empirical numbers dancing between |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1322 |
* overwhelming by cottages and skyscrapers outskirts. */ |
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1323 |
t->radius[0] = mass * mass; |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1324 |
/* Actually we are proportional to sqrt() but that's right because |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1325 |
* we are covering an area. */ |
470
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1326 |
t->radius[1] = mass * 7; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1327 |
t->radius[2] = 0; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1328 |
t->radius[3] = mass * 4; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1329 |
t->radius[4] = mass * 3; |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1330 |
//debug("%d (->%d): %d %d %d %d\n", t->num_houses, mass, t->radius[0], t->radius[1], t->radius[3], t->radius[4]); |
08b29b012837
(svn r703) Attempt to improve the town growth algorithm - now it scales over 76 houses, is slightly exponential and travels further for larger towns.
pasky
parents:
468
diff
changeset
|
1331 |
} |
0 | 1332 |
} |
1333 |
||
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1334 |
static bool CreateTownName(uint32 *townnameparts) |
0 | 1335 |
{ |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1336 |
extern int _nb_orig_names; |
0 | 1337 |
Town *t2; |
1338 |
char buf1[64]; |
|
1339 |
char buf2[64]; |
|
1340 |
uint32 r; |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1341 |
/* Do not set too low tries, since when we run out of names, we loop |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1342 |
* for #tries only one time anyway - then we stop generating more |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1343 |
* towns. Do not show it too high neither, since looping through all |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1344 |
* the other towns may take considerable amount of time (10000 is |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1345 |
* too much). */ |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1346 |
int tries = 1000; |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1347 |
bool grf = (_opt.town_name >= _nb_orig_names); |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1348 |
uint32 grfid = grf ? GetGRFTownNameId(_opt.town_name - _nb_orig_names) : 0; |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1349 |
uint16 townnametype = grf ? GetGRFTownNameType(_opt.town_name - _nb_orig_names) : SPECSTR_TOWNNAME_START + _opt.town_name; |
0 | 1350 |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1351 |
assert(townnameparts); |
0 | 1352 |
|
2952 | 1353 |
for (;;) { |
0 | 1354 |
restart: |
1355 |
r = Random(); |
|
1356 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1357 |
SetDParam(0, r); |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1358 |
if (grf && grfid != 0) { |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1359 |
GRFTownNameGenerate(buf1, grfid, townnametype, r, lastof(buf1)); |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1360 |
} else { |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1361 |
GetString(buf1, townnametype, lastof(buf1)); |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1362 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1363 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1364 |
/* Check size and width */ |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4559
diff
changeset
|
1365 |
if (strlen(buf1) >= 31 || GetStringBoundingBox(buf1).width > 130) continue; |
0 | 1366 |
|
1367 |
FOR_ALL_TOWNS(t2) { |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1368 |
/* We can't just compare the numbers since |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1369 |
* several numbers may map to a single name. */ |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1370 |
SetDParam(0, t2->index); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4850
diff
changeset
|
1371 |
GetString(buf2, STR_TOWN, lastof(buf2)); |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1372 |
if (strcmp(buf1, buf2) == 0) { |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1373 |
if (tries-- < 0) return false; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1374 |
goto restart; |
0 | 1375 |
} |
1376 |
} |
|
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1377 |
*townnameparts = r; |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1378 |
return true; |
0 | 1379 |
} |
1380 |
} |
|
1381 |
||
1377
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
1382 |
void UpdateTownMaxPass(Town *t) |
0 | 1383 |
{ |
1384 |
t->max_pass = t->population >> 3; |
|
1385 |
t->max_mail = t->population >> 4; |
|
1386 |
} |
|
1387 |
||
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1388 |
/** |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1389 |
* Does the actual town creation. |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1390 |
* |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1391 |
* @param t The town |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1392 |
* @param tile Where to put it |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1393 |
* @param townnameparts The town name |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1394 |
* @param size_mode How the size should be determined |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1395 |
* @param size Parameter for size determination |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1396 |
*/ |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1397 |
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSizeMode size_mode, uint size) |
0 | 1398 |
{ |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1399 |
extern int _nb_orig_names; |
0 | 1400 |
int x, i; |
1401 |
||
1402 |
t->xy = tile; |
|
1403 |
t->num_houses = 0; |
|
1404 |
t->time_until_rebuild = 10; |
|
1405 |
UpdateTownRadius(t); |
|
1406 |
t->flags12 = 0; |
|
1407 |
t->population = 0; |
|
1408 |
t->grow_counter = 0; |
|
1409 |
t->growth_rate = 250; |
|
1410 |
t->new_max_pass = 0; |
|
1411 |
t->new_max_mail = 0; |
|
1412 |
t->new_act_pass = 0; |
|
1413 |
t->new_act_mail = 0; |
|
1414 |
t->max_pass = 0; |
|
1415 |
t->max_mail = 0; |
|
1416 |
t->act_pass = 0; |
|
1417 |
t->act_mail = 0; |
|
1418 |
||
1419 |
t->pct_pass_transported = 0; |
|
1420 |
t->pct_mail_transported = 0; |
|
1421 |
t->fund_buildings_months = 0; |
|
1422 |
t->new_act_food = 0; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1423 |
t->new_act_water = 0; |
0 | 1424 |
t->act_food = 0; |
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
1425 |
t->act_water = 0; |
0 | 1426 |
|
2952 | 1427 |
for (i = 0; i != MAX_PLAYERS; i++) |
0 | 1428 |
t->ratings[i] = 500; |
1429 |
||
1430 |
t->have_ratings = 0; |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1431 |
t->exclusivity = INVALID_PLAYER; |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
1432 |
t->exclusive_counter = 0; |
0 | 1433 |
t->statues = 0; |
1434 |
||
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1435 |
if (_opt.town_name < _nb_orig_names) { |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1436 |
/* Original town name */ |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1437 |
t->townnamegrfid = 0; |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1438 |
t->townnametype = SPECSTR_TOWNNAME_START + _opt.town_name; |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1439 |
} else { |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1440 |
/* Newgrf town name */ |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1441 |
t->townnamegrfid = GetGRFTownNameId(_opt.town_name - _nb_orig_names); |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1442 |
t->townnametype = GetGRFTownNameType(_opt.town_name - _nb_orig_names); |
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
1443 |
} |
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1444 |
t->townnameparts = townnameparts; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1445 |
|
0 | 1446 |
UpdateTownVirtCoord(t); |
1447 |
_town_sort_dirty = true; |
|
1448 |
||
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1449 |
/* Random town size. */ |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1450 |
x = (Random() & 0xF) + 8; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1451 |
|
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1452 |
switch (size_mode) { |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1453 |
default: NOT_REACHED(); |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1454 |
|
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1455 |
case TSM_RANDOM: |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1456 |
t->larger_town = false; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1457 |
break; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1458 |
|
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1459 |
case TSM_FIXED: |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1460 |
x = size * 16 + 3; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1461 |
t->larger_town = false; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1462 |
break; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1463 |
|
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1464 |
case TSM_CITY: |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1465 |
x *= _patches.initial_city_size; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1466 |
t->larger_town = true; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1467 |
break; |
3674
d6c991bdcbe1
(svn r4591) -Fix (FS#122) Game no longer errors out when "Many random towns" is selected in the scenario editor.
celestar
parents:
3657
diff
changeset
|
1468 |
} |
0 | 1469 |
|
1470 |
t->num_houses += x; |
|
1471 |
UpdateTownRadius(t); |
|
1472 |
||
1473 |
i = x * 4; |
|
1474 |
do { |
|
1475 |
GrowTown(t); |
|
1476 |
} while (--i); |
|
1477 |
||
1478 |
t->num_houses -= x; |
|
1479 |
UpdateTownRadius(t); |
|
1480 |
UpdateTownMaxPass(t); |
|
1481 |
} |
|
1482 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1483 |
/** Create a new town. |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1484 |
* This obviously only works in the scenario editor. Function not removed |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1485 |
* as it might be possible in the future to fund your own town :) |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1486 |
* @param tile coordinates where town is built |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1487 |
* @param flags type of operation |
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1488 |
* @param p1 size of the town (0 = small, 1 = medium, 2 = large) |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1489 |
* @param p2 size mode (@see TownSizeMode) |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1490 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
1491 |
CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1492 |
{ |
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1493 |
uint32 townnameparts; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1494 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1495 |
/* Only in the scenario editor */ |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1496 |
if (_game_mode != GM_EDITOR) return CMD_ERROR; |
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1497 |
if (p2 > TSM_CITY) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1498 |
|
0 | 1499 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
1500 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1501 |
/* Check if too close to the edge of map */ |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
1502 |
if (DistanceFromEdge(tile) < 12) |
0 | 1503 |
return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP); |
1504 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1505 |
/* Can only build on clear flat areas, possibly with trees. */ |
5085
19b2b317c7eb
(svn r7152) -Feature (FS#396): allow towns to be built on top of trees in the scenario editor.
rubidium
parents:
5065
diff
changeset
|
1506 |
if ((!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES)) || GetTileSlope(tile, NULL) != SLOPE_FLAT) { |
0 | 1507 |
return_cmd_error(STR_0239_SITE_UNSUITABLE); |
2986
f440014bdbf3
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1508 |
} |
0 | 1509 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1510 |
/* Check distance to all other towns. */ |
0 | 1511 |
if (IsCloseToTown(tile, 20)) |
1512 |
return_cmd_error(STR_0238_TOO_CLOSE_TO_ANOTHER_TOWN); |
|
1513 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1514 |
/* Get a unique name for the town. */ |
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1515 |
if (!CreateTownName(&townnameparts)) |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1516 |
return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1517 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1518 |
/* Allocate town struct */ |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
1519 |
Town *t = new Town(tile); |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1520 |
if (t == NULL) return_cmd_error(STR_023A_TOO_MANY_TOWNS); |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
1521 |
AutoPtrT<Town> t_auto_delete = t; |
0 | 1522 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1523 |
/* Create the town */ |
0 | 1524 |
if (flags & DC_EXEC) { |
1525 |
_generating_world = true; |
|
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1526 |
DoCreateTown(t, tile, townnameparts, (TownSizeMode)p2, p1); |
0 | 1527 |
_generating_world = false; |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
1528 |
t_auto_delete.Detach(); |
0 | 1529 |
} |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1530 |
return CommandCost(); |
0 | 1531 |
} |
1532 |
||
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1533 |
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size) |
0 | 1534 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1535 |
TileIndex tile; |
0 | 1536 |
Town *t; |
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1537 |
uint32 townnameparts; |
0 | 1538 |
|
1539 |
do { |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1540 |
/* Generate a tile index not too close from the edge */ |
2051 | 1541 |
tile = RandomTile(); |
2951 | 1542 |
if (DistanceFromEdge(tile) < 20) continue; |
0 | 1543 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1544 |
/* Make sure the tile is plain */ |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1545 |
if (!IsTileType(tile, MP_CLEAR) || GetTileSlope(tile, NULL) != SLOPE_FLAT) continue; |
0 | 1546 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1547 |
/* Check not too close to a town */ |
2951 | 1548 |
if (IsCloseToTown(tile, 20)) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1549 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1550 |
/* Get a unique name for the town. */ |
2951 | 1551 |
if (!CreateTownName(&townnameparts)) break; |
1421
0532cbf429f1
(svn r1925) Fixed an infinite loop if the town generator runs out of town names. The number of generated towns is then limited by the number of available names.
pasky
parents:
1377
diff
changeset
|
1552 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1553 |
/* Allocate a town struct */ |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
1554 |
t = new Town(tile); |
2951 | 1555 |
if (t == NULL) break; |
0 | 1556 |
|
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1557 |
DoCreateTown(t, tile, townnameparts, mode, size); |
0 | 1558 |
return t; |
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1559 |
} while (--attempts); |
0 | 1560 |
return NULL; |
1561 |
} |
|
1562 |
||
6560
24106d85dcf5
(svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents:
6547
diff
changeset
|
1563 |
static const byte _num_initial_towns[4] = {5, 11, 23, 46}; |
0 | 1564 |
|
6247 | 1565 |
bool GenerateTowns() |
0 | 1566 |
{ |
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1567 |
uint num = 0; |
6061
fad5b9f8ada8
(svn r8791) -Revert: r8790 Committed too much in last commit
miham
parents:
6060
diff
changeset
|
1568 |
uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7)); |
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1569 |
uint num_cities = _patches.larger_towns == 0 ? 0 : n / _patches.larger_towns; |
1202
4d2a20c50760
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents:
1174
diff
changeset
|
1570 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1571 |
SetGeneratingWorldProgress(GWP_TOWN, n); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1572 |
|
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1573 |
do { |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4261
diff
changeset
|
1574 |
IncreaseGeneratingWorldProgress(GWP_TOWN); |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1575 |
/* try 20 times to create a random-sized town for the first loop. */ |
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1576 |
TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1577 |
if (CreateRandomTown(20, mode, _patches.initial_city_size) != NULL) num++; |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1578 |
if (num_cities > 0) num_cities--; |
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1579 |
} while (--n); |
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1580 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1581 |
/* give it a last try, but now more aggressive */ |
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
1582 |
if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0) == NULL) { |
5247
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
1583 |
if (GetNumTowns() == 0) { |
4384
7e0d3ed719d9
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1584 |
/* XXX - can we handle that more gracefully? */ |
7e0d3ed719d9
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1585 |
if (_game_mode != GM_EDITOR) error("Could not generate any town"); |
2430
b8bb9d74253b
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1586 |
|
4384
7e0d3ed719d9
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4357
diff
changeset
|
1587 |
return false; |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1588 |
} |
1362
bceb3c57353d
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents:
1335
diff
changeset
|
1589 |
} |
2430
b8bb9d74253b
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1590 |
|
b8bb9d74253b
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Darkvater
parents:
2425
diff
changeset
|
1591 |
return true; |
0 | 1592 |
} |
1593 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1594 |
static bool CheckBuildHouseMode(TileIndex tile, Slope tileh, int mode) |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1595 |
{ |
0 | 1596 |
int b; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1597 |
Slope slope; |
0 | 1598 |
|
1599 |
static const byte _masks[8] = { |
|
1600 |
0xC,0x3,0x9,0x6, |
|
1601 |
0x3,0xC,0x6,0x9, |
|
1602 |
}; |
|
1603 |
||
1604 |
slope = GetTileSlope(tile, NULL); |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1605 |
if (IsSteepSlope(slope)) return false; |
0 | 1606 |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5378
diff
changeset
|
1607 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; |
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5378
diff
changeset
|
1608 |
|
0 | 1609 |
b = 0; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1610 |
if ((slope != SLOPE_FLAT && ~slope & _masks[mode])) b = ~b; |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1611 |
if ((tileh != SLOPE_FLAT && ~tileh & _masks[mode+4])) b = ~b; |
0 | 1612 |
if (b) |
1613 |
return false; |
|
1614 |
||
6946
a48b23f1cc8a
(svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents:
6943
diff
changeset
|
1615 |
return CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR)); |
0 | 1616 |
} |
1617 |
||
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1618 |
|
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1619 |
uint GetTownRadiusGroup(const Town* t, TileIndex tile) |
0 | 1620 |
{ |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1621 |
uint dist = DistanceSquare(tile, t->xy); |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1622 |
uint smallest; |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1623 |
uint i; |
0 | 1624 |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1625 |
if (t->fund_buildings_months && dist <= 25) return 4; |
0 | 1626 |
|
1627 |
smallest = 0; |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2430
diff
changeset
|
1628 |
for (i = 0; i != lengthof(t->radius); i++) { |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
1629 |
if (dist < t->radius[i]) smallest = i; |
0 | 1630 |
} |
1631 |
||
1632 |
return smallest; |
|
1633 |
} |
|
1634 |
||
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1635 |
static bool CheckFree2x2Area(TileIndex tile) |
0 | 1636 |
{ |
1637 |
int i; |
|
1638 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1639 |
static const TileIndexDiffC _tile_add[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1640 |
{0 , 0 }, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1641 |
{0 - 0, 1 - 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1642 |
{1 - 0, 0 - 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1643 |
{1 - 1, 1 - 0} |
0 | 1644 |
}; |
1645 |
||
2952 | 1646 |
for (i = 0; i != 4; i++) { |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
900
diff
changeset
|
1647 |
tile += ToTileIndexDiff(_tile_add[i]); |
0 | 1648 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1649 |
if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return false; |
0 | 1650 |
|
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5378
diff
changeset
|
1651 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; |
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5378
diff
changeset
|
1652 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1653 |
if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_FORCETEST, CMD_LANDSCAPE_CLEAR))) |
0 | 1654 |
return false; |
1655 |
} |
|
1656 |
||
1657 |
return true; |
|
1658 |
} |
|
1659 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1660 |
static void DoBuildTownHouse(Town *t, TileIndex tile) |
0 | 1661 |
{ |
1662 |
int i; |
|
1663 |
uint bitmask; |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1664 |
HouseID house; |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1665 |
Slope slope; |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1328
diff
changeset
|
1666 |
uint z; |
3432
650dd1972479
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1667 |
uint oneof = 0; |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1668 |
HouseSpec *hs; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1669 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1670 |
/* Above snow? */ |
0 | 1671 |
slope = GetTileSlope(tile, &z); |
1672 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1673 |
/* Get the town zone type */ |
0 | 1674 |
{ |
1675 |
uint rad = GetTownRadiusGroup(t, tile); |
|
1676 |
||
1677 |
int land = _opt.landscape; |
|
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6350
diff
changeset
|
1678 |
if (land == LT_ARCTIC && z >= _opt.snow_line) land = -1; |
0 | 1679 |
|
1680 |
bitmask = (1 << rad) + (1 << (land + 12)); |
|
1681 |
} |
|
1682 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1683 |
/* bits 0-4 are used |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1684 |
* bits 11-15 are used |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1685 |
* bits 5-10 are not used. */ |
0 | 1686 |
{ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1687 |
HouseID houses[HOUSE_MAX]; |
0 | 1688 |
int num = 0; |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1689 |
uint cumulative_probs[HOUSE_MAX]; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1690 |
uint probability_max = 0; |
0 | 1691 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1692 |
/* Generate a list of all possible houses that can be built. */ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1693 |
for (i = 0; i < HOUSE_MAX; i++) { |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1694 |
hs = GetHouseSpecs(i); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1695 |
if ((~hs->building_availability & bitmask) == 0 && hs->enabled) { |
6914
6219e65dd7bf
(svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents:
6842
diff
changeset
|
1696 |
if (_loaded_newgrf_features.has_newhouses) { |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1697 |
probability_max += hs->probability; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1698 |
cumulative_probs[num] = probability_max; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1699 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1700 |
houses[num++] = (HouseID)i; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1701 |
} |
0 | 1702 |
} |
1703 |
||
2952 | 1704 |
for (;;) { |
6914
6219e65dd7bf
(svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents:
6842
diff
changeset
|
1705 |
if (_loaded_newgrf_features.has_newhouses) { |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1706 |
uint r = RandomRange(probability_max); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1707 |
for (i = 0; i < num; i++) if (cumulative_probs[i] >= r) break; |
0 | 1708 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1709 |
house = houses[i]; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1710 |
} else { |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1711 |
house = houses[RandomRange(num)]; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1712 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1713 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1714 |
hs = GetHouseSpecs(house); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1715 |
|
6914
6219e65dd7bf
(svn r10167) -Codechange: Change the flagging system of grf loaded feature from a bitset to a bool evaluation.
belugas
parents:
6842
diff
changeset
|
1716 |
if (_loaded_newgrf_features.has_newhouses) { |
7762
78449448addc
(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
parents:
7739
diff
changeset
|
1717 |
if (hs->override != 0) { |
78449448addc
(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
parents:
7739
diff
changeset
|
1718 |
house = hs->override; |
78449448addc
(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
parents:
7739
diff
changeset
|
1719 |
hs = GetHouseSpecs(house); |
78449448addc
(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
parents:
7739
diff
changeset
|
1720 |
} |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1721 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1722 |
if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1723 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
1724 |
if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) { |
6642
ced51f7c19aa
(svn r9873) -Codechange: Add missing second callback parameter for houses
peter1138
parents:
6629
diff
changeset
|
1725 |
uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1726 |
if (callback_res != CALLBACK_FAILED && callback_res == 0) continue; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1727 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1728 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1729 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1730 |
if (_cur_year < hs->min_date || _cur_year > hs->max_date) continue; |
0 | 1731 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1732 |
/* Special houses that there can be only one of. */ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1733 |
if (hs->building_flags & BUILDING_IS_CHURCH) { |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
1734 |
SetBit(oneof, TOWN_HAS_CHURCH); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1735 |
} else if (hs->building_flags & BUILDING_IS_STADIUM) { |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
1736 |
SetBit(oneof, TOWN_HAS_STADIUM); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1737 |
} else { |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1738 |
oneof = 0; |
483
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1739 |
} |
0 | 1740 |
|
3432
650dd1972479
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1741 |
if (HASBITS(t->flags12 , oneof)) continue; |
0 | 1742 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1743 |
/* Make sure there is no slope? */ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1744 |
if (hs->building_flags & TILE_NOT_SLOPED && slope != SLOPE_FLAT) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1745 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1746 |
if (hs->building_flags & TILE_SIZE_2x2) { |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1747 |
if (CheckFree2x2Area(tile) || |
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1748 |
CheckFree2x2Area(tile += TileDiffXY(-1, 0)) || |
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1749 |
CheckFree2x2Area(tile += TileDiffXY( 0, -1)) || |
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1750 |
CheckFree2x2Area(tile += TileDiffXY( 1, 0))) { |
1981 | 1751 |
break; |
2951 | 1752 |
} |
1753 |
tile += TileDiffXY(0, 1); |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1754 |
} else if (hs->building_flags & TILE_SIZE_2x1) { |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1755 |
if (CheckBuildHouseMode(tile + TileDiffXY(1, 0), slope, 0)) break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1756 |
|
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1757 |
if (CheckBuildHouseMode(tile + TileDiffXY(-1, 0), slope, 1)) { |
1981 | 1758 |
tile += TileDiffXY(-1, 0); |
0 | 1759 |
break; |
1760 |
} |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1761 |
} else if (hs->building_flags & TILE_SIZE_1x2) { |
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1762 |
if (CheckBuildHouseMode(tile + TileDiffXY(0, 1), slope, 2)) break; |
0 | 1763 |
|
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
1764 |
if (CheckBuildHouseMode(tile + TileDiffXY(0, -1), slope, 3)) { |
1981 | 1765 |
tile += TileDiffXY(0, -1); |
0 | 1766 |
break; |
1767 |
} |
|
2951 | 1768 |
} else { |
0 | 1769 |
break; |
2951 | 1770 |
} |
0 | 1771 |
} |
1772 |
} |
|
1773 |
||
1774 |
t->num_houses++; |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1775 |
IncreaseBuildingCount(t, house); |
0 | 1776 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1777 |
/* Special houses that there can be only one of. */ |
0 | 1778 |
t->flags12 |= oneof; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1779 |
|
0 | 1780 |
{ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1781 |
byte construction_counter = 0, construction_stage = 0; |
0 | 1782 |
|
1783 |
if (_generating_world) { |
|
1784 |
uint32 r = Random(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1785 |
|
3432
650dd1972479
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1786 |
construction_stage = TOWN_HOUSE_COMPLETED; |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
1787 |
if (Chance16(1, 7)) construction_stage = GB(r, 0, 2); |
0 | 1788 |
|
3432
650dd1972479
(svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents:
3426
diff
changeset
|
1789 |
if (construction_stage == TOWN_HOUSE_COMPLETED) { |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1790 |
ChangePopulation(t, hs->population); |
3382
be14efb0dfd7
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1791 |
} else { |
be14efb0dfd7
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1792 |
construction_counter = GB(r, 2, 2); |
be14efb0dfd7
(svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents:
3379
diff
changeset
|
1793 |
} |
0 | 1794 |
} |
8144
65cec0877b78
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
1795 |
MakeTownHouse(tile, t->index, construction_counter, construction_stage, house, Random()); |
0 | 1796 |
} |
1797 |
} |
|
1798 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1799 |
static bool BuildTownHouse(Town *t, TileIndex tile) |
0 | 1800 |
{ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
1801 |
CommandCost r; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1802 |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1803 |
if (IsSteepSlope(GetTileSlope(tile, NULL))) return false; |
5385
3868f2e6db9b
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents:
5378
diff
changeset
|
1804 |
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; |
0 | 1805 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1806 |
r = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR); |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2646
diff
changeset
|
1807 |
if (CmdFailed(r)) return false; |
0 | 1808 |
|
1809 |
DoBuildTownHouse(t, tile); |
|
1810 |
return true; |
|
1811 |
} |
|
1812 |
||
1813 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1814 |
static void DoClearTownHouseHelper(TileIndex tile) |
0 | 1815 |
{ |
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1816 |
assert(IsTileType(tile, MP_HOUSE)); |
0 | 1817 |
DoClearSquare(tile); |
1818 |
DeleteAnimatedTile(tile); |
|
1819 |
} |
|
1820 |
||
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1821 |
void ClearTownHouse(Town *t, TileIndex tile) |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1822 |
{ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1823 |
HouseID house = GetHouseType(tile); |
0 | 1824 |
uint eflags; |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1825 |
HouseSpec *hs; |
0 | 1826 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1005
diff
changeset
|
1827 |
assert(IsTileType(tile, MP_HOUSE)); |
0 | 1828 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1829 |
/* need to align the tile to point to the upper left corner of the house */ |
0 | 1830 |
if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks. |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1831 |
if (GetHouseSpecs(house-1)->building_flags & TILE_SIZE_2x1) { |
0 | 1832 |
house--; |
1981 | 1833 |
tile += TileDiffXY(-1, 0); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1834 |
} else if (GetHouseSpecs(house-1)->building_flags & BUILDING_2_TILES_Y) { |
0 | 1835 |
house--; |
1981 | 1836 |
tile += TileDiffXY(0, -1); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1837 |
} else if (GetHouseSpecs(house-2)->building_flags & BUILDING_HAS_4_TILES) { |
0 | 1838 |
house-=2; |
1981 | 1839 |
tile += TileDiffXY(-1, 0); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1840 |
} else if (GetHouseSpecs(house-3)->building_flags & BUILDING_HAS_4_TILES) { |
0 | 1841 |
house-=3; |
1981 | 1842 |
tile += TileDiffXY(-1, -1); |
0 | 1843 |
} |
1844 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1845 |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1846 |
hs = GetHouseSpecs(house); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1847 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1848 |
/* Remove population from the town if the house is finished. */ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1849 |
if (IsHouseCompleted(tile)) { |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1850 |
ChangePopulation(t, -hs->population); |
0 | 1851 |
} |
1852 |
||
1853 |
t->num_houses--; |
|
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1854 |
DecreaseBuildingCount(t, house); |
0 | 1855 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1856 |
/* Clear flags for houses that only may exist once/town. */ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1857 |
if (hs->building_flags & BUILDING_IS_CHURCH) { |
7929
6c9b25842b0f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
1858 |
ClrBit(t->flags12, TOWN_HAS_CHURCH); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1859 |
} else if (hs->building_flags & BUILDING_IS_STADIUM) { |
7929
6c9b25842b0f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
1860 |
ClrBit(t->flags12, TOWN_HAS_STADIUM); |
483
d8374ce6b365
(svn r764) Enumerate the houses only one per town can exist and use the enums instead of magic numbers to check for these
tron
parents:
482
diff
changeset
|
1861 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1862 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1863 |
/* Do the actual clearing of tiles */ |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1864 |
eflags = hs->building_flags; |
0 | 1865 |
DoClearTownHouseHelper(tile); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1866 |
if (eflags & BUILDING_2_TILES_X) DoClearTownHouseHelper(tile + TileDiffXY(1, 0)); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1867 |
if (eflags & BUILDING_2_TILES_Y) DoClearTownHouseHelper(tile + TileDiffXY(0, 1)); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
1868 |
if (eflags & BUILDING_HAS_4_TILES) DoClearTownHouseHelper(tile + TileDiffXY(1, 1)); |
0 | 1869 |
} |
1870 |
||
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1871 |
static bool IsUniqueTownName(const char *name) |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1872 |
{ |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1873 |
const Town *t; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1874 |
char buf[512]; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1875 |
|
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1876 |
FOR_ALL_TOWNS(t) { |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1877 |
SetDParam(0, t->index); |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1878 |
GetString(buf, STR_TOWN, lastof(buf)); |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1879 |
if (strcmp(buf, name) == 0) return false; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1880 |
} |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1881 |
|
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1882 |
return true; |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1883 |
} |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1884 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1885 |
/** Rename a town (server-only). |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1886 |
* @param tile unused |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1887 |
* @param flags type of operation |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1888 |
* @param p1 town ID to rename |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1889 |
* @param p2 unused |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1890 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
1891 |
CommandCost CmdRenameTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1892 |
{ |
1893 |
StringID str; |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1894 |
Town *t; |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1895 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1896 |
if (!IsValidTownID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1897 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1898 |
t = GetTown(p1); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1899 |
|
7097
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1900 |
if (!IsUniqueTownName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1901 |
|
bc497a49fb45
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7058
diff
changeset
|
1902 |
str = AllocateName(_cmd_text, 4); |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1903 |
if (str == 0) return CMD_ERROR; |
0 | 1904 |
|
1905 |
if (flags & DC_EXEC) { |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
1906 |
DeleteName(t->townnametype); |
0 | 1907 |
t->townnametype = str; |
7139
00737445dc48
(svn r10413) -Fix r10211: t->townnamegrfid was not cleared when renaming a town
glx
parents:
7097
diff
changeset
|
1908 |
t->townnamegrfid = 0; |
0 | 1909 |
|
1910 |
UpdateTownVirtCoord(t); |
|
1911 |
_town_sort_dirty = true; |
|
1912 |
UpdateAllStationVirtCoord(); |
|
7709
439dcda6d74b
(svn r11243) -Fix: update waypoint signs when renaming a town
glx
parents:
7684
diff
changeset
|
1913 |
UpdateAllWaypointSigns(); |
0 | 1914 |
MarkWholeScreenDirty(); |
1915 |
} else { |
|
1916 |
DeleteName(str); |
|
1917 |
} |
|
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
1918 |
return CommandCost(); |
0 | 1919 |
} |
1920 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
1921 |
/** Called from GUI */ |
0 | 1922 |
void ExpandTown(Town *t) |
1923 |
{ |
|
1924 |
int amount, n; |
|
1925 |
||
1926 |
_generating_world = true; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1927 |
|
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1928 |
/* The more houses, the faster we grow */ |
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1929 |
amount = RandomRange(t->num_houses / 10) + 3; |
0 | 1930 |
t->num_houses += amount; |
1931 |
UpdateTownRadius(t); |
|
1932 |
||
835
f6a341f541d7
(svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents:
830
diff
changeset
|
1933 |
n = amount * 10; |
0 | 1934 |
do GrowTown(t); while (--n); |
1935 |
||
1936 |
t->num_houses -= amount; |
|
1937 |
UpdateTownRadius(t); |
|
1938 |
||
1939 |
UpdateTownMaxPass(t); |
|
1940 |
_generating_world = false; |
|
1941 |
} |
|
1942 |
||
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1943 |
extern const byte _town_action_costs[8] = { |
0 | 1944 |
2, 4, 9, 35, 48, 53, 117, 175 |
1945 |
}; |
|
1946 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1947 |
static void TownActionAdvertiseSmall(Town* t) |
0 | 1948 |
{ |
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1949 |
ModifyStationRatingAround(t->xy, _current_player, 0x40, 10); |
0 | 1950 |
} |
1951 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1952 |
static void TownActionAdvertiseMedium(Town* t) |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1953 |
{ |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1954 |
ModifyStationRatingAround(t->xy, _current_player, 0x70, 15); |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1955 |
} |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1956 |
|
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1957 |
static void TownActionAdvertiseLarge(Town* t) |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1958 |
{ |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1959 |
ModifyStationRatingAround(t->xy, _current_player, 0xA0, 20); |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1960 |
} |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1961 |
|
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
1962 |
static void TownActionRoadRebuild(Town* t) |
0 | 1963 |
{ |
1964 |
t->road_build_months = 6; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1965 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
1966 |
SetDParam(0, t->index); |
7058
8105bb13ce3d
(svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents:
6997
diff
changeset
|
1967 |
SetDParam(1, _current_player); |
0 | 1968 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
1969 |
AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING, |
0 | 1970 |
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0); |
1971 |
} |
|
1972 |
||
6257
5e5a864cacf6
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6247
diff
changeset
|
1973 |
static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id) |
0 | 1974 |
{ |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1975 |
PlayerID old; |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
1976 |
CommandCost r; |
0 | 1977 |
|
7549
53483e249123
(svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium
parents:
7545
diff
changeset
|
1978 |
/* Statues can be build on slopes, just like houses. Only the steep slopes is a no go. */ |
53483e249123
(svn r11069) -Codechange: allow slopes under statues. Patch by kaan.
rubidium
parents:
7545
diff
changeset
|
1979 |
if (IsSteepSlope(GetTileSlope(tile, NULL))) return false; |
0 | 1980 |
|
2986
f440014bdbf3
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1981 |
if (!IsTileType(tile, MP_HOUSE) && |
f440014bdbf3
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1982 |
!IsTileType(tile, MP_CLEAR) && |
f440014bdbf3
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1983 |
!IsTileType(tile, MP_TREES)) { |
0 | 1984 |
return false; |
2986
f440014bdbf3
(svn r3561) Don't use FindLandscapeHeightByTile() when it's overkill. Also use a sprite enum instead of a magic number.
tron
parents:
2958
diff
changeset
|
1985 |
} |
0 | 1986 |
|
1987 |
old = _current_player; |
|
1988 |
_current_player = OWNER_NONE; |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
1989 |
r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 1990 |
_current_player = old; |
1991 |
||
2646
c01dfbc7b7e3
(svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents:
2639
diff
changeset
|
1992 |
if (CmdFailed(r)) return false; |
0 | 1993 |
|
6257
5e5a864cacf6
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6247
diff
changeset
|
1994 |
MakeStatue(tile, _current_player, town_id); |
3310
a19f247b75b6
(svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents:
3282
diff
changeset
|
1995 |
MarkTileDirtyByTile(tile); |
0 | 1996 |
|
1997 |
return true; |
|
1998 |
} |
|
1999 |
||
5118
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2000 |
/** |
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2001 |
* Search callback function for TownActionBuildStatue |
6484
79156627e1ba
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas
parents:
6455
diff
changeset
|
2002 |
* @param tile on which to perform the search |
6257
5e5a864cacf6
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6247
diff
changeset
|
2003 |
* @param town_id The town_id for which we want a statue |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6133
diff
changeset
|
2004 |
* @return the result of the test |
5118
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2005 |
*/ |
6257
5e5a864cacf6
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6247
diff
changeset
|
2006 |
static bool SearchTileForStatue(TileIndex tile, uint32 town_id) |
5118
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2007 |
{ |
6257
5e5a864cacf6
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6247
diff
changeset
|
2008 |
return DoBuildStatueOfCompany(tile, town_id); |
5118
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2009 |
} |
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2010 |
|
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2011 |
/** |
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2012 |
* Perform a 9x9 tiles circular search from the center of the town |
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2013 |
* in order to find a free tile to place a statue |
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2014 |
* @param t town to search in |
9640617e1abb
(svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents:
5085
diff
changeset
|
2015 |
*/ |
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2016 |
static void TownActionBuildStatue(Town* t) |
0 | 2017 |
{ |
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
2018 |
TileIndex tile = t->xy; |
0 | 2019 |
|
6257
5e5a864cacf6
(svn r9066) -Fix [FS#638]: store the owner of a statue, so when it gets removed, the town is notified of it
truelight
parents:
6247
diff
changeset
|
2020 |
if (CircularTileSearch(tile, 9, SearchTileForStatue, t->index)) |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
2021 |
SetBit(t->statues, _current_player); // Once found and built, "inform" the Town |
0 | 2022 |
} |
2023 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2024 |
static void TownActionFundBuildings(Town* t) |
0 | 2025 |
{ |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2026 |
/* Build next tick */ |
0 | 2027 |
t->grow_counter = 1; |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2028 |
/* If we were not already growing */ |
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
2029 |
SetBit(t->flags12, TOWN_IS_FUNDED); |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2030 |
/* And grow for 3 months */ |
0 | 2031 |
t->fund_buildings_months = 3; |
2032 |
} |
|
2033 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2034 |
static void TownActionBuyRights(Town* t) |
0 | 2035 |
{ |
7657
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7642
diff
changeset
|
2036 |
/* Check if it's allowed to by the rights */ |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7642
diff
changeset
|
2037 |
if (!_patches.exclusive_rights) return; |
2b55af55cc51
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7642
diff
changeset
|
2038 |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
2039 |
t->exclusive_counter = 12; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
2040 |
t->exclusivity = _current_player; |
0 | 2041 |
|
2042 |
ModifyStationRatingAround(t->xy, _current_player, 130, 17); |
|
2043 |
} |
|
2044 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2045 |
static void TownActionBribe(Town* t) |
0 | 2046 |
{ |
2047 |
if (!RandomRange(15)) { |
|
2048 |
Station *st; |
|
2049 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2050 |
/* set as unwanted for 6 months */ |
0 | 2051 |
t->unwanted[_current_player] = 6; |
2052 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2053 |
/* set all close by station ratings to 0 */ |
0 | 2054 |
FOR_ALL_STATIONS(st) { |
2055 |
if (st->town == t && st->owner == _current_player) { |
|
6350
04b19f551aec
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6343
diff
changeset
|
2056 |
for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0; |
0 | 2057 |
} |
2058 |
} |
|
2059 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2060 |
/* only show errormessage to the executing player. All errors are handled command.c |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2061 |
* but this is special, because it can only 'fail' on a DC_EXEC */ |
2425
e755ee29133a
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
Darkvater
parents:
2360
diff
changeset
|
2062 |
if (IsLocalPlayer()) ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0); |
0 | 2063 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2064 |
/* decrease by a lot! |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2065 |
* ChangeTownRating is only for stuff in demolishing. Bribe failure should |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2066 |
* be independent of any cheat settings |
0 | 2067 |
*/ |
2549 | 2068 |
if (t->ratings[_current_player] > RATING_BRIBE_DOWN_TO) { |
1005 | 2069 |
t->ratings[_current_player] = RATING_BRIBE_DOWN_TO; |
2549 | 2070 |
} |
0 | 2071 |
} else { |
1005 | 2072 |
ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM); |
0 | 2073 |
} |
2074 |
} |
|
2075 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2076 |
typedef void TownActionProc(Town* t); |
0 | 2077 |
static TownActionProc * const _town_action_proc[] = { |
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2078 |
TownActionAdvertiseSmall, |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2079 |
TownActionAdvertiseMedium, |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2080 |
TownActionAdvertiseLarge, |
0 | 2081 |
TownActionRoadRebuild, |
2082 |
TownActionBuildStatue, |
|
2083 |
TownActionFundBuildings, |
|
2084 |
TownActionBuyRights, |
|
2085 |
TownActionBribe |
|
2086 |
}; |
|
2087 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2088 |
extern uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2089 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2090 |
/** Do a town action. |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2091 |
* This performs an action such as advertising, building a statue, funding buildings, |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2092 |
* but also bribing the town-council |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3433
diff
changeset
|
2093 |
* @param tile unused |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2094 |
* @param flags type of operation |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2095 |
* @param p1 town to do the action at |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2096 |
* @param p2 action to perform, @see _town_action_proc for the list of available actions |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2097 |
*/ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
2098 |
CommandCost CmdDoTownAction(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 2099 |
{ |
6943
1914f26aee04
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
6914
diff
changeset
|
2100 |
CommandCost cost; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2101 |
Town *t; |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2102 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4346
diff
changeset
|
2103 |
if (!IsValidTownID(p1) || p2 > lengthof(_town_action_proc)) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2104 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2105 |
t = GetTown(p1); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1638
diff
changeset
|
2106 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7903
diff
changeset
|
2107 |
if (!HasBit(GetMaskOfTownActions(NULL, _current_player, t), p2)) return CMD_ERROR; |
0 | 2108 |
|
2109 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
2110 |
||
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6946
diff
changeset
|
2111 |
cost.AddCost((_price.build_industry >> 8) * _town_action_costs[p2]); |
0 | 2112 |
|
2113 |
if (flags & DC_EXEC) { |
|
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3674
diff
changeset
|
2114 |
_town_action_proc[p2](t); |
0 | 2115 |
InvalidateWindow(WC_TOWN_AUTHORITY, p1); |
2116 |
} |
|
2117 |
||
2118 |
return cost; |
|
2119 |
} |
|
2120 |
||
2121 |
static void UpdateTownGrowRate(Town *t) |
|
2122 |
{ |
|
2123 |
int n; |
|
2124 |
Station *st; |
|
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2125 |
uint16 m; |
0 | 2126 |
Player *p; |
2127 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2128 |
/* Reset player ratings if they're low */ |
0 | 2129 |
FOR_ALL_PLAYERS(p) { |
2130 |
if (p->is_active && t->ratings[p->index] <= 200) { |
|
2131 |
t->ratings[p->index] += 5; |
|
2132 |
} |
|
2133 |
} |
|
2134 |
||
2135 |
n = 0; |
|
2136 |
FOR_ALL_STATIONS(st) { |
|
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1209
diff
changeset
|
2137 |
if (DistanceSquare(st->xy, t->xy) <= t->radius[0]) { |
0 | 2138 |
if (st->time_since_load <= 20 || st->time_since_unload <= 20) { |
2139 |
n++; |
|
4850
93095755db8c
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2140 |
if (IsValidPlayer(st->owner) && t->ratings[st->owner] <= 1000-12) |
0 | 2141 |
t->ratings[st->owner] += 12; |
2142 |
} else { |
|
4850
93095755db8c
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2143 |
if (IsValidPlayer(st->owner) && t->ratings[st->owner] >= -1000+15) |
0 | 2144 |
t->ratings[st->owner] -= 15; |
2145 |
} |
|
2146 |
} |
|
2147 |
} |
|
2148 |
||
7929
6c9b25842b0f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
7928
diff
changeset
|
2149 |
ClrBit(t->flags12, TOWN_IS_FUNDED); |
6455
d9783947f1b0
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6454
diff
changeset
|
2150 |
if (_patches.town_growth_rate == 0 && t->fund_buildings_months == 0) return; |
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2151 |
|
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2152 |
/** Towns are processed every TOWN_GROWTH_FREQUENCY ticks, and this is the |
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2153 |
* number of times towns are processed before a new building is built. */ |
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2154 |
static const uint16 _grow_count_values[2][6] = { |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
2155 |
{ 120, 120, 120, 100, 80, 60 }, // Fund new buildings has been activated |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
2156 |
{ 320, 420, 300, 220, 160, 100 } // Normal values |
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2157 |
}; |
0 | 2158 |
|
2159 |
if (t->fund_buildings_months != 0) { |
|
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2160 |
m = _grow_count_values[0][min(n, 5)]; |
0 | 2161 |
t->fund_buildings_months--; |
2162 |
} else { |
|
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2163 |
m = _grow_count_values[1][min(n, 5)]; |
7967
a230c063a672
(svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents:
7931
diff
changeset
|
2164 |
if (n == 0 && !Chance16(1, 12)) return; |
0 | 2165 |
} |
2166 |
||
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6350
diff
changeset
|
2167 |
if (_opt.landscape == LT_ARCTIC) { |
6343
76d17f784c13
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents:
6342
diff
changeset
|
2168 |
if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90) |
0 | 2169 |
return; |
6357
f0f5e7d1713c
(svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents:
6350
diff
changeset
|
2170 |
} else if (_opt.landscape == LT_TROPIC) { |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2171 |
if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food==0 || t->act_water==0) && t->population > 60) |
0 | 2172 |
return; |
2173 |
} |
|
2174 |
||
6455
d9783947f1b0
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6454
diff
changeset
|
2175 |
/* Use the normal growth rate values if new buildings have been funded in |
d9783947f1b0
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6454
diff
changeset
|
2176 |
* this town and the growth rate is set to none. */ |
d9783947f1b0
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6454
diff
changeset
|
2177 |
uint growth_multiplier = _patches.town_growth_rate != 0 ? _patches.town_growth_rate - 1 : 1; |
d9783947f1b0
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6454
diff
changeset
|
2178 |
|
d9783947f1b0
(svn r9614) -Feature: Use the normal growth rate values when the growth rate is set to none and "Fund new buildings" is used.
maedhros
parents:
6454
diff
changeset
|
2179 |
m >>= growth_multiplier; |
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
2180 |
if (t->larger_town) m /= 2; |
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2181 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2182 |
t->growth_rate = m / (t->num_houses / 50 + 1); |
0 | 2183 |
if (m <= t->grow_counter) |
2184 |
t->grow_counter = m; |
|
2185 |
||
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
2186 |
SetBit(t->flags12, TOWN_IS_FUNDED); |
0 | 2187 |
} |
2188 |
||
2189 |
static void UpdateTownAmounts(Town *t) |
|
2190 |
{ |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2191 |
/* Using +1 here to prevent overflow and division by zero */ |
0 | 2192 |
t->pct_pass_transported = t->new_act_pass * 256 / (t->new_max_pass + 1); |
2193 |
||
2194 |
t->max_pass = t->new_max_pass; t->new_max_pass = 0; |
|
2195 |
t->act_pass = t->new_act_pass; t->new_act_pass = 0; |
|
2196 |
t->act_food = t->new_act_food; t->new_act_food = 0; |
|
4
cad62d5f9708
(svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents:
0
diff
changeset
|
2197 |
t->act_water = t->new_act_water; t->new_act_water = 0; |
0 | 2198 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2199 |
/* Using +1 here to prevent overflow and division by zero */ |
0 | 2200 |
t->pct_mail_transported = t->new_act_mail * 256 / (t->new_max_mail + 1); |
2201 |
t->max_mail = t->new_max_mail; t->new_max_mail = 0; |
|
2202 |
t->act_mail = t->new_act_mail; t->new_act_mail = 0; |
|
2203 |
||
2204 |
InvalidateWindow(WC_TOWN_VIEW, t->index); |
|
2205 |
} |
|
2206 |
||
2207 |
static void UpdateTownUnwanted(Town *t) |
|
2208 |
{ |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
2209 |
const Player* p; |
0 | 2210 |
|
2211 |
FOR_ALL_PLAYERS(p) { |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
2212 |
if (t->unwanted[p->index] > 0) t->unwanted[p->index]--; |
0 | 2213 |
} |
2214 |
} |
|
2215 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
2216 |
bool CheckIfAuthorityAllows(TileIndex tile) |
0 | 2217 |
{ |
2218 |
Town *t; |
|
2219 |
||
4850
93095755db8c
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2220 |
if (!IsValidPlayer(_current_player)) return true; |
0 | 2221 |
|
2222 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
2223 |
if (t == NULL) return true; |
0 | 2224 |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
2225 |
if (t->ratings[_current_player] > -200) return true; |
0 | 2226 |
|
2227 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
2228 |
SetDParam(0, t->index); |
0 | 2229 |
|
2230 |
return false; |
|
2231 |
} |
|
2232 |
||
2233 |
||
3983
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2234 |
Town* CalcClosestTownFromTile(TileIndex tile, uint threshold) |
0 | 2235 |
{ |
2236 |
Town *t; |
|
2237 |
uint dist, best = threshold; |
|
2238 |
Town *best_town = NULL; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2239 |
|
0 | 2240 |
FOR_ALL_TOWNS(t) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2241 |
dist = DistanceManhattan(tile, t->xy); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2242 |
if (dist < best) { |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2243 |
best = dist; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2244 |
best_town = t; |
0 | 2245 |
} |
2246 |
} |
|
2247 |
||
2248 |
return best_town; |
|
2249 |
} |
|
2250 |
||
3983
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2251 |
|
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2252 |
Town *ClosestTownFromTile(TileIndex tile, uint threshold) |
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2253 |
{ |
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2254 |
if (IsTileType(tile, MP_HOUSE) || ( |
7370
41adc721b1fa
(svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents:
7335
diff
changeset
|
2255 |
IsTileType(tile, MP_ROAD) && |
6661
1716fce5ad29
(svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents:
6645
diff
changeset
|
2256 |
GetRoadOwner(tile, ROADTYPE_ROAD) == OWNER_TOWN |
3983
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2257 |
)) { |
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2258 |
return GetTownByTile(tile); |
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2259 |
} else { |
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2260 |
return CalcClosestTownFromTile(tile, threshold); |
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2261 |
} |
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2262 |
} |
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2263 |
|
0f815283e04b
(svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents:
3977
diff
changeset
|
2264 |
|
0 | 2265 |
void ChangeTownRating(Town *t, int add, int max) |
2266 |
{ |
|
2267 |
int rating; |
|
2268 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2269 |
/* if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff */ |
2639 | 2270 |
if (t == NULL || |
4850
93095755db8c
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2271 |
!IsValidPlayer(_current_player) || |
2639 | 2272 |
(_cheats.magic_bulldozer.value && add < 0)) { |
0 | 2273 |
return; |
2639 | 2274 |
} |
0 | 2275 |
|
7931
b0a46cd92225
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7929
diff
changeset
|
2276 |
SetBit(t->have_ratings, _current_player); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2277 |
|
0 | 2278 |
rating = t->ratings[_current_player]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2279 |
|
0 | 2280 |
if (add < 0) { |
2281 |
if (rating > max) { |
|
2282 |
rating += add; |
|
2283 |
if (rating < max) rating = max; |
|
2284 |
} |
|
2285 |
} else { |
|
2286 |
if (rating < max) { |
|
2287 |
rating += add; |
|
2288 |
if (rating > max) rating = max; |
|
2289 |
} |
|
2290 |
} |
|
2291 |
t->ratings[_current_player] = rating; |
|
2292 |
} |
|
2293 |
||
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2294 |
/* penalty for removing town-owned stuff */ |
0 | 2295 |
static const int _default_rating_settings [3][3] = { |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2296 |
/* ROAD_REMOVE, TUNNELBRIDGE_REMOVE, INDUSTRY_REMOVE */ |
7641
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
2297 |
{ 0, 128, 384}, // Permissive |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
2298 |
{ 48, 192, 480}, // Neutral |
3a75903fd892
(svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents:
7603
diff
changeset
|
2299 |
{ 96, 384, 768}, // Hostile |
0 | 2300 |
}; |
2301 |
||
2958
ac0a9673b522
(svn r3520) Remove unused parameters from some functions
tron
parents:
2952
diff
changeset
|
2302 |
bool CheckforTownRating(uint32 flags, Town *t, byte type) |
0 | 2303 |
{ |
2304 |
int modemod; |
|
2305 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2306 |
/* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */ |
4850
93095755db8c
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4609
diff
changeset
|
2307 |
if (t == NULL || !IsValidPlayer(_current_player) || _cheats.magic_bulldozer.value) |
0 | 2308 |
return true; |
2309 |
||
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2310 |
/* check if you're allowed to remove the street/bridge/tunnel/industry |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2311 |
* owned by a town no removal if rating is lower than ... depends now on |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4396
diff
changeset
|
2312 |
* difficulty setting. Minimum town rating selected by difficulty level |
0 | 2313 |
*/ |
1500
a66721629bc0
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1451
diff
changeset
|
2314 |
modemod = _default_rating_settings[_opt.diff.town_council_tolerance][type]; |
0 | 2315 |
|
2316 |
if (t->ratings[_current_player] < 16 + modemod && !(flags & DC_NO_TOWN_RATING)) { |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
516
diff
changeset
|
2317 |
SetDParam(0, t->index); |
0 | 2318 |
_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES; |
2319 |
return false; |
|
2320 |
} |
|
2321 |
||
2322 |
return true; |
|
2323 |
} |
|
2324 |
||
6247 | 2325 |
void TownsMonthlyLoop() |
0 | 2326 |
{ |
2327 |
Town *t; |
|
2328 |
||
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2329 |
FOR_ALL_TOWNS(t) { |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3983
diff
changeset
|
2330 |
if (t->road_build_months != 0) t->road_build_months--; |
0 | 2331 |
|
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
2332 |
if (t->exclusive_counter != 0) |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
2333 |
if (--t->exclusive_counter == 0) t->exclusivity = INVALID_PLAYER; |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
39
diff
changeset
|
2334 |
|
0 | 2335 |
UpdateTownGrowRate(t); |
2336 |
UpdateTownAmounts(t); |
|
2337 |
UpdateTownUnwanted(t); |
|
2338 |
} |
|
2339 |
} |
|
2340 |
||
6247 | 2341 |
void InitializeTowns() |
0 | 2342 |
{ |
2343 |
Subsidy *s; |
|
2344 |
||
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2345 |
/* Clean the town pool and create 1 block in it */ |
7401
7a72cc2a1196
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents:
7390
diff
changeset
|
2346 |
_Town_pool.CleanPool(); |
7a72cc2a1196
(svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents:
7390
diff
changeset
|
2347 |
_Town_pool.AddBlockToPool(); |
0 | 2348 |
|
2349 |
memset(_subsidies, 0, sizeof(_subsidies)); |
|
2350 |
for (s=_subsidies; s != endof(_subsidies); s++) |
|
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
2351 |
s->cargo_type = CT_INVALID; |
0 | 2352 |
|
2353 |
_cur_town_ctr = 0; |
|
1529
3a8196d15b01
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1517
diff
changeset
|
2354 |
_cur_town_iter = 0; |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2355 |
_total_towns = 0; |
0 | 2356 |
_town_sort_dirty = true; |
2357 |
} |
|
2358 |
||
7494
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7483
diff
changeset
|
2359 |
static CommandCost TerraformTile_Town(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new) |
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7483
diff
changeset
|
2360 |
{ |
7582
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2361 |
if (AutoslopeEnabled()) { |
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2362 |
HouseID house = GetHouseType(tile); |
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2363 |
HouseSpec *hs = GetHouseSpecs(house); |
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2364 |
|
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2365 |
/* Here we differ from TTDP by checking TILE_NOT_SLOPED */ |
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2366 |
if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) && |
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2367 |
(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return _price.terraform; |
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2368 |
} |
80c8517b08d1
(svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents:
7577
diff
changeset
|
2369 |
|
7494
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7483
diff
changeset
|
2370 |
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7483
diff
changeset
|
2371 |
} |
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7483
diff
changeset
|
2372 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
2373 |
extern const TileTypeProcs _tile_type_town_procs = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2374 |
DrawTile_Town, /* draw_tile_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2375 |
GetSlopeZ_Town, /* get_slope_z_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2376 |
ClearTile_Town, /* clear_tile_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2377 |
GetAcceptedCargo_Town, /* get_accepted_cargo_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2378 |
GetTileDesc_Town, /* get_tile_desc_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2379 |
GetTileTrackStatus_Town, /* get_tile_track_status_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2380 |
ClickTile_Town, /* click_tile_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2381 |
AnimateTile_Town, /* animate_tile_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2382 |
TileLoop_Town, /* tile_loop_clear */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2383 |
ChangeTileOwner_Town, /* change_tile_owner_clear */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2384 |
NULL, /* get_produced_cargo_proc */ |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2385 |
NULL, /* vehicle_enter_tile_proc */ |
7335
141c6b86ec1f
(svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents:
7333
diff
changeset
|
2386 |
GetFoundation_Town, /* get_foundation_proc */ |
7494
ab05bad37410
(svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents:
7483
diff
changeset
|
2387 |
TerraformTile_Town, /* terraform_tile_proc */ |
0 | 2388 |
}; |
2389 |
||
2390 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2391 |
/** Save and load of towns. */ |
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1840
diff
changeset
|
2392 |
static const SaveLoad _town_desc[] = { |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2393 |
SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2394 |
SLE_CONDVAR(Town, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
159
diff
changeset
|
2395 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2396 |
SLE_CONDVAR(Town, population, SLE_FILE_U16 | SLE_VAR_U32, 0, 2), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2397 |
SLE_CONDVAR(Town, population, SLE_UINT32, 3, SL_MAX_VERSION), |
0 | 2398 |
|
2399 |
||
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2400 |
SLE_VAR(Town, num_houses, SLE_UINT16), |
6956
3579bfc5157b
(svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents:
6950
diff
changeset
|
2401 |
SLE_CONDVAR(Town, townnamegrfid, SLE_UINT32, 66, SL_MAX_VERSION), |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2402 |
SLE_VAR(Town, townnametype, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2403 |
SLE_VAR(Town, townnameparts, SLE_UINT32), |
0 | 2404 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2405 |
SLE_VAR(Town, flags12, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2406 |
SLE_VAR(Town, statues, SLE_UINT8), |
0 | 2407 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2408 |
/* sort_index_obsolete was stored here in savegame format 0 - 1 */ |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3184
diff
changeset
|
2409 |
SLE_CONDNULL(1, 0, 1), |
0 | 2410 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2411 |
SLE_VAR(Town, have_ratings, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2412 |
SLE_ARR(Town, ratings, SLE_INT16, 8), |
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2413 |
/* failed bribe attempts are stored since savegame format 4 */ |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2414 |
SLE_CONDARR(Town, unwanted, SLE_INT8, 8, 4,SL_MAX_VERSION), |
1377
7ab329d1fc28
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1362
diff
changeset
|
2415 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2416 |
SLE_CONDVAR(Town, max_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2417 |
SLE_CONDVAR(Town, max_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2418 |
SLE_CONDVAR(Town, new_max_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2419 |
SLE_CONDVAR(Town, new_max_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2420 |
SLE_CONDVAR(Town, act_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2421 |
SLE_CONDVAR(Town, act_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2422 |
SLE_CONDVAR(Town, new_act_pass, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2423 |
SLE_CONDVAR(Town, new_act_mail, SLE_FILE_U16 | SLE_VAR_U32, 0, 8), |
0 | 2424 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2425 |
SLE_CONDVAR(Town, max_pass, SLE_UINT32, 9, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2426 |
SLE_CONDVAR(Town, max_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2427 |
SLE_CONDVAR(Town, new_max_pass, SLE_UINT32, 9, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2428 |
SLE_CONDVAR(Town, new_max_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2429 |
SLE_CONDVAR(Town, act_pass, SLE_UINT32, 9, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2430 |
SLE_CONDVAR(Town, act_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2431 |
SLE_CONDVAR(Town, new_act_pass, SLE_UINT32, 9, SL_MAX_VERSION), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2432 |
SLE_CONDVAR(Town, new_act_mail, SLE_UINT32, 9, SL_MAX_VERSION), |
0 | 2433 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2434 |
SLE_VAR(Town, pct_pass_transported, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2435 |
SLE_VAR(Town, pct_mail_transported, SLE_UINT8), |
0 | 2436 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2437 |
SLE_VAR(Town, act_food, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2438 |
SLE_VAR(Town, act_water, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2439 |
SLE_VAR(Town, new_act_food, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2440 |
SLE_VAR(Town, new_act_water, SLE_UINT16), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2441 |
|
6454
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2442 |
SLE_CONDVAR(Town, time_until_rebuild, SLE_UINT8, 0, 53), |
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2443 |
SLE_CONDVAR(Town, grow_counter, SLE_UINT8, 0, 53), |
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2444 |
SLE_CONDVAR(Town, growth_rate, SLE_UINT8, 0, 53), |
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2445 |
|
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2446 |
SLE_CONDVAR(Town, time_until_rebuild, SLE_UINT16, 54, SL_MAX_VERSION), |
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2447 |
SLE_CONDVAR(Town, grow_counter, SLE_UINT16, 54, SL_MAX_VERSION), |
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2448 |
SLE_CONDVAR(Town, growth_rate, SLE_INT16, 54, SL_MAX_VERSION), |
ad53226c2027
(svn r9613) -Feature: Make it possible to have some control over the town growth. The
maedhros
parents:
6427
diff
changeset
|
2449 |
|
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2450 |
SLE_VAR(Town, fund_buildings_months, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2451 |
SLE_VAR(Town, road_build_months, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2452 |
|
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2453 |
SLE_VAR(Town, exclusivity, SLE_UINT8), |
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4330
diff
changeset
|
2454 |
SLE_VAR(Town, exclusive_counter, SLE_UINT8), |
6486
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
2455 |
|
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
2456 |
SLE_CONDVAR(Town, larger_town, SLE_BOOL, 56, SL_MAX_VERSION), |
7d2ae0a167fb
(svn r9667) -Feature: Add the concept of cities. A (configurable) proportion of towns can
maedhros
parents:
6484
diff
changeset
|
2457 |
|
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
6357
diff
changeset
|
2458 |
/* reserve extra space in savegame here. (currently 30 bytes) */ |
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3184
diff
changeset
|
2459 |
SLE_CONDNULL(30, 2, SL_MAX_VERSION), |
0 | 2460 |
|
2461 |
SLE_END() |
|
2462 |
}; |
|
2463 |
||
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2464 |
/* Save and load the mapping between the house id on the map, and the grf file |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2465 |
* it came from. */ |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2466 |
static const SaveLoad _house_id_mapping_desc[] = { |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2467 |
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32), |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2468 |
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8), |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2469 |
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8), |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2470 |
SLE_END() |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2471 |
}; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2472 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2473 |
static void Save_HOUSEIDS() |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2474 |
{ |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2475 |
uint j = _house_mngr.GetMaxMapping(); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2476 |
|
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2477 |
for (uint i = 0; i < j; i++) { |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2478 |
SlSetArrayIndex(i); |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2479 |
SlObject(&_house_mngr.mapping_ID[i], _house_id_mapping_desc); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2480 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2481 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2482 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2483 |
static void Load_HOUSEIDS() |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2484 |
{ |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2485 |
int index; |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2486 |
|
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2487 |
_house_mngr.ResetMapping(); |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2488 |
uint max_id = _house_mngr.GetMaxMapping(); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2489 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2490 |
while ((index = SlIterateArray()) != -1) { |
6629
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2491 |
if ((uint)index >= max_id) break; |
eba0ac353e4d
(svn r9850) -Codechange: Introduction of the Override/Substitute manager. Currently only used for newhouses.
belugas
parents:
6610
diff
changeset
|
2492 |
SlObject(&_house_mngr.mapping_ID[index], _house_id_mapping_desc); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2493 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2494 |
} |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2495 |
|
6247 | 2496 |
static void Save_TOWN() |
0 | 2497 |
{ |
2498 |
Town *t; |
|
2499 |
||
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2500 |
FOR_ALL_TOWNS(t) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2501 |
SlSetArrayIndex(t->index); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2502 |
SlObject(t, _town_desc); |
0 | 2503 |
} |
2504 |
} |
|
2505 |
||
6247 | 2506 |
static void Load_TOWN() |
0 | 2507 |
{ |
2508 |
int index; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
2509 |
|
1261
914ecc20a2df
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
2510 |
_total_towns = 0; |
914ecc20a2df
(svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents:
1260
diff
changeset
|
2511 |
|
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2512 |
while ((index = SlIterateArray()) != -1) { |
7386
93f6a042d1c3
(svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents:
7370
diff
changeset
|
2513 |
Town *t = new (index) Town(); |
0 | 2514 |
SlObject(t, _town_desc); |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2515 |
|
5298
46eabcb5c2b2
(svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents:
5247
diff
changeset
|
2516 |
_total_towns++; |
0 | 2517 |
} |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2518 |
|
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2519 |
/* This is to ensure all pointers are within the limits of |
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2520 |
* the size of the TownPool */ |
5247
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
2521 |
if (_cur_town_ctr > GetMaxTownIndex()) |
1260
632f63689178
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1252
diff
changeset
|
2522 |
_cur_town_ctr = 0; |
0 | 2523 |
} |
2524 |
||
6247 | 2525 |
void AfterLoadTown() |
0 | 2526 |
{ |
2527 |
Town *t; |
|
2528 |
FOR_ALL_TOWNS(t) { |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
2529 |
UpdateTownRadius(t); |
0 | 2530 |
} |
2531 |
_town_sort_dirty = true; |
|
2532 |
} |
|
2533 |
||
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
2534 |
extern const ChunkHandler _town_chunk_handlers[] = { |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2535 |
{ 'HIDS', Save_HOUSEIDS, Load_HOUSEIDS, CH_ARRAY }, |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2536 |
{ 'CITY', Save_TOWN, Load_TOWN, CH_ARRAY | CH_LAST}, |
0 | 2537 |
}; |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2538 |
|
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2539 |
void ResetHouses() |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2540 |
{ |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2541 |
memset(&_house_specs, 0, sizeof(_house_specs)); |
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2542 |
memcpy(&_house_specs, &_original_house_specs, sizeof(_original_house_specs)); |
7666
69cabc700c4d
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
7657
diff
changeset
|
2543 |
|
69cabc700c4d
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
7657
diff
changeset
|
2544 |
/* Reset any overrides that have been set. */ |
69cabc700c4d
(svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents:
7657
diff
changeset
|
2545 |
_house_mngr.ResetOverride(); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6257
diff
changeset
|
2546 |
} |