town_cmd.c
author truelight
Sat, 26 Aug 2006 14:22:54 +0000
changeset 4384 7e0d3ed719d9
parent 4357 aaba385fa723
child 4396 28cfaf264db6
permissions -rw-r--r--
(svn r6137) -Codechange: some very minor cleanups:
- Start using DeleteXXX for every pool item, not manually doing it
- Use some wrapper to improve logic
- Rewrote some pieces to improve logic
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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     4
#include "openttd.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     5
#include "functions.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
     6
#include "strings.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3071
diff changeset
     7
#include "road_map.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     8
#include "table/strings.h"
2148
542ea702738c (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
     9
#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
    10
#include "map.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
    11
#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
    12
#include "town_map.h"
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3150
diff changeset
    13
#include "tunnel_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "gui.h"
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
    25
#include "unmovable_map.h"
3433
4e0d2ea104b3 (svn r4262) -Codechange: use IsClearWaterTile instead of some "home-brewn" marco. town_cmd is now map access free
celestar
parents: 3432
diff changeset
    26
#include "water_map.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    27
#include "variables.h"
3359
633290bf1117 (svn r4154) -Moved MAX_BRIDGES in bridge.h and made it an enum. This makes two drops ...
celestar
parents: 3319
diff changeset
    28
#include "bridge.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4231
diff changeset
    29
#include "date.h"
3654
c09872510a61 (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    30
#include "table/town_land.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4261
diff changeset
    31
#include "genworld.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
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
    33
enum {
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    34
	/* Max towns: 64000 (8 * 8000) */
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    35
	TOWN_POOL_BLOCK_SIZE_BITS = 3,       /* In bits, so (1 << 3) == 8 */
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    36
	TOWN_POOL_MAX_BLOCKS      = 8000,
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    37
};
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    38
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    39
/**
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    40
 * 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
    41
 */
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    42
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
    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
	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
    45
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    46
	/* 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
    47
	 * TODO - This is just a temporary stage, this will be removed. */
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    48
	for (t = GetTown(start_item); t != NULL; t = (t->index + 1 < GetTownPoolSize()) ? GetTown(t->index + 1) : 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
    49
}
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    50
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
    51
/* Initialize the town-pool */
3585
43461f26b729 (svn r4471) - Pools: Add a facility for calling a custom function during pool block clean up.
peter1138
parents: 3491
diff changeset
    52
MemoryPool _town_pool = { "Towns", TOWN_POOL_MAX_BLOCKS, TOWN_POOL_BLOCK_SIZE_BITS, sizeof(Town), &TownPoolNewBlock, NULL, 0, 0, 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
    53
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
// Local
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
static int _grow_town_result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
    57
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
    58
static void ClearTownHouse(Town *t, TileIndex tile);
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
    59
static void DoBuildTownHouse(Town *t, TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
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
    61
static void TownDrawHouseLift(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
{
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
    63
	AddChildSpriteScreen(SPR_LIFT, 14, 60 - GetLiftPosition(ti->tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
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
    66
typedef void TownDrawTileProc(const TileInfo *ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
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
    68
	TownDrawHouseLift
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
static void DrawTile_Town(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
{
3654
c09872510a61 (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    74
	const DrawBuildingsTileStruct *dcts;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
	/* Retrieve pointer to the draw town tile struct */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
	{
480
2e915fd96ac3 (svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents: 473
diff changeset
    79
		/* this "randomizes" on the (up to) 4 variants of a building */
2e915fd96ac3 (svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents: 473
diff changeset
    80
		uint variant;
2e915fd96ac3 (svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents: 473
diff changeset
    81
		variant  = ti->x >> 4;
2e915fd96ac3 (svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents: 473
diff changeset
    82
		variant ^= ti->x >> 6;
2e915fd96ac3 (svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents: 473
diff changeset
    83
		variant ^= ti->y >> 4;
2e915fd96ac3 (svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents: 473
diff changeset
    84
		variant -= ti->y >> 6;
2e915fd96ac3 (svn r756) Demystify and explain some piece of code regarding which house sprite to draw
tron
parents: 473
diff changeset
    85
		variant &= 3;
3654
c09872510a61 (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    86
		dcts = &_town_draw_tile_data[GetHouseType(ti->tile) << 4 | variant << 2 | GetHouseBuildingStage(ti->tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
4053
7396defc2412 (svn r5327) Use DrawFoundation() for houses
tron
parents: 4000
diff changeset
    89
	if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
7396defc2412 (svn r5327) Use DrawFoundation() for houses
tron
parents: 4000
diff changeset
    90
	DrawGroundSprite(dcts->ground);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	/* Add a house on top of the ground? */
3654
c09872510a61 (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    93
	image = dcts->building;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
    94
	if (image != 0) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
    95
		if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
    96
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
    97
		AddSortableSpriteToDraw(image,
482
3999e4338a7c (svn r760) Replace some bit-juggling with bit fields
tron
parents: 480
diff changeset
    98
			ti->x + dcts->subtile_x,
3999e4338a7c (svn r760) Replace some bit-juggling with bit fields
tron
parents: 480
diff changeset
    99
			ti->y + dcts->subtile_y,
3999e4338a7c (svn r760) Replace some bit-juggling with bit fields
tron
parents: 480
diff changeset
   100
			dcts->width + 1,
3999e4338a7c (svn r760) Replace some bit-juggling with bit fields
tron
parents: 480
diff changeset
   101
			dcts->height + 1,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
			dcts->dz,
4053
7396defc2412 (svn r5327) Use DrawFoundation() for houses
tron
parents: 4000
diff changeset
   103
			ti->z
7396defc2412 (svn r5327) Use DrawFoundation() for houses
tron
parents: 4000
diff changeset
   104
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   106
		if (_display_opt & DO_TRANS_BUILDINGS) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	{
3654
c09872510a61 (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
   110
		int proc = dcts->draw_proc - 1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   111
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   112
		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
   113
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4077
diff changeset
   116
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
   117
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4077
diff changeset
   118
	return GetTileMaxZ(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   121
static Slope GetSlopeTileh_Town(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 4
diff changeset
   122
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   123
	return SLOPE_FLAT;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 4
diff changeset
   124
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 4
diff changeset
   125
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   126
static void AnimateTile_Town(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
{
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   128
	int pos, dest;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   130
	if (_tick_counter & 3) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
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
   132
	// If the house is not one with a lift anymore, then stop this animating.
c3810847175d (svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents: 2061
diff changeset
   133
	// Not exactly sure when this happens, but probably when a house changes.
c3810847175d (svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents: 2061
diff changeset
   134
	// Before this was just a return...so it'd leak animated tiles..
c3810847175d (svn r2574) Fix: AnimatedTile leak in town_cmd.c (this one has probably been here since day 1)
ludde
parents: 2061
diff changeset
   135
	// That bug seems to have been here since day 1??
3377
608cf1405409 (svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents: 3359
diff changeset
   136
	if (!(_housetype_extra_flags[GetHouseType(tile)] & 0x20)) {
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
   137
		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
   138
		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
   139
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   141
	if (!IsLiftMoving(tile)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   142
		int i;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   143
2891
7a9dbadd3f28 (svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents: 2817
diff changeset
   144
		/** Building has 6 floors, number 0 .. 6, where 1 is illegal.
7a9dbadd3f28 (svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents: 2817
diff changeset
   145
		 *  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
   146
		 *  the height of 2 'normal' floors.
7a9dbadd3f28 (svn r3445) - Fix: [ 1415379 ] Enhance documentation of lift destination
Darkvater
parents: 2817
diff changeset
   147
		 *  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
   148
		do {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   149
			i = (Random() & 7) - 1;
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   150
		} 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
   151
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   152
		SetLiftDestination(tile, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   155
	pos = GetLiftPosition(tile);
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   156
	dest = GetLiftDestination(tile) * 6;
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   157
	pos += (pos < dest) ? 1 : -1;
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   158
	SetLiftPosition(tile, pos);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   160
	if (pos == dest) HaltLift(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   161
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
static void UpdateTownRadius(Town *t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   167
static bool IsCloseToTown(TileIndex tile, uint dist)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
{
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2549
diff changeset
   169
	const Town* t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	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
   172
		if (DistanceManhattan(tile, t->xy) < dist) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   177
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
   178
{
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   179
	MarkAllViewportsDirty(
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   180
		t->sign.left-6,
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   181
		t->sign.top-3,
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   182
		t->sign.left+t->sign.width_1*4+12,
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   183
		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
   184
	);
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   185
}
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   186
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   187
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
   188
{
836
8d2ecd281d34 (svn r1313) -Fix: fixed MSVC problem
truelight
parents: 835
diff changeset
   189
	Point pt;
8d2ecd281d34 (svn r1313) -Fix: fixed MSVC problem
truelight
parents: 835
diff changeset
   190
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   191
	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
   192
	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
   193
	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
   194
	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
   195
	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
   196
		_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
   197
	MarkTownSignDirty(t);
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   198
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
static void ChangePopulation(Town *t, int mod)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	t->population += mod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	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
   204
	UpdateTownVirtCoord(t);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	if (_town_sort_order & 2) _town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
   209
uint32 GetWorldPopulation(void)
1080
23797dda4792 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1041
diff changeset
   210
{
23797dda4792 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1041
diff changeset
   211
	uint32 pop;
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2549
diff changeset
   212
	const Town* t;
7206058a7e82 (svn r3172) static, const
tron
parents: 2549
diff changeset
   213
1080
23797dda4792 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1041
diff changeset
   214
	pop = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   215
	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
   216
	return pop;
23797dda4792 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1041
diff changeset
   217
}
23797dda4792 (svn r1581) Added a display for the total map population to the town display (Jango)
celestar
parents: 1041
diff changeset
   218
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   219
static void MakeSingleHouseBigger(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
{
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
   221
	assert(IsTileType(tile, MP_HOUSE));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   222
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   223
	if (LiftHasDestination(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   225
	IncHouseConstructionTick(tile);
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   226
	if (GetHouseConstructionTick(tile) != 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   228
	IncHouseBuildingStage(tile);  /*increase construction stage of one more step*/
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   230
	if (GetHouseBuildingStage(tile) == TOWN_HOUSE_COMPLETED){
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   231
		/*Now, construction is completed.  Can add population of building to the town*/
3377
608cf1405409 (svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents: 3359
diff changeset
   232
		ChangePopulation(GetTownByTile(tile), _housetype_population[GetHouseType(tile)]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   237
static void MakeTownHouseBigger(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
{
3377
608cf1405409 (svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents: 3359
diff changeset
   239
	uint flags = _house_more_flags[GetHouseType(tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	if (flags & 8) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	if (flags & 4) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	if (flags & 2) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	if (flags & 1) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   246
static void TileLoop_Town(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	int house;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   252
	if (GetHouseBuildingStage(tile) != TOWN_HOUSE_COMPLETED) {
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   253
		/*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
   254
		MakeTownHouseBigger(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
3377
608cf1405409 (svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents: 3359
diff changeset
   258
	house = GetHouseType(tile);
3426
451a6367552d (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3422
diff changeset
   259
	if ((_housetype_extra_flags[house] & 0x20) && !LiftHasDestination(tile) && CHANCE16(1, 2) && AddAnimatedTile(tile)) BeginLiftMovement(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
3319
16c0f06829a5 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents: 3310
diff changeset
   261
	t = GetTownByTile(tile);
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
	r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   265
	if (GB(r, 0, 8) < _housetype_population[house]) {
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   266
		uint amt = GB(r, 0, 8) / 8 + 1;
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   267
		uint moved;
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   268
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
		if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
		t->new_max_pass += amt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
		moved = MoveGoodsToStation(tile, 1, 1, CT_PASSENGERS, amt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
		t->new_act_pass += moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   275
	if (GB(r, 8, 8) < _housetype_mailamount[house] ) {
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   276
		uint amt = GB(r, 8, 8) / 8 + 1;
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   277
		uint moved;
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   278
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
		if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
		t->new_max_mail += amt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		moved = MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
		t->new_act_mail += moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   285
	if (_house_more_flags[house] & 8 && HASBIT(t->flags12, TOWN_IS_FUNDED) && --t->time_until_rebuild == 0) {
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   286
		t->time_until_rebuild = GB(r, 16, 6) + 130;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
		_current_player = OWNER_TOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
		ClearTownHouse(t, tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   291
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
		// rebuild with another house?
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   293
		if (GB(r, 24, 8) >= 12) DoBuildTownHouse(t, tile);
314
75fe42199623 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 260
diff changeset
   294
75fe42199623 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 260
diff changeset
   295
		_current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   299
static void ClickTile_Town(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   304
static int32 ClearTile_Town(TileIndex tile, byte flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	int house, rating;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	// safety checks
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	if (flags&DC_AUTO && !(flags&DC_AI_BUILDING)) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
3377
608cf1405409 (svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents: 3359
diff changeset
   314
	house = GetHouseType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	cost = _price.remove_house * _housetype_remove_cost[house] >> 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	rating = _housetype_remove_ratingmod[house];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	_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
   319
	_cleared_town = t = GetTownByTile(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   320
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
	if (_current_player < MAX_PLAYERS) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
		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
   323
			SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
			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
   325
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	if (flags & DC_EXEC) {
1005
f48b2bdd84fc (svn r1504) enummed town ratings (Jango)
celestar
parents: 926
diff changeset
   329
		ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
		ClearTownHouse(t, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   336
static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
{
3377
608cf1405409 (svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents: 3359
diff changeset
   338
	byte type = GetHouseType(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   339
473
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 470
diff changeset
   340
	ac[CT_PASSENGERS] = _housetype_cargo_passengers[type];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   341
	ac[CT_MAIL]       = _housetype_cargo_mail[type];
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   342
	ac[CT_GOODS]      = _housetype_cargo_goods[type];
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   343
	ac[CT_FOOD]       = _housetype_cargo_food[type];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   346
static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
{
3377
608cf1405409 (svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents: 3359
diff changeset
   348
	td->str = _town_tile_names[GetHouseType(tile)];
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   349
	if (GetHouseBuildingStage(tile) != TOWN_HOUSE_COMPLETED) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 516
diff changeset
   350
		SetDParamX(td->dparam, 0, td->str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
		td->str = STR_2058_UNDER_CONSTRUCTION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	td->owner = OWNER_TOWN;
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
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   357
static uint32 GetTileTrackStatus_Town(TileIndex tile, TransportType mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
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
   363
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
   364
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   369
static const TileIndexDiffC _roadblock_tileadd[] = {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   370
	{ 0, -1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   371
	{ 1,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   372
	{ 0,  1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   373
	{-1,  0},
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   374
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
	// Store the first 3 elements again.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	// Lets us rotate without using &3.
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   377
	{ 0, -1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   378
	{ 1,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   379
	{ 0,  1}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2791
diff changeset
   382
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2791
diff changeset
   383
static bool GrowTown(Town *t);
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2791
diff changeset
   384
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
static void TownTickHandler(Town *t)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
{
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   387
	if (HASBIT(t->flags12, TOWN_IS_FUNDED)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
		int i = t->grow_counter - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
		if (i < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
			if (GrowTown(t)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
				i = t->growth_rate;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
			} else {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   393
				i = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
		t->grow_counter = i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	UpdateTownRadius(t);
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
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
   402
void OnTick_Town(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   404
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
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
   406
	/* 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
   407
	 * same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   408
	for (_cur_town_iter += GetTownArraySize();
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
   409
	     _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
   410
	     _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
   411
		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
   412
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
   413
		if (++_cur_town_ctr >= GetTownArraySize())
1448
472b3b3855e7 (svn r1952) Fix: Hopefully fixed the enormous towns growth slowdown in large maps. (Inspired by toholio.)
pasky
parents: 1421
diff changeset
   414
			_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
   415
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
   416
		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
   417
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
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
   420
static RoadBits GetTownRoadMask(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
{
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
   422
	TrackBits b = GetAnyRoadTrackBits(tile);
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
   423
	RoadBits r = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   424
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
   425
	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
   426
	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
   427
	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
   428
	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
   429
	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
   430
	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
   431
	return r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   434
static bool IsRoadAllowedHere(TileIndex tile, int dir)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   436
	Slope k;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   437
	Slope slope;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	// If this assertion fails, it might be because the world contains
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
	//  land at the edges. This is not ok.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	TILE_ASSERT(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   442
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   443
	for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		// Check if there already is a road at this point?
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
   445
		if (GetAnyRoadTrackBits(tile) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
			// No, try to build one in the direction.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
			// if that fails clear the land, and if that fails exit.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
			// 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
   449
			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
   450
					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
   451
				return false;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
		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
   455
		if (slope == SLOPE_FLAT) {
465
21f9985e12d1 (svn r694) Make the town sometimes build streets on slopes.
pasky
parents: 314
diff changeset
   456
no_slope:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
			// Tile has no slope
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
			// Disallow the road if any neighboring tile has a road.
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   459
			if (HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+1]))), dir^2) ||
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   460
					HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+3]))), dir^2) ||
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   461
					HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+1]) + ToTileIndexDiff(_roadblock_tileadd[dir+2]))), dir) ||
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   462
					HASBIT(GetTownRoadMask(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[dir+3]) + ToTileIndexDiff(_roadblock_tileadd[dir+2]))), dir))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
				return false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   464
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
			// Otherwise allow
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   468
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
		// If the tile is not a slope in the right direction, then
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
		// 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
   471
		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
   472
		if (k != slope && ComplementSlope(k) != slope) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
			uint32 r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   475
			if (CHANCE16I(1, 8, r) && !_generating_world) {
465
21f9985e12d1 (svn r694) Make the town sometimes build streets on slopes.
pasky
parents: 314
diff changeset
   476
				int32 res;
21f9985e12d1 (svn r694) Make the town sometimes build streets on slopes.
pasky
parents: 314
diff changeset
   477
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   478
				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
   479
					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
   480
					                      CMD_TERRAFORM_LAND);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   481
				} else {
3639
c27c9e4fddbd (svn r4547) Revert a part of r4541 to silence an assertion for now
tron
parents: 3636
diff changeset
   482
					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
   483
					                      CMD_TERRAFORM_LAND);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   484
				}
2646
c01dfbc7b7e3 (svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents: 2639
diff changeset
   485
				if (CmdFailed(res) && CHANCE16I(1, 3, r)) {
465
21f9985e12d1 (svn r694) Make the town sometimes build streets on slopes.
pasky
parents: 314
diff changeset
   486
					// We can consider building on the slope, though.
21f9985e12d1 (svn r694) Make the town sometimes build streets on slopes.
pasky
parents: 314
diff changeset
   487
					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
   488
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
		}
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
   492
		return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   496
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
   497
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
	int32 r;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   499
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
	TILE_ASSERT(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
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
   502
	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
   503
	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
   504
	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
   505
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   508
static void LevelTownLand(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   510
	Slope tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	TILE_ASSERT(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
	// 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
   515
	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
   516
	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
   517
	if (tileh == SLOPE_FLAT) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	// 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
   520
	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
   521
		TerraformTownTile(tile, tileh & 0xF, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
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
   525
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
   526
{
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
   527
	RoadBits rcmd;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   528
	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
   529
	DiagDirection i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
	int j;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   531
	TileIndex tile = *tile_ptr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
	TILE_ASSERT(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
	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
   536
		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
   537
		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
   538
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
		// Tile has no road. First reset the status counter
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   540
		// to say that this is the last iteration.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
		_grow_town_result = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
		// Remove hills etc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
		LevelTownLand(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
		// Is a road allowed here?
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   547
		if (!IsRoadAllowedHere(tile, block)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
		// Randomize new road block numbers
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
		a = block;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
		b = block ^ 2;
2637
722dae65c4a8 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2635
diff changeset
   552
		if (CHANCE16(1, 4)) {
722dae65c4a8 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2635
diff changeset
   553
			do {
722dae65c4a8 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2635
diff changeset
   554
				a = GB(Random(), 0, 2);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   555
			} while (a == b);
2637
722dae65c4a8 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2635
diff changeset
   556
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   558
		if (!IsRoadAllowedHere(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a])), a)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
			// A road is not allowed to continue the randomized road,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
			//   return if the road we're trying to build is curved.
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   561
			if (a != (b ^ 2)) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   562
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
			// Return if neither side of the new road is a house
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
   564
			if (!IsTileType(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a + 1])), MP_HOUSE) &&
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
   565
					!IsTileType(TILE_ADD(tile, ToTileIndexDiff(_roadblock_tileadd[a + 3])), MP_HOUSE))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
				return;
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
			// That means that the road is only allowed if there is a house
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
			//  at any side of the new road.
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
		rcmd = (1 << a) + (1 << b);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
	} else if (block < 5 && !HASBIT(mask,block^2)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
		// Continue building on a partial road.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
		// Always OK.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
		_grow_town_result = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   577
		rcmd = 1 << (block ^ 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
	} 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
   579
		int i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
		// Reached a tunnel? Then continue at the other side of it.
3184
118a520164e4 (svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents: 3154
diff changeset
   582
		if (IsTunnelTile(tile) && GetTunnelTransportType(tile) == TRANSPORT_ROAD) {
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3150
diff changeset
   583
			*tile_ptr = GetOtherTunnelEnd(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   586
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
		// For any other kind of tunnel/bridge, bail out.
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   588
		if (IsTileType(tile, MP_TUNNELBRIDGE)) return;
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
		// Possibly extend the road in a direction.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
		// Randomize a direction and if it has a road, bail out.
2635
7ed07303448d (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2630
diff changeset
   592
		i = GB(Random(), 0, 2);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   593
		if (HASBIT(mask, i)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
		// 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
   596
		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
   597
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
		// 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
   599
		if (IsClearWaterTile(tmptile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   601
		// Build a house at the edge. 60% chance or
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
		//  always ok if no road allowed.
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   603
		if (!IsRoadAllowedHere(tmptile, i) || CHANCE16(6, 10)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
			// 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
   605
			if (!IsTileType(tmptile, MP_HOUSE)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
				// Level the land if possible
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
				LevelTownLand(tmptile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
				// And build a house.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
				// Set result to -1 if we managed to build it.
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   611
				if (BuildTownHouse(t1, tmptile)) _grow_town_result = -1;
0
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
			return;
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
		_grow_town_result = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
		rcmd = 1 << i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	// 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
   621
	if (IsClearWaterTile(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
	// Determine direction of slope,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	//  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
   625
	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
   626
		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
   627
		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
   628
		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
   629
		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
   630
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
   631
		default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
build_road_and_exit:
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
   633
			if (!CmdFailed(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
   634
				_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
   635
			}
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
   636
			return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	tmptile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	// Now it contains the direction of the slope
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
	j = -11;	// max 11 tile long bridges
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
		if (++j == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
			goto build_road_and_exit;
900
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
   646
		tmptile = TILE_MASK(tmptile + TileOffsByDir(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
   647
	} while (IsClearWaterTile(tmptile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	// no water tiles in between?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	if (j == -10)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
		goto build_road_and_exit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	// Quit if it selecting an appropiate bridge type fails a large number of times.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	j = 22;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
		int32 bridge_len = GetBridgeLength(tile, tmptile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
			byte bridge_type = RandomRange(MAX_BRIDGES - 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
			if (CheckBridge_Stuff(bridge_type, bridge_len)) {
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
   660
				if (!CmdFailed(DoCommand(tile, tmptile, 0x8000 + bridge_type, DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
					_grow_town_result = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
				// obviously, if building any bridge would fail, there is no need to try other bridge-types
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
			}
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   666
		} while (--j != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
// Returns true if a house was built, or no if the build failed.
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   671
static int GrowTownAtRoad(Town *t, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
	int block = 5; // special case
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
	TILE_ASSERT(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	// Number of times to search.
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
   678
	_grow_town_result = 10 + t->num_houses * 4 / 9;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
		// 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
   682
		RoadBits mask = GetTownRoadMask(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
		// Try to grow the town from this point
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
		GrowTownInTile(&tile,mask,block,t);
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
		// Exclude the source position from the bitmask
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
		// and return if no more road blocks available
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
		CLRBIT(mask, (block ^ 2));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
		if (mask == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
			return _grow_town_result;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
		// Select a random bit from the blockmask, walk a step
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
		// and continue the search from there.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
		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
   696
		tile += ToTileIndexDiff(_roadblock_tileadd[block]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
1327
6e507eb10edd (svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents: 1309
diff changeset
   698
		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
   699
			/* 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
   700
			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
   701
				_grow_town_result = -1;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4053
diff changeset
   702
			} 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
   703
				/* If we are in the SE, and this road-piece has no town owner yet, it just found an
6e507eb10edd (svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents: 1309
diff changeset
   704
				*  owner :) (happy happy happy road now) */
1902
86b7fb11f938 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
   705
				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
   706
				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
   707
			}
6e507eb10edd (svn r1831) -Fix: Scenario Editor now handles human-made roads better (try to build
truelight
parents: 1309
diff changeset
   708
		}
1280
33a251c30758 (svn r1784) -Fix: removed ClosestTownFromTile where possible, or replaced it
truelight
parents: 1264
diff changeset
   709
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
		// Max number of times is checked.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
	} while (--_grow_town_result >= 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
	return (_grow_town_result == -2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
// Generate a random road block
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
// The probability of a straight road
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
// is somewhat higher than a curved.
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
   719
static RoadBits GenRandomRoadBits(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
	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
   722
	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
   723
	uint b = GB(r, 8, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	if (a == b) b ^= 2;
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
   725
	return (1 << a) + (1 << b);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
// Grow the town
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
// Returns true if a house was built, or no if the build failed.
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2791
diff changeset
   730
static bool GrowTown(Town *t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
   732
	TileIndex tile;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   733
	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
   734
	PlayerID old_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   736
	static const TileIndexDiffC _town_coord_mod[] = {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   737
		{-1,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   738
		{ 1,  1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   739
		{ 1, -1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   740
		{-1, -1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   741
		{-1,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   742
		{ 0,  2},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   743
		{ 2,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   744
		{ 0, -2},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   745
		{-1, -1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   746
		{-2,  2},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   747
		{ 2,  2},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   748
		{ 2, -2},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   749
		{ 0,  0}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	// Current player is a town
260
4819bcce8389 (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 193
diff changeset
   753
	old_player = _current_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
	_current_player = OWNER_TOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
	// Find a road that we can base the construction on.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
	tile = t->xy;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   758
	for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
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
   759
		if (GetAnyRoadTrackBits(tile) != 0) {
260
4819bcce8389 (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 193
diff changeset
   760
			int r = GrowTownAtRoad(t, tile);
4819bcce8389 (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 193
diff changeset
   761
			_current_player = old_player;
4819bcce8389 (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 193
diff changeset
   762
			return r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
		}
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   764
		tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   765
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
	// No road available, try to build a random road block by
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
	// clearing some land and then building a road there.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	tile = t->xy;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   770
	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
   771
		/* 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
   772
		if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) {
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
   773
			if (!CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) {
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
   774
				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
   775
				_current_player = old_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
		}
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   779
		tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   780
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
260
4819bcce8389 (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 193
diff changeset
   782
	_current_player = old_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
static void UpdateTownRadius(Town *t)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
	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
   789
		{  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
   790
		{ 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
   791
		{ 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
   792
		{ 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
   793
		{ 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
   794
		{ 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
   795
		{ 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
   796
		{ 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
   797
		{ 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
   798
		{ 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
   799
		{ 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
   800
		{ 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
   801
		{ 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
   802
		{ 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
   803
		{ 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
   804
		{ 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
   805
		{ 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
   806
		{ 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
   807
		{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
   808
		{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
   809
		{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
   810
		{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
   811
		{121, 81,  0, 49, 36}, // 88
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
	};
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
   813
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
   814
	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
   815
		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
   816
	} 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
   817
		int mass = t->num_houses / 8;
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
   818
		// At least very roughly extrapolate. Empirical numbers dancing between
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
   819
		// overwhelming by cottages and skyscrapers outskirts.
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
   820
		t->radius[0] = mass * mass;
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
   821
		// Actually we are proportional to sqrt() but that's right because
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
   822
		// we are covering an area.
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
   823
		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
   824
		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
   825
		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
   826
		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
   827
		//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
   828
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
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
   831
static bool CreateTownName(uint32 *townnameparts)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
	Town *t2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
	char buf1[64];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
	char buf2[64];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
	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
   837
	/* 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
   838
	 * 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
   839
	 * 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
   840
	 * 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
   841
	 * 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
   842
	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
   843
	uint16 townnametype = SPECSTR_TOWNNAME_START + _opt.town_name;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
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
   845
	assert(townnameparts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   847
	for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
restart:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
		r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 516
diff changeset
   851
		SetDParam(0, 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
   852
		GetString(buf1, townnametype);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   853
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
		// Check size and width
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
   855
		if (strlen(buf1) >= 31 || GetStringWidth(buf1) > 130) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
		FOR_ALL_TOWNS(t2) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   858
			// We can't just compare the numbers since
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   859
			// several numbers may map to a single name.
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   860
			SetDParam(0, t2->index);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   861
			GetString(buf2, STR_TOWN);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   862
			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
   863
				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
   864
				goto restart;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
		}
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
   867
		*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
   868
		return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
1377
7ab329d1fc28 (svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents: 1362
diff changeset
   872
void UpdateTownMaxPass(Town *t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
	t->max_pass = t->population >> 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
	t->max_mail = t->population >> 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
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
   878
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, uint size_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	int x, i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
	// clear the town struct
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
	i = t->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
	memset(t, 0, sizeof(Town));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
	t->index = i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	t->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	t->num_houses = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	t->time_until_rebuild = 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
	UpdateTownRadius(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
	t->flags12 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
	t->population = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
	t->grow_counter = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
	t->growth_rate = 250;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	t->new_max_pass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	t->new_max_mail = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
	t->new_act_pass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	t->new_act_mail = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
	t->max_pass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	t->max_mail = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	t->act_pass = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
	t->act_mail = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	t->pct_pass_transported = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	t->pct_mail_transported = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	t->fund_buildings_months = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
	t->new_act_food = 0;
4
cad62d5f9708 (svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents: 0
diff changeset
   908
	t->new_act_water = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	t->act_food = 0;
4
cad62d5f9708 (svn r5) -Fix: townname generation of TTDLX savegames. All work
darkvater
parents: 0
diff changeset
   910
	t->act_water = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   912
	for (i = 0; i != MAX_PLAYERS; i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
		t->ratings[i] = 500;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	t->have_ratings = 0;
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 39
diff changeset
   916
	t->exclusivity = (byte)-1;
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 39
diff changeset
   917
	t->exclusive_counter = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
	t->statues = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
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
   920
	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
   921
	t->townnameparts = townnameparts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   922
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
	UpdateTownVirtCoord(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
	_town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
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
   926
	if (size_mode == 0) {
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
   927
		x = (Random() & 0xF) + 8;
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
   928
	} else {
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
   929
		x = (size_mode - 1) * 16 + 3;
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
   930
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	t->num_houses += x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
	UpdateTownRadius(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
	i = x * 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
		GrowTown(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
	t->num_houses -= x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
	UpdateTownRadius(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	UpdateTownMaxPass(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
   945
static Town *AllocateTown(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	Town *t;
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   948
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   949
	/* 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
   950
	 * TODO - This is just a temporary stage, this will be removed. */
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   951
	for (t = GetTown(0); t != NULL; t = (t->index + 1 < GetTownPoolSize()) ? GetTown(t->index + 1) : NULL) {
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   952
		if (!IsValidTown(t)) {
4330
cf31daa8b321 (svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents: 4317
diff changeset
   953
			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
   954
4357
aaba385fa723 (svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents: 4355
diff changeset
   955
			if (t->index >= _total_towns) _total_towns = t->index + 1;
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
   956
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
   957
			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
   958
			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
   959
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
			return t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	}
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
   963
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
   964
	/* Check if we can add a block to the pool */
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
   965
	if (AddBlockToPool(&_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
   966
		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
   967
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
   971
/** Create a new town.
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
   972
 * 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
   973
 * 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
   974
 * @param tile coordinates where town is built
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
   975
 * @param p1 size of the town (1 = small, 2 = medium, 3 = large)
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
   976
 * @param p2 unused
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
   977
 */
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
   978
int32 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
   979
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	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
   981
	uint32 townnameparts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   982
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
   983
	/* Only in the scenario editor */
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
   984
	if (_game_mode != GM_EDITOR) return CMD_ERROR;
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
   985
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
	// 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
   989
	if (DistanceFromEdge(tile) < 12)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
		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
   991
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
	// Can only build on clear flat areas.
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   993
	if (!IsTileType(tile, MP_CLEAR) || GetTileSlope(tile, NULL) != SLOPE_FLAT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
		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
   995
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
	// Check distance to all other towns.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	if (IsCloseToTown(tile, 20))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
		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
  1000
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
  1001
	// Get a unique name for the town.
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
  1002
	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
  1003
		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
  1004
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	// Allocate town struct
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	t = AllocateTown();
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1007
	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
  1008
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	// Create the town
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
		_generating_world = true;
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
  1012
		DoCreateTown(t, tile, townnameparts, p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
		_generating_world = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
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
  1018
Town *CreateRandomTown(uint attempts, uint size_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1020
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
	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
  1022
	uint32 townnameparts;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
		// Generate a tile index not too close from the edge
2051
e369160ce2f3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
  1026
		tile = RandomTile();
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1027
		if (DistanceFromEdge(tile) < 20) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
		// 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
  1030
		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
  1031
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
		// Check not too close to a town
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1033
		if (IsCloseToTown(tile, 20)) continue;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1034
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
  1035
		// Get a unique name for the town.
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1036
		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
  1037
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
		// Allocate a town struct
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
		t = AllocateTown();
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1040
		if (t == NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
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
  1042
		DoCreateTown(t, tile, townnameparts, size_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
		return t;
1362
bceb3c57353d (svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents: 1335
diff changeset
  1044
	} while (--attempts);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
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
  1048
static const byte _num_initial_towns[3] = {11, 23, 46};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
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
  1050
bool GenerateTowns(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
{
1362
bceb3c57353d (svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents: 1335
diff changeset
  1052
	uint num = 0;
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
  1053
	uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
1202
4d2a20c50760 (svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
tron
parents: 1174
diff changeset
  1054
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4261
diff changeset
  1055
	SetGeneratingWorldProgress(GWP_TOWN, n);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4261
diff changeset
  1056
1362
bceb3c57353d (svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents: 1335
diff changeset
  1057
	do {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4261
diff changeset
  1058
		IncreaseGeneratingWorldProgress(GWP_TOWN);
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
  1059
		// try 20 times to create a random-sized town for the first loop.
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
  1060
		if (CreateRandomTown(20, 0) != NULL) num++;
1362
bceb3c57353d (svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents: 1335
diff changeset
  1061
	} while (--n);
bceb3c57353d (svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents: 1335
diff changeset
  1062
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
  1063
	// give it a last try, but now more aggressive
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
  1064
	if (num == 0 && CreateRandomTown(10000, 0) == NULL) {
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4357
diff changeset
  1065
		if (GetTownArraySize() == 0) {
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4357
diff changeset
  1066
			/* XXX - can we handle that more gracefully? */
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4357
diff changeset
  1067
			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
  1068
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4357
diff changeset
  1069
			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
  1070
		}
1362
bceb3c57353d (svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
celestar
parents: 1335
diff changeset
  1071
	}
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
  1072
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
  1073
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1076
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
  1077
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
	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
  1079
	Slope slope;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
	static const byte _masks[8] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
		0xC,0x3,0x9,0x6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
		0x3,0xC,0x6,0x9,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
	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
  1087
	if (IsSteepSlope(slope)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
	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
  1090
	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
  1091
	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
  1092
	if (b)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
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
  1095
	return !CmdFailed(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
  1096
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
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
  1098
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
  1099
uint GetTownRadiusGroup(const Town* t, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
{
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
  1101
	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
  1102
	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
  1103
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
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
  1105
	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
  1106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
	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
  1108
	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
  1109
		if (dist < t->radius[i]) smallest = i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	return smallest;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1115
static bool CheckFree2x2Area(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1119
	static const TileIndexDiffC _tile_add[] = {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1120
		{0    , 0    },
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1121
		{0 - 0, 1 - 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1122
		{1 - 0, 0 - 1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1123
		{1 - 1, 1 - 0}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
  1126
	for (i = 0; i != 4; i++) {
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1127
		tile += ToTileIndexDiff(_tile_add[i]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1129
		if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
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
  1131
		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
  1132
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1138
static void DoBuildTownHouse(Town *t, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	uint bitmask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	int house;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1143
	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
  1144
	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
  1145
	uint oneof = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1146
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	// Above snow?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	slope = GetTileSlope(tile, &z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	// Get the town zone type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
		uint rad = GetTownRadiusGroup(t, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
		int land = _opt.landscape;
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
  1155
		if (land == LT_HILLY && z >= _opt.snow_line) land = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
		bitmask = (1 << rad) + (1 << (land + 12));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
	// bits 0-4 are used
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
	// bits 11-15 are used
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	// bits 5-10 are not used.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
		byte houses[lengthof(_housetype_flags)];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
		int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
		// Generate a list of all possible houses that can be built.
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
  1168
		for (i=0; i!=lengthof(_housetype_flags); i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
			if ((~_housetype_flags[i] & bitmask) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
				houses[num++] = (byte)i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
  1173
		for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
			house = houses[RandomRange(num)];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
			if (_cur_year < _housetype_years[house].min || _cur_year > _housetype_years[house].max)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
				continue;
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
			// Special houses that there can be only one of.
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
  1180
			switch (house) {
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
  1181
				case HOUSE_TEMP_CHURCH:
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
  1182
				case HOUSE_ARCT_CHURCH:
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
  1183
				case HOUSE_SNOW_CHURCH:
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
  1184
				case HOUSE_TROP_CHURCH:
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
  1185
				case HOUSE_TOY_CHURCH:
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1186
					SETBIT(oneof, TOWN_HAS_CHURCH);
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
  1187
					break;
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
  1188
				case HOUSE_STADIUM:
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
  1189
				case HOUSE_MODERN_STADIUM:
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1190
					SETBIT(oneof, 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
  1191
					break;
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
  1192
				default:
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
  1193
					oneof = 0;
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
  1194
					break;
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
  1195
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1197
			if (HASBITS(t->flags12 , oneof)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
			// Make sure there is no slope?
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1200
			if (_housetype_extra_flags[house] & 0x12 && slope != SLOPE_FLAT) continue;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1201
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1202
			if (_housetype_extra_flags[house] & 0x10) {
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1203
				if (CheckFree2x2Area(tile) ||
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1204
						CheckFree2x2Area(tile += TileDiffXY(-1,  0)) ||
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1205
						CheckFree2x2Area(tile += TileDiffXY( 0, -1)) ||
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1206
						CheckFree2x2Area(tile += TileDiffXY( 1,  0))) {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1207
					break;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1208
				}
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1209
				tile += TileDiffXY(0, 1);
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1210
			} else if (_housetype_extra_flags[house] & 4) {
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1211
				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
  1212
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1213
				if (CheckBuildHouseMode(tile + TileDiffXY(-1, 0), slope, 1)) {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1214
					tile += TileDiffXY(-1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
				}
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1217
			} else if (_housetype_extra_flags[house] & 8) {
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1218
				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
  1219
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1220
				if (CheckBuildHouseMode(tile + TileDiffXY(0, -1), slope, 3)) {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1221
					tile += TileDiffXY(0, -1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
				}
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1224
			} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
				break;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2891
diff changeset
  1226
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	t->num_houses++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
	// Special houses that there can be only one of.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
	t->flags12 |= oneof;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1234
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
	{
3382
be14efb0dfd7 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3379
diff changeset
  1236
		byte construction_counter = 0, construction_stage = 0, size_flags;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
		if (_generating_world) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
			uint32 r = Random();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1240
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1241
			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
  1242
			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
  1243
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1244
			if (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
  1245
				ChangePopulation(t, _housetype_population[house]);
be14efb0dfd7 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3379
diff changeset
  1246
			} else {
be14efb0dfd7 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3379
diff changeset
  1247
				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
  1248
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
		}
3382
be14efb0dfd7 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3379
diff changeset
  1250
		size_flags = GB(_housetype_extra_flags[house], 2, 3);
be14efb0dfd7 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3379
diff changeset
  1251
		MakeTownHouse(tile, t->index, construction_counter, construction_stage, size_flags, house);
0
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1255
static bool BuildTownHouse(Town *t, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
	int32 r;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1258
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
	// make sure it's possible
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
	if (!EnsureNoVehicle(tile)) return false;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1261
	if (IsSteepSlope(GetTileSlope(tile, NULL))) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
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
  1263
	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
  1264
	if (CmdFailed(r)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
	DoBuildTownHouse(t, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1271
static void DoClearTownHouseHelper(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
{
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
  1273
	assert(IsTileType(tile, MP_HOUSE));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
	DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
	DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1278
static void ClearTownHouse(Town *t, TileIndex tile)
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1279
{
3377
608cf1405409 (svn r4179) -Codechange: Add and make use of an accessor that obtains the building type
celestar
parents: 3359
diff changeset
  1280
	uint house = GetHouseType(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	uint eflags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
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
  1283
	assert(IsTileType(tile, MP_HOUSE));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
	// need to align the tile to point to the upper left corner of the house
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
	if (house >= 3) { // house id 0,1,2 MUST be single tile houses, or this code breaks.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
		if (_housetype_extra_flags[house-1] & 0x04) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
			house--;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1289
			tile += TileDiffXY(-1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
		} else if (_housetype_extra_flags[house-1] & 0x18) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
			house--;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1292
			tile += TileDiffXY(0, -1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
		} else if (_housetype_extra_flags[house-2] & 0x10) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
			house-=2;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1295
			tile += TileDiffXY(-1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
		} else if (_housetype_extra_flags[house-3] & 0x10) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
			house-=3;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1298
			tile += TileDiffXY(-1, -1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1301
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1302
	// Remove population from the town if the house is finished.
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1303
	if (GetHouseBuildingStage(tile) == TOWN_HOUSE_COMPLETED) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
		ChangePopulation(t, -_housetype_population[house]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
	t->num_houses--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
	// Clear flags for houses that only may exist once/town.
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
  1310
	switch (house) {
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
  1311
		case HOUSE_TEMP_CHURCH:
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
  1312
		case HOUSE_ARCT_CHURCH:
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
  1313
		case HOUSE_SNOW_CHURCH:
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
  1314
		case HOUSE_TROP_CHURCH:
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
  1315
		case HOUSE_TOY_CHURCH:
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1316
			CLRBIT(t->flags12, TOWN_HAS_CHURCH);
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
  1317
			break;
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
  1318
		case HOUSE_STADIUM:
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
  1319
		case HOUSE_MODERN_STADIUM:
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1320
			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
  1321
			break;
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
  1322
		default:
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
  1323
			break;
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
  1324
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1325
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
	// Do the actual clearing of tiles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
	eflags = _housetype_extra_flags[house];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
	DoClearTownHouseHelper(tile);
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1329
	if (eflags & 0x14) DoClearTownHouseHelper(tile + TileDiffXY(1, 0));
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1330
	if (eflags & 0x18) DoClearTownHouseHelper(tile + TileDiffXY(0, 1));
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1331
	if (eflags & 0x10) DoClearTownHouseHelper(tile + TileDiffXY(1, 1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1334
/** 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
  1335
 * @param tile unused
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1336
 * @param p1 town ID to rename
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1337
 * @param p2 unused
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1338
 */
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
  1339
int32 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
  1340
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
	StringID str;
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1342
	Town *t;
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1343
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
  1344
	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
  1345
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1346
	t = GetTown(p1);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1347
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
  1348
	str = AllocateNameUnique(_cmd_text, 4);
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1349
	if (str == 0) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
	if (flags & DC_EXEC) {
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1352
		DeleteName(t->townnametype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
		t->townnametype = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
		UpdateTownVirtCoord(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
		_town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
		UpdateAllStationVirtCoord();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
		DeleteName(str);
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
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
// Called from GUI
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
void DeleteTown(Town *t)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
	Industry *i;
1252
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1369
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
	// Delete town authority window
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
	//  and remove from list of sorted towns
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
	DeleteWindowById(WC_TOWN_VIEW, t->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
	_town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
	// Delete all industries belonging to the town
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1377
	FOR_ALL_INDUSTRIES(i) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1378
		if (i->town == t) DeleteIndustry(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
	// Go through all tiles and delete those belonging to the town
1252
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1382
	for (tile = 0; tile < MapSize(); ++tile) {
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1383
		switch (GetTileType(tile)) {
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1384
			case MP_HOUSE:
3319
16c0f06829a5 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents: 3310
diff changeset
  1385
				if (GetTownByTile(tile) == t)
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
  1386
					DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
1252
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1387
				break;
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1388
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1389
			case MP_STREET:
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1390
			case MP_TUNNELBRIDGE:
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  1391
				if (IsTileOwner(tile, OWNER_TOWN) &&
1252
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1392
						ClosestTownFromTile(tile, (uint)-1) == t)
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
  1393
					DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
1252
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1394
				break;
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1395
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1396
			default:
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1397
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
		}
1252
fa73bce0f2e0 (svn r1756) Cleanup: if cascade -> switch, uint -> TileIndex
tron
parents: 1245
diff changeset
  1399
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	t->xy = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
	DeleteName(t->townnametype);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
	MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
// Called from GUI
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
void ExpandTown(Town *t)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	int amount, n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	_generating_world = true;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1413
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
  1414
	/* 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
  1415
	amount = RandomRange(t->num_houses / 10) + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
	t->num_houses += amount;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	UpdateTownRadius(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 830
diff changeset
  1419
	n = amount * 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
	do GrowTown(t); while (--n);
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 -= amount;
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
	UpdateTownMaxPass(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
	_generating_world = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
const byte _town_action_costs[8] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
	2, 4, 9, 35, 48, 53, 117, 175
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1433
static void TownActionAdvertiseSmall(Town* t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
{
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1435
	ModifyStationRatingAround(t->xy, _current_player, 0x40, 10);
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
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1438
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
  1439
{
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1440
	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
  1441
}
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1442
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1443
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
  1444
{
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1445
	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
  1446
}
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1447
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1448
static void TownActionRoadRebuild(Town* t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
{
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
  1450
	const Player* p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
	t->road_build_months = 6;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1453
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 516
diff changeset
  1454
	SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1928
diff changeset
  1456
	p = GetPlayer(_current_player);
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 516
diff changeset
  1457
	SetDParam(1, p->name_1);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 516
diff changeset
  1458
	SetDParam(2, p->name_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1460
	AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
		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
  1462
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1464
static bool DoBuildStatueOfCompany(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
{
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
  1466
	PlayerID old;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
	int32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1469
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
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
  1471
	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
  1472
			!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
  1473
			!IsTileType(tile, MP_TREES)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
		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
  1475
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
	old = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
	_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
  1479
	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
  1480
	_current_player = old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
2646
c01dfbc7b7e3 (svn r3188) Use CmdFailed() to check, if a command failed, don't compare with CMD_ERROR
tron
parents: 2639
diff changeset
  1482
	if (CmdFailed(r)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
  1484
	MakeStatue(tile, _current_player);
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3282
diff changeset
  1485
	MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1490
static void TownActionBuildStatue(Town* t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
	// Layouted as an outward spiral
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1493
	static const TileIndexDiffC _statue_tiles[] = {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1494
		{-1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1495
		{ 0, 1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1496
		{ 1, 0}, { 1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1497
		{ 0,-1}, { 0,-1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1498
		{-1, 0}, {-1, 0}, {-1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1499
		{ 0, 1}, { 0, 1}, { 0, 1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1500
		{ 1, 0}, { 1, 0}, { 1, 0}, { 1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1501
		{ 0,-1}, { 0,-1}, { 0,-1}, { 0,-1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1502
		{-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1503
		{ 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1504
		{ 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1505
		{ 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1506
		{-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1507
		{ 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1508
		{ 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1509
		{ 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1510
		{-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1511
		{ 0, 0}
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1512
	};
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1513
	TileIndex tile = t->xy;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1514
	const TileIndexDiffC *p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
	SETBIT(t->statues, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1518
	for (p = _statue_tiles; p != endof(_statue_tiles); ++p) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
  1519
		if (DoBuildStatueOfCompany(tile)) return;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1520
		tile = TILE_ADD(tile, ToTileIndexDiff(*p));
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1521
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1524
static void TownActionFundBuildings(Town* t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
{
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1526
	// Build next tick
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
	t->grow_counter = 1;
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1528
	// If we were not already growing
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1529
	SETBIT(t->flags12, TOWN_IS_FUNDED);
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1530
	// And grow for 3 months
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
	t->fund_buildings_months = 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1534
static void TownActionBuyRights(Town* t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
{
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 39
diff changeset
  1536
	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
  1537
	t->exclusivity = _current_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
	ModifyStationRatingAround(t->xy, _current_player, 130, 17);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1542
static void TownActionBribe(Town* t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
	if (!RandomRange(15)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
		Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
		// set as unwanted for 6 months
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
		t->unwanted[_current_player] = 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
		// set all close by station ratings to 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
			if (st->town == t && st->owner == _current_player) {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1553
				uint i;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1554
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1555
				for (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
  1556
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
		// only show errormessage to the executing player. All errors are handled command.c
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
		// 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
  1561
		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
  1562
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
		/*	decrease by a lot!
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
		 *	ChangeTownRating is only for stuff in demolishing. Bribe failure should
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
		 *	be independent of any cheat settings
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
		 */
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1567
		if (t->ratings[_current_player] > RATING_BRIBE_DOWN_TO) {
1005
f48b2bdd84fc (svn r1504) enummed town ratings (Jango)
celestar
parents: 926
diff changeset
  1568
			t->ratings[_current_player] = RATING_BRIBE_DOWN_TO;
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1569
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
	} else {
1005
f48b2bdd84fc (svn r1504) enummed town ratings (Jango)
celestar
parents: 926
diff changeset
  1571
		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
  1572
	}
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
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1575
typedef void TownActionProc(Town* t);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
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
  1577
	TownActionAdvertiseSmall,
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1578
	TownActionAdvertiseMedium,
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3674
diff changeset
  1579
	TownActionAdvertiseLarge,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
	TownActionRoadRebuild,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
	TownActionBuildStatue,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
	TownActionFundBuildings,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
	TownActionBuyRights,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
	TownActionBribe
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1587
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
  1588
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1589
/** Do a town action.
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1590
 * 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
  1591
 * 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
  1592
 * @param tile unused
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1593
 * @param p1 town to do the action at
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1594
 * @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
  1595
 */
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
  1596
int32 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
  1597
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
	int32 cost;
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1599
	Town *t;
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1600
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4346
diff changeset
  1601
	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
  1602
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1603
	t = GetTown(p1);
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1604
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1638
diff changeset
  1605
	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
  1606
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
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
	cost = (_price.build_industry >> 8) * _town_action_costs[p2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
	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
  1612
		_town_action_proc[p2](t);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
		InvalidateWindow(WC_TOWN_AUTHORITY, p1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1614
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1616
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
static void UpdateTownGrowRate(Town *t)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
	int n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
	byte m;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
	Player *p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
	// Reset player ratings if they're low
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
	FOR_ALL_PLAYERS(p) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
		if (p->is_active && t->ratings[p->index] <= 200) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
			t->ratings[p->index] += 5;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
	n = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
	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
  1635
		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
  1636
			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
  1637
				n++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
				if (st->owner < MAX_PLAYERS && t->ratings[st->owner] <= 1000-12)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
					t->ratings[st->owner] += 12;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
				if (st->owner < MAX_PLAYERS && t->ratings[st->owner] >= -1000+15)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
					t->ratings[st->owner] -= 15;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1647
	CLRBIT(t->flags12, TOWN_IS_FUNDED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
	if (t->fund_buildings_months != 0) {
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
  1650
		static const byte _grow_count_values[6] = {
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
  1651
			60, 60, 60, 50, 40, 30
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
  1652
		};
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
  1653
		m = _grow_count_values[min(n, 5)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
		t->fund_buildings_months--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
	} else if (n == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
		m = 160;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
		if (!CHANCE16(1, 12))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1659
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
		static const byte _grow_count_values[5] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
			210, 150, 110, 80, 50
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
		};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1663
		m = _grow_count_values[min(n, 5) - 1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
	if (_opt.landscape == LT_HILLY) {
1041
94db182c3614 (svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents: 1035
diff changeset
  1667
 		if (TilePixelHeight(t->xy) >= _opt.snow_line && t->act_food == 0 && t->population > 90)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1668
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
	} else if (_opt.landscape == LT_DESERT) {
3379
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3377
diff changeset
  1670
 		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
  1671
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
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
  1674
  	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
  1675
	if (m <= t->grow_counter)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
		t->grow_counter = m;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
3432
650dd1972479 (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
  1678
	SETBIT(t->flags12, TOWN_IS_FUNDED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
static void UpdateTownAmounts(Town *t)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
	// Using +1 here to prevent overflow and division by zero
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
	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
  1685
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
	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
  1687
	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
  1688
	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
  1689
	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
  1690
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
	// Using +1 here to prevent overflow and division by zero
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
	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
  1693
	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
  1694
	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
  1695
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
	InvalidateWindow(WC_TOWN_VIEW, t->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
static void UpdateTownUnwanted(Town *t)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
{
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
  1701
	const Player* p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
	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
  1704
		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
  1705
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1962
diff changeset
  1708
bool CheckIfAuthorityAllows(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
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
  1712
	if (_current_player >= MAX_PLAYERS) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
	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
  1715
	if (t == NULL) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
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
  1717
	if (t->ratings[_current_player] > -200) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
	_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
  1720
	SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
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
  1726
Town* CalcClosestTownFromTile(TileIndex tile, uint threshold)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
	uint dist, best = threshold;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
	Town *best_town = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1731
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
	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
  1733
		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
  1734
		if (dist < best) {
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1735
			best = dist;
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1736
			best_town = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
	return best_town;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
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
  1743
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
  1744
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
  1745
{
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
  1746
	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
  1747
				IsTileType(tile, MP_STREET) &&
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
  1748
				(IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN
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
  1749
			)) {
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
  1750
		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
  1751
	} 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
  1752
		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
  1753
	}
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
  1754
}
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
  1755
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
  1756
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
void ChangeTownRating(Town *t, int add, int max)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
	int rating;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
	//	if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
  1762
	if (t == NULL ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
  1763
			_current_player >= MAX_PLAYERS ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
  1764
			(_cheats.magic_bulldozer.value && add < 0)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
		return;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2637
diff changeset
  1766
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1767
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
	SETBIT(t->have_ratings, _current_player);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1769
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
	rating = t->ratings[_current_player];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1771
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
	if (add < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
		if (rating > max) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
			rating += add;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
			if (rating < max) rating = max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1778
		if (rating < max) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1779
			rating += add;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1780
			if (rating > max) rating = max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
	t->ratings[_current_player] = rating;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1786
/*	penalty for removing town-owned stuff */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1787
static const int _default_rating_settings [3][3] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1788
	// ROAD_REMOVE, TUNNELBRIDGE_REMOVE, INDUSTRY_REMOVE
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
  1789
	{  0, 128, 384}, // Permissive
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
  1790
	{ 48, 192, 480}, // Neutral
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
  1791
	{ 96, 384, 768}, // Hostile
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1792
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
2958
ac0a9673b522 (svn r3520) Remove unused parameters from some functions
tron
parents: 2952
diff changeset
  1794
bool CheckforTownRating(uint32 flags, Town *t, byte type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1796
	int modemod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
	//	if magic_bulldozer cheat is active, town doesn't restrict your destructive actions
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
	if (t == NULL || _current_player >= MAX_PLAYERS || _cheats.magic_bulldozer.value)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
	/*	check if you're allowed to remove the street/bridge/tunnel/industry
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1803
	 *	owned by a town	no removal if rating is lower than ... depends now on
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
	 *	difficulty setting. Minimum town rating selected by difficulty level
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
	 */
1500
a66721629bc0 (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1451
diff changeset
  1806
	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
  1807
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
	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
  1809
		SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
		_error_message = STR_2009_LOCAL_AUTHORITY_REFUSES;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1812
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
	return true;
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
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
  1817
void TownsMonthlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1821
	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
  1822
		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
  1823
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 39
diff changeset
  1824
		if (t->exclusive_counter != 0)
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
  1825
			if (--t->exclusive_counter == 0) t->exclusivity = (byte)-1;
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 39
diff changeset
  1826
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
		UpdateTownGrowRate(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1828
		UpdateTownAmounts(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1829
		UpdateTownUnwanted(t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
  1833
void InitializeTowns(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
	Subsidy *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1837
	/* Clean the town pool and create 1 block in it */
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1838
	CleanPool(&_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
  1839
	AddBlockToPool(&_town_pool);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
	memset(_subsidies, 0, sizeof(_subsidies));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1842
	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
  1843
		s->cargo_type = CT_INVALID;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
	_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
  1846
	_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
  1847
	_total_towns = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
	_town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
}
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
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
  1852
	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
  1853
	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
  1854
	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
  1855
	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
  1856
	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
  1857
	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
  1858
	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
  1859
	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
  1860
	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
  1861
	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
  1862
	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
  1863
	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
  1864
	GetSlopeTileh_Town,      /* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
// 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
  1869
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
  1870
	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
  1871
	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
  1872
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
  1873
	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
  1874
	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
  1875
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
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
  1877
	    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
  1878
	    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
  1879
	    SLE_VAR(Town, townnameparts,         SLE_UINT32),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
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
  1881
	    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
  1882
	    SLE_VAR(Town, statues,               SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
	// 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
  1885
	SLE_CONDNULL(1, 0, 1),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
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
  1887
	    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
  1888
	    SLE_ARR(Town, ratings,               SLE_INT16, 8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
	// 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
  1890
	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
  1891
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
  1892
	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
  1893
	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
  1894
	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
  1895
	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
  1896
	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
  1897
	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
  1898
	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
  1899
	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
  1900
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
  1901
	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
  1902
	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
  1903
	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
  1904
	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
  1905
	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
  1906
	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
  1907
	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
  1908
	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
  1909
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
  1910
	    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
  1911
	    SLE_VAR(Town, pct_mail_transported,  SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
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
  1913
	    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
  1914
	    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
  1915
	    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
  1916
	    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
  1917
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
  1918
	    SLE_VAR(Town, time_until_rebuild,    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
  1919
	    SLE_VAR(Town, grow_counter,          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
  1920
	    SLE_VAR(Town, growth_rate,           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
  1921
	    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
  1922
	    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
  1923
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
  1924
	    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
  1925
	    SLE_VAR(Town, exclusive_counter,     SLE_UINT8),
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 39
diff changeset
  1926
	// 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
  1927
	SLE_CONDNULL(30, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
	SLE_END()
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
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
  1932
static void Save_TOWN(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1936
	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
  1937
		SlSetArrayIndex(t->index);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1938
		SlObject(t, _town_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
  1942
static void Load_TOWN(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
	int index;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1945
1261
914ecc20a2df (svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents: 1260
diff changeset
  1946
	_total_towns = 0;
914ecc20a2df (svn r1765) -Fix: on loading, the total amount of towns wasn't reset to zero
truelight
parents: 1260
diff changeset
  1947
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1948
	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
  1949
		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
  1950
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1951
		if (!AddBlockIfNeeded(&_town_pool, index))
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1952
			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
  1953
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1954
		t = GetTown(index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1955
		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
  1956
4357
aaba385fa723 (svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents: 4355
diff changeset
  1957
		if ((uint)index >= _total_towns) _total_towns = index + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1958
	}
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1959
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1960
	/* 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
  1961
	 *  the size of the TownPool */
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4352
diff changeset
  1962
	if (_cur_town_ctr >= GetTownArraySize())
1260
632f63689178 (svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents: 1252
diff changeset
  1963
		_cur_town_ctr = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1965
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1080
diff changeset
  1966
void AfterLoadTown(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1967
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1968
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
	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
  1970
		UpdateTownRadius(t);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1971
		UpdateTownVirtCoord(t);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1972
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
	_town_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1977
const ChunkHandler _town_chunk_handlers[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
	{ 'CITY', Save_TOWN, Load_TOWN, CH_ARRAY | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
};