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