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