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