src/station_cmd.cpp
author richk
Tue, 17 Jun 2008 13:22:13 +0000
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
child 10995 311b38c7f9a7
permissions -rw-r--r--
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
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
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
     3
/** @file station_cmd.cpp Handling of station tiles. */
2213
cb78ae22fe58 (svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents: 2187
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"
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6402
diff changeset
     7
#include "aircraft.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
     8
#include "bridge_map.h"
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
     9
#include "cmd_helper.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1295
diff changeset
    10
#include "debug.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    11
#include "tile_cmd.h"
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
    12
#include "landscape.h"
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
    13
#include "station_map.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    14
#include "viewport_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    15
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "town.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    17
#include "news_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "airport.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    20
#include "sprite.h"
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2671
diff changeset
    21
#include "train.h"
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
    22
#include "roadveh.h"
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
    23
#include "water_map.h"
3515
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
    24
#include "industry_map.h"
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
    25
#include "newgrf_callbacks.h"
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
    26
#include "newgrf_station.h"
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
    27
#include "yapf/yapf.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    28
#include "road_type.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    29
#include "road_internal.h" /* For drawing catenary/checking road removal */
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6413
diff changeset
    30
#include "cargotype.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    31
#include "variables.h"
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
    32
#include "autoslope.h"
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
    33
#include "newgrf_fsmports.h"
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    34
#include "transparency.h"
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
    35
#include "water.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    36
#include "station_gui.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    37
#include "strings_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    38
#include "functions.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    39
#include "window_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    40
#include "date_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    41
#include "vehicle_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    42
#include "string_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    43
#include "signal_func.h"
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    44
#include "oldpool_func.h"
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
    45
#include "animated_tile_func.h"
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
    46
#include "elrail_func.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    47
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    48
#include "table/sprites.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    49
#include "table/strings.h"
5917
e0d30aba24a3 (svn r8126) -Fix (r8125): missing #include fixes compilation error on g++ (still some warnings, working on it)
KUDr
parents: 5916
diff changeset
    50
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    51
DEFINE_OLD_POOL_GENERIC(Station, Station)
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    52
DEFINE_OLD_POOL_GENERIC(RoadStop, RoadStop)
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    53
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    54
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    55
/**
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    56
 * Check whether the given tile is a hangar.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    57
 * @param t the tile to of whether it is a hangar.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    58
 * @pre IsTileType(t, MP_STATION)
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    59
 * @return true if and only if the tile is a hangar.
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    60
 */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    61
bool IsHangar(TileIndex t)
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    62
{
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    63
	assert(IsTileType(t, MP_STATION));
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    64
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    65
	Station *st = GetStationByTile(t);
6863
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    66
	FSMDepots *hangar_list;
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    67
	byte num_depots;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    68
	if (IsCustomFSMportsSpecIndex(t)) {
6853
b3b8bb6c0a48 (svn r10956) [NewGRF_ports] -Codechange: start refactoring the airport specific code to be more generic so it can be used for non-aircraft ports too.
rubidium
parents: 6837
diff changeset
    69
		hangar_list = st->fsmportsspeclist[1].spec->portFSM->depots;
6856
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
    70
		num_depots = st->fsmportsspeclist[1].spec->portFSM->num_depots;
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    71
	} else {
6853
b3b8bb6c0a48 (svn r10956) [NewGRF_ports] -Codechange: start refactoring the airport specific code to be more generic so it can be used for non-aircraft ports too.
rubidium
parents: 6837
diff changeset
    72
		hangar_list = st->Airport()->depots;
6856
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
    73
		num_depots = st->Airport()->num_depots;
5969
8aa5b3220178 (svn r8212) -Fix
tron
parents: 5967
diff changeset
    74
	}
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    75
	for (uint i = 0; i < num_depots; i++) {
6863
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    76
		TileIndexDiffC depot = RotateFSMPosition(hangar_list[i].tile_pos,
6746
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
    77
												 st->fsmportsspeclist[1].spec->size_x[st->FSMport_layout_set],
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
    78
												 st->fsmportsspeclist[1].spec->size_y[st->FSMport_layout_set],
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
    79
												 st->FSMport_orientation);
837a9ca5a2f0 (svn r10784) [NewGRF_ports] -Feature: Added rotation of FSMport movement.
richk
parents: 6745
diff changeset
    80
		if (st->airport_tile + ToTileIndexDiff(depot) == t) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    81
			return true;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    82
		}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    83
	}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
    84
	return false;
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    85
}
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    86
6863
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    87
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    88
FSMDepots GetKeyDepotByTile(TileIndex t)
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    89
{
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    90
	Station *st = GetStationByTile(t);
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    91
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    92
	FSMDepots *hangar_list;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    93
	byte num_depots;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    94
	uint i;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    95
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    96
	if (IsCustomFSMportsSpecIndex(t)) {
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    97
		hangar_list = st->fsmportsspeclist[1].spec->portFSM->depots;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    98
		num_depots = st->fsmportsspeclist[1].spec->portFSM->num_depots;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
    99
	} else {
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   100
		hangar_list = st->Airport()->depots;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   101
		num_depots = st->Airport()->num_depots;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   102
	}
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   103
	for (i = 0; i < num_depots; i++) {
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   104
		TileIndexDiffC depot = RotateFSMPosition(hangar_list[i].tile_pos,
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   105
												 st->fsmportsspeclist[1].spec->size_x[st->FSMport_layout_set],
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   106
												 st->fsmportsspeclist[1].spec->size_y[st->FSMport_layout_set],
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   107
												 st->FSMport_orientation);
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   108
		if (st->airport_tile + ToTileIndexDiff(depot) == t) {
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   109
			break;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   110
		}
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   111
	}
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   112
	return hangar_list[i];
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   113
}
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   114
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   115
/**
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   116
 * goes from a tile location, looks up the depot, finds the location of the key part of the depot in the state machine
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   117
 * returns the tile location of that key part
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   118
 * @param t: the tile to start from
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   119
 * @pre IsHangar(t)
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   120
 * @return tile of key part of hangar
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   121
 */
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   122
TileIndex GetKeyDepotTile(TileIndex t)
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   123
{
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   124
	Station *st = GetStationByTile(t);
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   125
	const FSMPortMovingData *md = st->fsmportsspeclist[1].spec->portFSM->MovingData(GetKeyDepotByTile(t).FSMposition);
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   126
	TileIndexDiffC keydepot;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   127
	keydepot.x = md->x / TILE_SIZE;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   128
	keydepot.y = md->y / TILE_SIZE;
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   129
	keydepot = RotateFSMPosition(keydepot,
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   130
												 st->fsmportsspeclist[1].spec->size_x[st->FSMport_layout_set],
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   131
												 st->fsmportsspeclist[1].spec->size_y[st->FSMport_layout_set],
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   132
												 st->FSMport_orientation);
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   133
	return st->airport_tile + ToTileIndexDiff(keydepot);
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   134
}
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
   135
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   136
RoadStop *GetRoadStopByTile(TileIndex tile, RoadStopType type)
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   137
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   138
	const Station *st = GetStationByTile(tile);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   139
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   140
	for (RoadStop *rs = st->GetPrimaryRoadStop(type);; rs = rs->next) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   141
		if (rs->xy == tile) return rs;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   142
		assert(rs->next != NULL);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   143
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   144
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   145
6164
a4458b13cca9 (svn r8539) -Fix
tron
parents: 6157
diff changeset
   146
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   147
static uint GetNumRoadStopsInStation(const Station *st, RoadStopType type)
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   148
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   149
	uint num = 0;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   150
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   151
	assert(st != NULL);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   152
	for (const RoadStop *rs = st->GetPrimaryRoadStop(type); rs != NULL; rs = rs->next) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   153
		num++;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   154
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   155
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   156
	return num;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   157
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   158
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   159
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   160
/** Calculate the radius of the station. Basicly it is the biggest
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   161
 *  radius that is available within the station
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   162
 * @param st Station to query
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   163
 * @return the so calculated radius
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   164
 */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   165
static uint FindCatchmentRadius(const Station *st)
703
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   166
{
6367
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   167
	uint ret = CA_NONE;
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   168
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   169
	if (st->bus_stops   != NULL) ret = max<uint>(ret, CA_BUS);
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   170
	if (st->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK);
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   171
	if (st->train_tile  != 0)    ret = max<uint>(ret, CA_TRAIN);
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   172
	if (st->dock_tile   != 0)    ret = max<uint>(ret, CA_DOCK);
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   173
	if (st->airport_tile)        ret = max<uint>(ret, st->Airport()->catchment);
703
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   174
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   175
	return ret;
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   176
}
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   177
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
#define CHECK_STATIONS_ERR ((Station*)-1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   180
static Station *GetStationAround(TileIndex tile, int w, int h, StationID closest_station)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   182
	/* check around to see if there's any stations there */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   183
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
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: 1032
diff changeset
   184
		if (IsTileType(tile_cur, MP_STATION)) {
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
   185
			StationID t = GetStationIndex(tile_cur);
28
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   186
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
   187
			if (closest_station == INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
				closest_station = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
			} else if (closest_station != t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
				_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
				return CHECK_STATIONS_ERR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
		}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   194
	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
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
   195
	return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   198
/**
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   199
 * Function to check whether the given tile matches some criterion.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   200
 * @param tile the tile to check
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   201
 * @return true if it matches, false otherwise
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   202
 */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   203
typedef bool (*CMSAMatcher)(TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
3515
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   205
/**
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   206
 * Counts the numbers of tiles matching a specific type in the area around
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   207
 * @param tile the center tile of the 'count area'
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   208
 * @param type the type of tile searched for
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   209
 * @param industry when type == MP_INDUSTRY, the type of the industry,
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   210
 *                 in all other cases this parameter is ignored
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6524
diff changeset
   211
 * @return the result the noumber of matching tiles around
3515
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   212
 */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   213
static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   214
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   217
	for (int dx = -3; dx <= 3; dx++) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   218
		for (int dy = -3; dy <= 3; dy++) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   219
			if (cmp(TILE_MASK(tile + TileDiffXY(dx, dy)))) num++;
3515
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   220
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
	return num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   226
/**
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   227
 * Check whether the tile is a mine.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   228
 * @param tile the tile to investigate.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   229
 * @return true if and only if the tile is a mine
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   230
 */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   231
static bool CMSAMine(TileIndex tile)
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   232
{
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   233
	/* No industry */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   234
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   235
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   236
	const Industry *ind = GetIndustryByTile(tile);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   237
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   238
	/* No extractive industry */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   239
	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   240
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   241
	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   242
		/* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   243
		if (ind->produced_cargo[i] != CT_INVALID && (GetCargo(ind->produced_cargo[i])->classes & CC_LIQUID) == 0) return true;
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   244
	}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   245
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   246
	return false;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   247
}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   248
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   249
/**
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   250
 * Check whether the tile is water.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   251
 * @param tile the tile to investigate.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   252
 * @return true if and only if the tile is a mine
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   253
 */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   254
static bool CMSAWater(TileIndex tile)
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   255
{
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   256
	return IsTileType(tile, MP_WATER) && IsWater(tile);
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   257
}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   258
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   259
/**
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   260
 * Check whether the tile is a tree.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   261
 * @param tile the tile to investigate.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   262
 * @return true if and only if the tile is a mine
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   263
 */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   264
static bool CMSATree(TileIndex tile)
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   265
{
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   266
	return IsTileType(tile, MP_TREES);
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   267
}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   268
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   269
/**
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   270
 * Check whether the tile is a forest.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   271
 * @param tile the tile to investigate.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   272
 * @return true if and only if the tile is a mine
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   273
 */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   274
static bool CMSAForest(TileIndex tile)
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   275
{
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   276
	/* No industry */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   277
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   278
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   279
	const Industry *ind = GetIndustryByTile(tile);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   280
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   281
	/* No extractive industry */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   282
	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   283
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   284
	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   285
		/* The industry produces wood. */
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   286
		if (ind->produced_cargo[i] != CT_INVALID && GetCargo(ind->produced_cargo[i])->label == 'WOOD') return true;
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   287
	}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   288
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   289
	return false;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   290
}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   291
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
#define M(x) ((x) - STR_SV_STNAME)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   294
enum StationNaming {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   295
	STATIONNAMING_RAIL = 0,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   296
	STATIONNAMING_ROAD = 0,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   297
	STATIONNAMING_AIRPORT,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   298
	STATIONNAMING_OILRIG,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   299
	STATIONNAMING_DOCK,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   300
	STATIONNAMING_BUOY,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   301
	STATIONNAMING_HELIPORT,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   302
};
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   303
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   304
static StringID GenerateStationName(Station *st, TileIndex tile, int flag)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	static const uint32 _gen_station_name_bits[] = {
1454
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   307
		0,                                      /* 0 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   308
		1 << M(STR_SV_STNAME_AIRPORT),          /* 1 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   309
		1 << M(STR_SV_STNAME_OILFIELD),         /* 2 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   310
		1 << M(STR_SV_STNAME_DOCKS),            /* 3 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   311
		0x1FF << M(STR_SV_STNAME_BUOY_1),       /* 4 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   312
		1 << M(STR_SV_STNAME_HELIPORT),         /* 5 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   315
	const Town *t = st->town;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   316
	uint32 free_names = UINT32_MAX;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   318
	const Station *s;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   319
	FOR_ALL_STATIONS(s) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   320
		if (s != st && s->town == t) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   321
			uint str = M(s->string_id);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   322
			if (str <= 0x20) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   323
				if (str == M(STR_SV_STNAME_FOREST)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   324
					str = M(STR_SV_STNAME_WOODS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
				}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   326
				ClrBit(free_names, str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   328
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   330
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
	/* check default names */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   332
	uint32 tmp = free_names & _gen_station_name_bits[flag];
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   333
	if (tmp != 0) return STR_SV_STNAME + FindFirstBit(tmp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	/* check mine? */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   336
	if (HasBit(free_names, M(STR_SV_STNAME_MINES))) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   337
		if (CountMapSquareAround(tile, CMSAMine) >= 2) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   338
			return STR_SV_STNAME_MINES;
1454
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   339
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	/* check close enough to town to get central as name? */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   343
	if (DistanceMax(tile, t->xy) < 8) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   344
		if (HasBit(free_names, M(STR_SV_STNAME))) return STR_SV_STNAME;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   345
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   346
		if (HasBit(free_names, M(STR_SV_STNAME_CENTRAL))) return STR_SV_STNAME_CENTRAL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	/* Check lakeside */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   350
	if (HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   351
			DistanceFromEdge(tile) < 20 &&
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   352
			CountMapSquareAround(tile, CMSAWater) >= 5) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   353
		return STR_SV_STNAME_LAKESIDE;
1454
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   354
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
	/* Check woods */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   357
	if (HasBit(free_names, M(STR_SV_STNAME_WOODS)) && (
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   358
				CountMapSquareAround(tile, CMSATree) >= 8 ||
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
   359
				CountMapSquareAround(tile, CMSAForest) >= 2)
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   360
			) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   361
		return _settings_game.game_creation.landscape == LT_TROPIC ? STR_SV_STNAME_FOREST : STR_SV_STNAME_WOODS;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	/* check elevation compared to town */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   365
	uint z = GetTileZ(tile);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   366
	uint z2 = GetTileZ(t->xy);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   367
	if (z < z2) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   368
		if (HasBit(free_names, M(STR_SV_STNAME_VALLEY))) return STR_SV_STNAME_VALLEY;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   369
	} else if (z > z2) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   370
		if (HasBit(free_names, M(STR_SV_STNAME_HEIGHTS))) return STR_SV_STNAME_HEIGHTS;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
	/* check direction compared to town */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   374
	static const int8 _direction_and_table[] = {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   375
		~( (1 << M(STR_SV_STNAME_WEST))  | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   376
		~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   377
		~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   378
		~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) ),
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   379
	};
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   380
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   381
	free_names &= _direction_and_table[
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   382
		(TileX(tile) < TileX(t->xy)) +
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   383
		(TileY(tile) < TileY(t->xy)) * 2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   385
	tmp = free_names & ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 26) | (1 << 27) | (1 << 28) | (1 << 29) | (1 << 30));
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   386
	return (tmp == 0) ? STR_SV_STNAME_FALLBACK : (STR_SV_STNAME + FindFirstBit(tmp));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
#undef M
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   390
static Station *GetClosestStationFromTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
{
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
   392
	uint threshold = 8;
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   393
	Station *best_station = NULL;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   394
	Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
	FOR_ALL_STATIONS(st) {
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
   397
		if (st->facilities == 0 && st->owner == _current_player) {
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   398
			uint cur_dist = DistanceManhattan(tile, st->xy);
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   399
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   400
			if (cur_dist < threshold) {
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   401
				threshold = cur_dist;
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   402
				best_station = st;
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   403
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
	return best_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   410
/** Update the virtual coords needed to draw the station sign.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   411
 * @param st Station to update for.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   412
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
static void UpdateStationVirtCoord(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
{
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
   415
	Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   416
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	pt.y -= 32;
6854
92ca286e9466 (svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents: 6853
diff changeset
   418
	if (st->facilities & FACIL_AIRPORT && st->Airport() == AirportFTAClass::oil_rig) pt.y -= 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   420
	SetDParam(0, st->index);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   421
	SetDParam(1, st->facilities);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_305C_0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   425
/** Update the virtual coords needed to draw the station sign for all stations. */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   426
void UpdateAllStationVirtCoord()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   428
	Station *st;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   429
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
	FOR_ALL_STATIONS(st) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   431
		UpdateStationVirtCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   435
/**
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   436
 * Update the station virt coords while making the modified parts dirty.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   437
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   438
 * This function updates the virt coords and mark the modified parts as dirty
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   439
 *
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   440
 * @param st The station to update the virt coords
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   441
 * @ingroup dirty
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
   442
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
static void UpdateStationVirtCoordDirty(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
{
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   445
	st->MarkDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	UpdateStationVirtCoord(st);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   447
	st->MarkDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   450
/** Get a mask of the cargo types that the station accepts.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   451
 * @param st Station to query
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   452
 * @return the expected mask
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   453
 */
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   454
static uint GetAcceptanceMask(const Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
	uint mask = 0;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   457
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
   458
	for (CargoID i = 0; i < NUM_CARGO; i++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   459
		if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) mask |= 1 << i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	return mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   464
/** Items contains the two cargo names that are to be accepted or rejected.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   465
 * msg is the string id of the message to display.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   466
 */
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   467
static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *cargo, StringID msg)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
{
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   469
	for (uint i = 0; i < num_items; i++) {
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6413
diff changeset
   470
		SetDParam(i + 1, GetCargo(cargo[i])->name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
	}
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   472
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   473
	SetDParam(0, st->index);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   474
	AddNewsItem(msg, NS_ACCEPTANCE, st->xy, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   477
/**
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   478
 * Get a list of the cargo types being produced around the tile (in a rectangle).
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   479
 * @param produced: Destination array of produced cargo
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   480
 * @param tile: Center of the search area
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   481
 * @param w: Width of the center
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   482
 * @param h: Height of the center
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   483
 * @param rad: Radius of the search area
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   484
 */
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   485
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile,
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   486
	int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
{
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   488
	memset(produced, 0, sizeof(AcceptedCargo));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   490
	int x = TileX(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   491
	int y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   493
	/* expand the region by rad tiles on each side
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   494
	 * while making sure that we remain inside the board. */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   495
	int x2 = min(x + w + rad, MapSizeX());
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   496
	int x1 = max(x - rad, 0);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   497
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   498
	int y2 = min(y + h + rad, MapSizeY());
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   499
	int y1 = max(y - rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   506
	for (int yc = y1; yc != y2; yc++) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   507
		for (int xc = x1; xc != x2; xc++) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   508
			TileIndex tile = TileXY(xc, yc);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   509
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   510
			if (!IsTileType(tile, MP_STATION)) {
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   511
				GetProducedCargoProc *gpc = _tile_type_procs[GetTileType(tile)]->get_produced_cargo_proc;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
				if (gpc != NULL) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   513
					CargoID cargos[256]; // Required for CBID_HOUSE_PRODUCE_CARGO.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   514
					memset(cargos, CT_INVALID, 256);
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   515
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
					gpc(tile, cargos);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   517
					for (uint i = 0; i < lengthof(cargos); ++i) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
   518
						if (cargos[i] != CT_INVALID) produced[cargos[i]]++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
			}
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   522
		}
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   523
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   526
/**
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   527
 * Get a list of the cargo types that are accepted around the tile.
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   528
 * @param accepts: Destination array of accepted cargo
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   529
 * @param tile: Center of the search area
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   530
 * @param w: Width of the center
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   531
 * @param h: Height of the center
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   532
 * @param rad: Radius of the rectangular search area
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   533
 */
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   534
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile,
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   535
	int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
{
473
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   537
	memset(accepts, 0, sizeof(AcceptedCargo));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   539
	int x = TileX(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   540
	int y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   542
	/* expand the region by rad tiles on each side
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   543
	 * while making sure that we remain inside the board. */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   544
	int x2 = min(x + w + rad, MapSizeX());
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   545
	int y2 = min(y + h + rad, MapSizeY());
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   546
	int x1 = max(x - rad, 0);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   547
	int y1 = max(y - rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   554
	for (int yc = y1; yc != y2; yc++) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   555
		for (int xc = x1; xc != x2; xc++) {
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   556
			TileIndex tile = TileXY(xc, yc);
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   557
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: 1032
diff changeset
   558
			if (!IsTileType(tile, MP_STATION)) {
473
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   559
				AcceptedCargo ac;
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   560
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   561
				GetAcceptedCargo(tile, ac);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   562
				for (uint i = 0; i < lengthof(ac); ++i) accepts[i] += ac[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
			}
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   564
		}
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   565
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   568
static inline void MergePoint(Rect *rect, TileIndex tile)
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   569
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   570
	int x = TileX(tile);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   571
	int y = TileY(tile);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   572
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   573
	if (rect->left   > x) rect->left   = x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   574
	if (rect->bottom > y) rect->bottom = y;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   575
	if (rect->right  < x) rect->right  = x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   576
	if (rect->top    < y) rect->top    = y;
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   577
}
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   578
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   579
/** Update the acceptance for a station.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   580
 * @param st Station to update
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   581
 * @param show_msg controls whether to display a message that acceptance was changed.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   582
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
static void UpdateStationAcceptance(Station *st, bool show_msg)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   585
	/* Don't update acceptance for a buoy */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   586
	if (st->IsBuoy()) return;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   587
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   588
	Rect rect;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   589
	rect.left   = MapSizeX();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   590
	rect.bottom = MapSizeY();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   591
	rect.right  = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   592
	rect.top    = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
	/* old accepted goods types */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   595
	uint old_acc = GetAcceptanceMask(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   597
	/* Put all the tiles that span an area in the table. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	if (st->train_tile != 0) {
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   599
		MergePoint(&rect, st->train_tile);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   600
		MergePoint(&rect, st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   602
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
	if (st->airport_tile != 0) {
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   604
		const AirportFTAClass *afc = st->Airport();
3876
c0d426e78b56 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
   605
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   606
		MergePoint(&rect, st->airport_tile);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   607
		MergePoint(&rect, st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1));
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   608
	}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   609
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   610
	if (st->dock_tile != 0) MergePoint(&rect, st->dock_tile);
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   611
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   612
	for (const RoadStop *rs = st->bus_stops; rs != NULL; rs = rs->next) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   613
		MergePoint(&rect, rs->xy);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   614
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   616
	for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   617
		MergePoint(&rect, rs->xy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   619
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   620
	/* And retrieve the acceptance. */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   621
	AcceptedCargo accepts;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   622
	if (rect.right >= rect.left) {
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   623
		GetAcceptanceAroundTiles(
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   624
			accepts,
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   625
			TileXY(rect.left, rect.bottom),
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   626
			rect.right - rect.left   + 1,
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
   627
			rect.top   - rect.bottom + 1,
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   628
			_settings_game.station.modified_catchment ? FindCatchmentRadius(st) : (uint)CA_UNMODIFIED
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   629
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
		memset(accepts, 0, sizeof(accepts));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   634
	/* Adjust in case our station only accepts fewer kinds of goods */
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
   635
	for (CargoID i = 0; i < NUM_CARGO; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
		uint amt = min(accepts[i], 15);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   638
		/* Make sure the station can accept the goods type. */
6655
951b0ba32eb1 (svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents: 6632
diff changeset
   639
		bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
951b0ba32eb1 (svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents: 6632
diff changeset
   640
		if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   641
				(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
			amt = 0;
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   643
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
   645
		SB(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, amt >= 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   648
	/* Only show a message in case the acceptance was actually changed. */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   649
	uint new_acc = GetAcceptanceMask(st);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   650
	if (old_acc == new_acc) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   651
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   652
	/* show a message to report that the acceptance was changed? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	if (show_msg && st->owner == _local_player && st->facilities) {
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   654
		/* List of accept and reject strings for different number of
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   655
		 * cargo types */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   656
		static const StringID accept_msg[] = {
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   657
			STR_3040_NOW_ACCEPTS,
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   658
			STR_3041_NOW_ACCEPTS_AND,
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   659
		};
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   660
		static const StringID reject_msg[] = {
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   661
			STR_303E_NO_LONGER_ACCEPTS,
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   662
			STR_303F_NO_LONGER_ACCEPTS_OR,
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   663
		};
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   664
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   665
		/* Array of accepted and rejected cargo types */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   666
		CargoID accepts[2] = { CT_INVALID, CT_INVALID };
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   667
		CargoID rejects[2] = { CT_INVALID, CT_INVALID };
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   668
		uint num_acc = 0;
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   669
		uint num_rej = 0;
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   670
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   671
		/* Test each cargo type to see if its acceptange has changed */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   672
		for (CargoID i = 0; i < NUM_CARGO; i++) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   673
			if (HasBit(new_acc, i)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   674
				if (!HasBit(old_acc, i) && num_acc < lengthof(accepts)) {
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   675
					/* New cargo is accepted */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   676
					accepts[num_acc++] = i;
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   677
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
			} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   679
				if (HasBit(old_acc, i) && num_rej < lengthof(rejects)) {
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   680
					/* Old cargo is no longer accepted */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   681
					rejects[num_rej++] = i;
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   682
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
			}
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   684
		}
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   685
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   686
		/* Show news message if there are any changes */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   687
		if (num_acc > 0) ShowRejectOrAcceptNews(st, num_acc, accepts, accept_msg[num_acc - 1]);
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   688
		if (num_rej > 0) ShowRejectOrAcceptNews(st, num_rej, rejects, reject_msg[num_rej - 1]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   691
	/* redraw the station view since acceptance changed */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   692
	InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ACCEPTLIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
5098
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   695
static void UpdateStationSignCoord(Station *st)
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   696
{
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   697
	const StationRect *r = &st->rect;
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
   698
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   699
	if (r->IsEmpty()) return; /* no tiles belong to this station */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   700
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   701
	/* clamp sign coord to be inside the station rect */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   702
	st->xy = TileXY(ClampU(TileX(st->xy), r->left, r->right), ClampU(TileY(st->xy), r->top, r->bottom));
5098
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   703
	UpdateStationVirtCoordDirty(st);
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   704
}
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   705
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   706
/** This is called right after a station was deleted.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   707
 * It checks if the whole station is free of substations, and if so, the station will be
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   708
 * deleted after a little while.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   709
 * @param st Station
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   710
 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   711
static void DeleteStationIfEmpty(Station *st)
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   712
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
	if (st->facilities == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
		st->delete_ctr = 0;
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   715
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
27
87c8058a69b5 (svn r28) -Fix removing station merged with oilrig, will reset oilrigs ownership
darkvater
parents: 22
diff changeset
   716
	}
5098
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   717
	/* station remains but it probably lost some parts - station sign should stay in the station boundaries */
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   718
	UpdateStationSignCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   721
static CommandCost ClearTile_Station(TileIndex tile, byte flags);
977
bcafa4f6550a (svn r1472) -Fix: correct error message for when trying to build a railroad station over a bus/truck/etc-station.
darkvater
parents: 972
diff changeset
   722
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   723
/** Tries to clear the given area.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   724
 * @param tile TileIndex to start check
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   725
 * @param w width of search area
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   726
 * @param h height of search area
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   727
 * @param flags operation to perform
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   728
 * @param invalid_dirs prohibited directions (set of DiagDirections)
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   729
 * @param station StationID to be queried and returned if available
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   730
 * @param check_clear if clearing tile should be performed (in wich case, cost will be added)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   731
 * @return the cost in case of success, or an error code if it failed.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   732
 */
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   733
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint32 invalid_dirs, StationID* station, const FSMportsSpec *fsmportspec, bool check_clear = true)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
{
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   735
	CommandCost cost(EXPENSES_CONSTRUCTION);
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1328
diff changeset
   736
	int allowed_z = -1;
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   737
	byte layout_set = GB(invalid_dirs, 0, 3);
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   738
	byte *b = NULL;
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   739
	if (fsmportspec != NULL) {
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   740
		b = fsmportspec->layouts[layout_set];
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   741
		b++;  //skip orientation
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   742
		b++;  //skip minipic
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   743
	}
6718
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   744
	bool do_tile_test;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   745
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   746
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   747
		if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   748
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   749
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   750
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   751
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   753
		uint z;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   754
		Slope tileh = GetTileSlope(tile_cur, &z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   756
		/* Prohibit building if
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   757
		 *   1) The tile is "steep" (i.e. stretches two height levels)
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   758
		 * -OR-
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   759
		 *   2) The tile is non-flat if
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   760
		 *     a) the player building is an "old-school" AI
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   761
		 *   -OR-
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   762
		 *     b) the build_on_slopes switch is disabled
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   763
		 */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   764
		if (IsSteepSlope(tileh) ||
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   765
				((_is_old_ai_player || !_settings_game.construction.build_on_slopes) && tileh != SLOPE_FLAT)) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   766
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   769
		int flat_z = z;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   770
		if (tileh != SLOPE_FLAT) {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   771
			/* need to check so the entrance to the station is not pointing at a slope.
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   772
			 * This must be valid for all station tiles, as the user can remove single station tiles. */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   773
			if ((HasBit(invalid_dirs, DIAGDIR_NE) && !(tileh & SLOPE_NE)) ||
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   774
			    (HasBit(invalid_dirs, DIAGDIR_SE) && !(tileh & SLOPE_SE)) ||
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   775
			    (HasBit(invalid_dirs, DIAGDIR_SW) && !(tileh & SLOPE_SW)) ||
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   776
			    (HasBit(invalid_dirs, DIAGDIR_NW) && !(tileh & SLOPE_NW))) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   777
				return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
			}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   779
			cost.AddCost(_price.terraform);
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   780
			flat_z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   782
6718
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   783
		// do tile tests if it is not an airport or airport tile is 255
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   784
		do_tile_test = true;
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   785
		if (fsmportspec != NULL) {
6718
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   786
			if ((byte)*b++ == (byte)255) {
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   787
				do_tile_test = false;
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   788
			}
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   789
		};
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   790
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   791
		/* get corresponding flat level and make sure that all parts of the station have the same level. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
		if (allowed_z == -1) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   793
			/* first tile */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
			allowed_z = flat_z;
6718
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   795
		} else if (do_tile_test && (allowed_z != flat_z)) {
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
   796
			/* test here whether build on height permitted. for FSM ports with layout masks, this is not an error
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
   797
			 * land checking is done in airport placement
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
   798
			 */
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   799
			if (fsmportspec->layout_mask == NULL) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
6718
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   802
		if (do_tile_test) {
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   803
			// if station is set, then we have special handling to allow building on top of already existing stations.
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   804
			// so station points to INVALID_STATION if we can build on any station. or it points to a station if we're only allowed to build
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   805
			// on exactly that station.
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   806
			if (station != NULL && IsTileType(tile_cur, MP_STATION)) {
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   807
				if (!IsRailwayStation(tile_cur)) {
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   808
					return ClearTile_Station(tile_cur, DC_AUTO); // get error message
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   809
				} else {
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   810
					StationID st = GetStationIndex(tile_cur);
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   811
					if (*station == INVALID_STATION) {
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   812
						*station = st;
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   813
					} else if (*station != st) {
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   814
						return_cmd_error(STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING);
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   815
					}
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   816
				}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   817
			} else if (check_clear) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   818
				bool water_tile = IsWaterTile(tile_cur);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   819
				CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
6718
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
   820
				if (CmdFailed(ret)) return ret;
6799
2adc1052a548 (svn r10871) [NewGRF_ports] -Codechange: do not pay for clearing water tiles when placing watery tile on them anyway.
rubidium
parents: 6793
diff changeset
   821
				if (!water_tile) cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
		}
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   824
	} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
   829
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station, bool check_clear = true)
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
   830
{
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
   831
	return CheckFlatLandBelow(tile, w, h, flags, (uint32)invalid_dirs, station, NULL, check_clear);
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
   832
}
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
   833
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   834
static bool CanExpandRailroadStation(const Station *st, uint *fin, Axis axis)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
{
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   836
	uint curw = st->trainst_w;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   837
	uint curh = st->trainst_h;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   838
	TileIndex tile = fin[0];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
	uint w = fin[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
	uint h = fin[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   842
	if (_settings_game.station.nonuniform_stations) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   843
		/* determine new size of train station region.. */
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   844
		int x = min(TileX(st->train_tile), TileX(tile));
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   845
		int y = min(TileY(st->train_tile), TileY(tile));
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   846
		curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   847
		curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   848
		tile = TileXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
	} else {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   850
		/* do not allow modifying non-uniform stations,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   851
		 * the uniform-stations code wouldn't handle it well */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   852
		BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   853
			if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   854
				_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   855
				return false;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   856
			}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   857
		END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   858
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   859
		/* check so the orientation is the same */
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
   860
		if (GetRailStationAxis(st->train_tile) != axis) {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   861
			_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   862
			return false;
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   863
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   865
		/* check if the new station adjoins the old station in either direction */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   866
		if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   867
			/* above */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
			curh += h;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   869
		} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   870
			/* below */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   871
			tile -= TileDiffXY(0, curh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
			curh += h;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   873
		} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   874
			/* to the left */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
			curw += w;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   876
		} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   877
			/* to the right */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   878
			tile -= TileDiffXY(curw, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
			curw += w;
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   880
		} else {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
   881
			_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
			return false;
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   883
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
	}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   885
	/* make sure the final size is not too big. */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   886
	if (curw > _settings_game.station.station_spread || curh > _settings_game.station.station_spread) {
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   887
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   888
		return false;
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   889
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   891
	/* now tile contains the new value for st->train_tile
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   892
	 * curw, curh contain the new value for width and height */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
	fin[0] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
	fin[1] = curw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	fin[2] = curh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   899
static inline byte *CreateSingle(byte *layout, int n)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
	do *layout++ = 0; while (--i);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   903
	layout[((n - 1) >> 1) - n] = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   907
static inline byte *CreateMulti(byte *layout, int n, byte b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
	do *layout++ = b; while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
	if (n > 4) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   912
		layout[0 - n] = 0;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   913
		layout[n - 1 - n] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   918
static void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
{
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   920
	if (statspec != NULL && statspec->lengths >= plat_len &&
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   921
			statspec->platforms[plat_len - 1] >= numtracks &&
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   922
			statspec->layouts[plat_len - 1][numtracks - 1]) {
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   923
		/* Custom layout defined, follow it. */
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   924
		memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1],
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   925
			plat_len * numtracks);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   926
		return;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   927
	}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   928
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	if (plat_len == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
		CreateSingle(layout, numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
	} else {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   932
		if (numtracks & 1) layout = CreateSingle(layout, plat_len);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   933
		numtracks >>= 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
		while (--numtracks >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
			layout = CreateMulti(layout, plat_len, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
			layout = CreateMulti(layout, plat_len, 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   942
/** Build railroad station
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: 3482
diff changeset
   943
 * @param tile_org starting position of station dragging/placement
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   944
 * @param flags operation to perform
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   945
 * @param p1 various bitstuffed elements
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   946
 * - p1 = (bit  0)    - orientation (Axis)
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: 2133
diff changeset
   947
 * - p1 = (bit  8-15) - number of tracks
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   948
 * - p1 = (bit 16-23) - platform length
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   949
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   950
 * @param p2 various bitstuffed elements
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   951
 * - p2 = (bit  0- 3) - railtype (p2 & 0xF)
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   952
 * - p2 = (bit  8-15) - custom station class
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   953
 * - p2 = (bit 16-23) - custom station id
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   955
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	/* Does the authority allow this? */
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   958
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   959
	if (!ValParamRailtype((RailType)(p2 & 0xF))) return CMD_ERROR;
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   960
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   961
	/* unpack parameters */
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   962
	Axis axis = Extract<Axis, 0>(p1);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   963
	uint numtracks = GB(p1,  8, 8);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   964
	uint plat_len  = GB(p1, 16, 8);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   965
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
   966
	int w_org, h_org;
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   967
	if (axis == AXIS_X) {
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   968
		w_org = plat_len;
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   969
		h_org = numtracks;
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   970
	} else {
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   971
		h_org = plat_len;
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   972
		w_org = numtracks;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   975
	if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR;
1781
92e08797c84b (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   976
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   977
	/* these values are those that will be stored in train_tile and station_platforms */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   978
	uint finalvalues[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
	finalvalues[0] = tile_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	finalvalues[1] = w_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
	finalvalues[2] = h_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   983
	/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   984
	StationID est = INVALID_STATION;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   985
	/* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   986
	 * for detail info, see:
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   987
	 * https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   988
	CommandCost ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL);
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   989
	if (CmdFailed(ret)) return ret;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   990
	CommandCost cost(EXPENSES_CONSTRUCTION, ret.GetCost() + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   992
	Station *st = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   993
	bool check_surrounding = true;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   994
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   995
	if (_settings_game.station.adjacent_stations) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   996
		if (est != INVALID_STATION) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
   997
			if (HasBit(p1, 24)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   998
				/* You can't build an adjacent station over the top of one that
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
   999
				 * already exists. */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1000
				return_cmd_error(STR_MUST_REMOVE_RAILWAY_STATION_FIRST);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1001
			} else {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1002
				/* Extend the current station, and don't check whether it will
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1003
				 * be near any other stations. */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1004
				st = GetStation(est);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1005
				check_surrounding = false;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1006
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1007
		} else {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1008
			/* There's no station here. Don't check the tiles surrounding this
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1009
			 * one if the player wanted to build an adjacent station. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1010
			if (HasBit(p1, 24)) check_surrounding = false;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1011
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1012
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1013
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1014
	if (check_surrounding) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1015
		/* Make sure there are no similar stations around us. */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1016
		st = GetStationAround(tile_org, w_org, h_org, est);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1017
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1018
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1020
	/* See if there is a deleted station close to us. */
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
  1021
	if (st == NULL) st = GetClosestStationFromTile(tile_org);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
	if (st != NULL) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1024
		/* Reuse an existing station. */
6390
542cf60254b2 (svn r8794) -Fix
tron
parents: 6378
diff changeset
  1025
		if (st->owner != _current_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
		if (st->train_tile != 0) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1029
			/* check if we want to expanding an already existing station? */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1030
			if (_is_old_ai_player || !_settings_game.station.join_stations)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
				return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD);
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
  1032
			if (!CanExpandRailroadStation(st, finalvalues, axis))
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
  1033
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1036
		/* XXX can't we pack this in the "else" part of the if above? */
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1037
		if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR;
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4399
diff changeset
  1038
	} else {
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1039
		/* allocate and initialize new station */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1040
		if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1041
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1042
		if (flags & DC_EXEC) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1043
			st = new Station(tile_org);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1044
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1045
			st->town = ClosestTownFromTile(tile_org, UINT_MAX);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1046
			st->string_id = GenerateStationName(st, tile_org, STATIONNAMING_RAIL);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1047
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1048
			if (IsValidPlayer(_current_player)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1049
				SetBit(st->town->have_ratings, _current_player);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1050
			}
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1051
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1054
	/* Check if the given station class is valid */
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1055
	if (GB(p2, 8, 8) >= GetNumStationClasses()) return CMD_ERROR;
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1056
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1057
	/* Check if we can allocate a custom stationspec to this station */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1058
	const StationSpec *statspec = GetCustomStationSpec((StationClassID)GB(p2, 8, 8), GB(p2, 16, 8));
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1059
	int specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC);
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1060
	if (specindex == -1) return CMD_ERROR;
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1061
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1062
	if (statspec != NULL) {
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1063
		/* Perform NewStation checks */
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1064
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1065
		/* Check if the station size is permitted */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1066
		if (HasBit(statspec->disallowed_platforms, numtracks - 1) || HasBit(statspec->disallowed_lengths, plat_len - 1)) {
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1067
			return CMD_ERROR;
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1068
		}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1069
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1070
		/* Check if the station is buildable */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1071
		if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1072
			return CMD_ERROR;
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1073
		}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1074
	}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1075
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
	if (flags & DC_EXEC) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1077
		TileIndexDiff tile_delta;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
		byte *layout_ptr;
3769
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1079
		byte numtracks_orig;
2824
a7a9d3239884 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1080
		Track track;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1082
		/* Now really clear the land below the station
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1083
		 * It should never return CMD_ERROR.. but you never know ;)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1084
		 * (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1085
		ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL);
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1086
		if (CmdFailed(ret)) return ret;
313
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
  1087
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
		st->train_tile = finalvalues[0];
5972
564f98b055d1 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5969
diff changeset
  1089
		st->AddFacility(FACIL_TRAIN, finalvalues[0]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
		st->trainst_w = finalvalues[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
		st->trainst_h = finalvalues[2];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1093
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1094
		st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1095
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1096
		if (statspec != NULL) {
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1097
			/* Include this station spec's animation trigger bitmask
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1098
			 * in the station's cached copy. */
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1099
			st->cached_anim_triggers |= statspec->anim_triggers;
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1100
		}
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1101
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
  1102
		tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
  1103
		track = AxisToTrack(axis);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1104
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1105
		layout_ptr = AllocaM(byte, numtracks * plat_len);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1106
		GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1107
3769
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1108
		numtracks_orig = numtracks;
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1109
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
		do {
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
  1111
			TileIndex tile = tile_org;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
			int w = plat_len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
			do {
3769
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1114
				byte layout = *layout_ptr++;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1115
				MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p2, 0, 4));
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1116
				SetCustomStationSpecIndex(tile, specindex);
3742
8528d7737361 (svn r4724) - Newstations: Add per-tile random data for station tiles.
peter1138
parents: 3741
diff changeset
  1117
				SetStationTileRandomBits(tile, GB(Random(), 0, 4));
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1118
				SetStationAnimationFrame(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1120
				if (statspec != NULL) {
3784
41d43d1191a5 (svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents: 3775
diff changeset
  1121
					/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
41d43d1191a5 (svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents: 3775
diff changeset
  1122
					uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1123
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1124
					/* As the station is not yet completely finished, the station does not yet exist. */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1125
					uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, NULL, tile);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1126
					if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis);
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1127
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1128
					/* Trigger station animation -- after building? */
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1129
					StationAnimationTrigger(st, tile, STAT_ANIM_BUILT);
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1130
				}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1131
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
				tile += tile_delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
			} while (--w);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1134
			AddTrackToSignalBuffer(tile_org, track, _current_player);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1135
			YapfNotifyTrackLayoutChange(tile_org, track);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1136
			tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
		} while (--numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1139
		st->MarkTilesDirty(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
		UpdateStationAcceptance(st, false);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1142
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1143
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
static void MakeRailwayStationAreaSmaller(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	uint w = st->trainst_w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	uint h = st->trainst_h;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1153
	TileIndex tile = st->train_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
restart:
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1156
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1157
	/* too small? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
	if (w != 0 && h != 0) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1159
		/* check the left side, x = constant, y changes */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1160
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1161
			/* the left side is unused? */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1162
			if (++i == h) {
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1163
				tile += TileDiffXY(1, 0);
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1164
				w--;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1165
				goto restart;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1166
			}
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1167
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1169
		/* check the right side, x = constant, y changes */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1170
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1171
			/* the right side is unused? */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1172
			if (++i == h) {
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1173
				w--;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1174
				goto restart;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1175
			}
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1176
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1178
		/* check the upper side, y = constant, x changes */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1179
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1180
			/* the left side is unused? */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1181
			if (++i == w) {
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1182
				tile += TileDiffXY(0, 1);
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1183
				h--;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1184
				goto restart;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1185
			}
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1186
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1188
		/* check the lower side, y = constant, x changes */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1189
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1190
			/* the left side is unused? */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1191
			if (++i == w) {
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1192
				h--;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1193
				goto restart;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1194
			}
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1195
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
		tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
	st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
	st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
	st->train_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1205
/** Remove a single tile from a railroad station.
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1206
 * This allows for custom-built station with holes and weird layouts
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: 3482
diff changeset
  1207
 * @param tile tile of station piece to remove
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1208
 * @param flags operation to perform
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1209
 * @param p1 start_tile
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1210
 * @param p2 unused
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1211
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1212
CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1214
	TileIndex start = p1 == 0 ? tile : p1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1215
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1216
	/* Count of the number of tiles removed */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1217
	int quantity = 0;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1218
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1219
	if (tile >= MapSize() || start >= MapSize()) return CMD_ERROR;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1220
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1221
	/* make sure sx,sy are smaller than ex,ey */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1222
	int ex = TileX(tile);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1223
	int ey = TileY(tile);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1224
	int sx = TileX(start);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1225
	int sy = TileY(start);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1226
	if (ex < sx) Swap(ex, sx);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1227
	if (ey < sy) Swap(ey, sy);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1228
	tile = TileXY(sx, sy);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1229
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1230
	int size_x = ex - sx + 1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1231
	int size_y = ey - sy + 1;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1232
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1233
	/* Do the action for every tile into the area */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1234
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1235
		/* Make sure the specified tile is a railroad station */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1236
		if (!IsTileType(tile2, MP_STATION) || !IsRailwayStation(tile2)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1237
			continue;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1238
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1239
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1240
		/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1241
		if (!EnsureNoVehicleOnGround(tile2)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1242
			continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
		}
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1244
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1245
		/* Check ownership of station */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1246
		Station *st = GetStationByTile(tile2);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1247
		if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1248
			continue;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1249
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1250
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1251
		/* Do not allow removing from stations if non-uniform stations are not enabled
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1252
		 * The check must be here to give correct error message
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1253
		 */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1254
		if (!_settings_game.station.nonuniform_stations) return_cmd_error(STR_NONUNIFORM_STATIONS_DISALLOWED);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1255
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1256
		/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1257
		quantity++;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1258
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1259
		if (flags & DC_EXEC) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1260
			/* read variables before the station tile is removed */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1261
			uint specindex = GetCustomStationSpecIndex(tile2);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1262
			Track track = GetRailStationTrack(tile2);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1263
			Owner owner = GetTileOwner(tile2);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1264
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1265
			DoClearSquare(tile2);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1266
			st->rect.AfterRemoveTile(st, tile2);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1267
			AddTrackToSignalBuffer(tile2, track, owner);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1268
			YapfNotifyTrackLayoutChange(tile2, track);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1269
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1270
			DeallocateSpecFromStation(st, specindex);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1271
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1272
			/* now we need to make the "spanned" area of the railway station smaller
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1273
			 * if we deleted something at the edges.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1274
			 * we also need to adjust train_tile. */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1275
			MakeRailwayStationAreaSmaller(st);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1276
			st->MarkTilesDirty(false);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1277
			UpdateStationSignCoord(st);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1278
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1279
			/* if we deleted the whole station, delete the train facility. */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1280
			if (st->train_tile == 0) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1281
				st->facilities &= ~FACIL_TRAIN;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1282
				InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1283
				UpdateStationVirtCoordDirty(st);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1284
				DeleteStationIfEmpty(st);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1285
			}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1286
		}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1287
	} END_TILE_LOOP(tile2, size_x, size_y, tile)
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1288
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1289
	/* If we've not removed any tiles, give an error */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1290
	if (quantity == 0) return CMD_ERROR;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1291
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1292
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_rail_station * quantity);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
3928
791f04fb29ad (svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents: 3900
diff changeset
  1295
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1296
static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1298
	/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1299
	if (_current_player == OWNER_WATER && _settings_game.station.nonuniform_stations) {
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: 3482
diff changeset
  1300
		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1301
	}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1302
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
	/* Current player owns the station? */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1304
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
	/* determine width and height of platforms */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
	tile = st->train_tile;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1308
	int w = st->trainst_w;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1309
	int h = st->trainst_h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1310
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
	assert(w != 0 && h != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1313
	CommandCost cost(EXPENSES_CONSTRUCTION);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
	/* clear all areas of the station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
		int w_bak = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
		do {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1318
			/* for nonuniform stations, only remove tiles that are actually train station tiles */
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1319
			if (st->TileBelongsToRailStation(tile)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1320
				if (!EnsureNoVehicleOnGround(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
					return CMD_ERROR;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1322
				cost.AddCost(_price.remove_rail_station);
2824
a7a9d3239884 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1323
				if (flags & DC_EXEC) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1324
					/* read variables before the station tile is removed */
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1325
					Track track = GetRailStationTrack(tile);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1326
					Owner owner = GetTileOwner(tile); // _current_player can be OWNER_WATER
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
					DoClearSquare(tile);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1328
					AddTrackToSignalBuffer(tile, track, owner);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1329
					YapfNotifyTrackLayoutChange(tile, track);
2824
a7a9d3239884 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1330
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
			}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1332
			tile += TileDiffXY(1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
		} while (--w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
		w = w_bak;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1335
		tile += TileDiffXY(-w, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
	} while (--h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
	if (flags & DC_EXEC) {
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1339
		st->rect.AfterRemoveRect(st, st->train_tile, st->trainst_w, st->trainst_h);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1340
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
		st->train_tile = 0;
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1342
		st->trainst_w = st->trainst_h = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
		st->facilities &= ~FACIL_TRAIN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1345
		free(st->speclist);
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1346
		st->num_specs = 0;
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1347
		st->speclist  = NULL;
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1348
		st->cached_anim_triggers = 0;
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1349
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1350
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1354
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
	return cost;
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
6694
a10a42eefd52 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6683
diff changeset
  1358
/**
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1359
 * @param truck_station Determines whether a stop is ROADSTOP_BUS or ROADSTOP_TRUCK
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1360
 * @param st The Station to do the whole procedure for
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1361
 * @return a pointer to where to link a new RoadStop*
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
  1362
 */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1363
static RoadStop **FindRoadStopSpot(bool truck_station, Station *st)
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1364
{
3691
7e1ad0718ed8 (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1365
	RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1366
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1367
	if (*primary_stop == NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1368
		/* we have no roadstop of the type yet, so write a "primary stop" */
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1369
		return primary_stop;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1370
	} else {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1371
		/* there are stops already, so append to the end of the list */
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1372
		RoadStop *stop = *primary_stop;
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1373
		while (stop->next != NULL) stop = stop->next;
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1374
		return &stop->next;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1375
	}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1376
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1377
3691
7e1ad0718ed8 (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1378
/** Build a bus or truck stop
7e1ad0718ed8 (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1379
 * @param tile tile to build the stop at
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1380
 * @param flags operation to perform
3333
41f8abe65d1e (svn r4111) Fix/Remove some stale comments
tron
parents: 3315
diff changeset
  1381
 * @param p1 entrance direction (DiagDirection)
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1382
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1383
 *           bit 1: 0 for normal, 1 for drive-through
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1384
 *           bit 2..4: the roadtypes
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1385
 *           bit 5: allow stations directly adjacent to other stations.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1387
CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1389
	bool type = HasBit(p2, 0);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1390
	bool is_drive_through = HasBit(p2, 1);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1391
	bool build_over_road  = is_drive_through && IsNormalRoadTile(tile);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1392
	bool town_owned_road  = false;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1393
	RoadTypes rts = (RoadTypes)GB(p2, 2, 3);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1394
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1395
	if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_player, rts)) return CMD_ERROR;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1396
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1397
	/* Trams only have drive through stops */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1398
	if (!is_drive_through && HasBit(rts, ROADTYPE_TRAM)) return CMD_ERROR;
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1399
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1400
	/* Saveguard the parameters */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1401
	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1402
	/* If it is a drive-through stop check for valid axis */
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1403
	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
6344
c5c1b17c8925 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6338
diff changeset
  1404
	/* Road bits in the wrong direction */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1405
	if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1407
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1408
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1409
	/* Not allowed to build over this road */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1410
	if (build_over_road) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1411
		RoadTypes cur_rts = GetRoadTypes(tile);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1412
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1413
		/* there is a road, check if we can build road+tram stop over it */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1414
		if (HasBit(cur_rts, ROADTYPE_ROAD)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1415
			Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1416
			if (road_owner == OWNER_TOWN) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1417
				town_owned_road = true;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1418
				if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1419
			} else {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1420
				if (road_owner != OWNER_NONE && !CheckOwnership(road_owner)) return CMD_ERROR;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1421
			}
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1422
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1423
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1424
		/* there is a tram, check if we can build road+tram stop over it */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1425
		if (HasBit(cur_rts, ROADTYPE_TRAM)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1426
			Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1427
			if (tram_owner != OWNER_NONE && !CheckOwnership(tram_owner)) return CMD_ERROR;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1428
		}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1429
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1430
		/* Don't allow building the roadstop when vehicles are already driving on it */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1431
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1432
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1433
		/* Do not remove roadtypes! */
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1434
		rts |= cur_rts;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1435
	}
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1436
	CommandCost cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1437
	if (CmdFailed(cost)) return cost;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1438
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1439
	Station *st = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1440
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1441
	if (!_settings_game.station.adjacent_stations || !HasBit(p2, 5)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1442
		st = GetStationAround(tile, 1, 1, INVALID_STATION);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1443
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1444
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
	/* Find a station close to us */
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
  1447
	if (st == NULL) st = GetClosestStationFromTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1449
	/* give us a road stop in the list, and check if something went wrong */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1450
	if (!RoadStop::CanAllocateItem()) return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
6084
75d052b142e5 (svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents: 5972
diff changeset
  1451
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  1452
	if (st != NULL &&
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1453
			GetNumRoadStopsInStation(st, ROADSTOP_BUS) + GetNumRoadStopsInStation(st, ROADSTOP_TRUCK) >= RoadStop::LIMIT) {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1454
		return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1455
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1456
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
	if (st != NULL) {
6390
542cf60254b2 (svn r8794) -Fix
tron
parents: 6378
diff changeset
  1458
		if (st->owner != _current_player) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1460
		}
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1461
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1462
		if (!st->rect.BeforeAddTile(tile, StationRect::ADD_TEST)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	} else {
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1464
		/* allocate and initialize new station */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1465
		if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1466
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1467
		if (flags & DC_EXEC) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1468
			st = new Station(tile);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1469
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1470
			st->town = ClosestTownFromTile(tile, UINT_MAX);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1471
			st->string_id = GenerateStationName(st, tile, STATIONNAMING_ROAD);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1472
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1473
			if (IsValidPlayer(_current_player)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1474
				SetBit(st->town->have_ratings, _current_player);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1475
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1476
			st->sign.width_1 = 0;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1477
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1480
	cost.AddCost((type) ? _price.build_truck_station : _price.build_bus_station);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
	if (flags & DC_EXEC) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1483
		RoadStop *road_stop = new RoadStop(tile);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1484
		/* Insert into linked list of RoadStops */
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1485
		RoadStop **currstop = FindRoadStopSpot(type, st);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1486
		*currstop = road_stop;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1487
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1488
		/*initialize an empty station */
5972
564f98b055d1 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5969
diff changeset
  1489
		st->AddFacility((type) ? FACIL_TRUCK_STOP : FACIL_BUS_STOP, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1491
		st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1492
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1493
		RoadStopType rs_type = type ? ROADSTOP_TRUCK : ROADSTOP_BUS;
6424
65bf2bbe789d (svn r8833) -Fix
tron
parents: 6419
diff changeset
  1494
		if (is_drive_through) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1495
			MakeDriveThroughRoadStop(tile, st->owner, st->index, rs_type, rts, (Axis)p1, town_owned_road);
6424
65bf2bbe789d (svn r8833) -Fix
tron
parents: 6419
diff changeset
  1496
		} else {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1497
			MakeRoadStop(tile, st->owner, st->index, rs_type, rts, (DiagDirection)p1);
6424
65bf2bbe789d (svn r8833) -Fix
tron
parents: 6419
diff changeset
  1498
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
		UpdateStationAcceptance(st, false);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1502
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1503
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1508
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1509
static void *ClearRoadStopStatusEnum(Vehicle *v, void *)
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1510
{
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1511
	if (v->type == VEH_ROAD) ClrBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1512
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1513
	return NULL;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1514
}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1515
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1516
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1517
/** Remove a bus station
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1518
 * @param st Station to remove
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1519
 * @param flags operation to perform
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1520
 * @param tile TileIndex been queried
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1521
 * @return cost or failure of operation
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1522
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1523
static CommandCost RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1525
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
		return CMD_ERROR;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1527
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1529
	bool is_truck = IsTruckStop(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1530
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1531
	RoadStop **primary_stop;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1532
	RoadStop *cur_stop;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1533
	if (is_truck) { // truck stop
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1534
		primary_stop = &st->truck_stops;
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1535
		cur_stop = GetRoadStopByTile(tile, ROADSTOP_TRUCK);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1536
	} else {
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1537
		primary_stop = &st->bus_stops;
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1538
		cur_stop = GetRoadStopByTile(tile, ROADSTOP_BUS);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1539
	}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1540
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1541
	assert(cur_stop != NULL);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1542
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1543
	/* don't do the check for drive-through road stops when company bankrupts */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1544
	if (IsDriveThroughStopTile(tile) && (flags & DC_BANKRUPT)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1545
		/* remove the 'going through road stop' status from all vehicles on that tile */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1546
		if (flags & DC_EXEC) VehicleFromPos(tile, NULL, &ClearRoadStopStatusEnum);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1547
	} else {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1548
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  1549
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
	if (flags & DC_EXEC) {
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1552
		if (*primary_stop == cur_stop) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1553
			/* removed the first stop in the list */
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1554
			*primary_stop = cur_stop->next;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1555
			/* removed the only stop? */
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1556
			if (*primary_stop == NULL) {
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1557
				st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP);
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1558
			}
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1559
		} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1560
			/* tell the predecessor in the list to skip this stop */
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1561
			RoadStop *pred = *primary_stop;
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1562
			while (pred->next != cur_stop) pred = pred->next;
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1563
			pred->next = cur_stop->next;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1564
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1566
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
5959
6a4c261987c3 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5948
diff changeset
  1567
		delete cur_stop;
4398
e889842a75a1 (svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents: 4397
diff changeset
  1568
		DoClearSquare(tile);
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1569
		st->rect.AfterRemoveTile(st, tile);
4398
e889842a75a1 (svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents: 4397
diff changeset
  1570
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1575
	return CommandCost(EXPENSES_CONSTRUCTION, (is_truck) ? _price.remove_truck_station : _price.remove_bus_station);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1578
/** Remove a bus or truck stop
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1579
 * @param tile tile to remove the stop from
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1580
 * @param flags operation to perform
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1581
 * @param p1 not used
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1582
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1583
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1584
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1585
{
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1586
	/* Make sure the specified tile is a road stop of the correct type */
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1587
	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != GB(p2, 0, 1)) return CMD_ERROR;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1588
	Station *st = GetStationByTile(tile);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1589
	/* Save the stop info before it is removed */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1590
	bool is_drive_through = IsDriveThroughStopTile(tile);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1591
	RoadTypes rts = GetRoadTypes(tile);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1592
	RoadBits road_bits = IsDriveThroughStopTile(tile) ?
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1593
			((GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) :
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1594
			DiagDirToRoadBits(GetRoadStopDir(tile));
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1595
	bool is_towns_road = is_drive_through && GetStopBuiltOnTownRoad(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1596
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1597
	CommandCost ret = RemoveRoadStop(st, flags, tile);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1598
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1599
	/* If the stop was a drive-through stop replace the road */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1600
	if ((flags & DC_EXEC) && CmdSucceeded(ret) && is_drive_through) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1601
		/* Rebuild the drive throuhg road stop. As a road stop can only be
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1602
		 * removed by the owner of the roadstop, _current_player is the
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1603
		 * owner of the road stop. */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1604
		MakeRoadNormal(tile, road_bits, rts, is_towns_road ? ClosestTownFromTile(tile, UINT_MAX)->index : 0,
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1605
				is_towns_road ? OWNER_TOWN : _current_player, _current_player, _current_player);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1606
	}
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1607
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1608
	return ret;
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1609
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1611
/** Recalculate the noise generated by the airports of each town */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1612
void UpdateAirportsNoise()
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1613
{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1614
	Town *t;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1615
	const Station *st;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1616
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1617
	FOR_ALL_TOWNS(t) t->noise_reached = 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1618
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1619
	FOR_ALL_STATIONS(st) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1620
		if (IsAirport(st->xy)) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1621
			st->town->noise_reached += GetAirportNoiseLevelForTown(st->Airport(), st->town->xy, st->xy);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1622
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1623
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1624
}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1625
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1626
/** Get a possible noise reduction factor based on distance from town center.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1627
 * The further you get, the less noise you generate.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1628
 * So all those folks at city council can now happily slee...  work in their offices
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1629
 * @param afc AirportFTAClass pointer of the class being proposed
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1630
 * @param town_tile TileIndex of town's center, the one who will receive the airport's candidature
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1631
 * @param tile TileIndex where the new airport might be built
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1632
 * @return the noise that will be generated, according to distance
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1633
 */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1634
uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile)
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1635
{
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1636
	struct TileIndexDistance {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1637
		TileIndex index;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1638
		uint distance;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1639
	};
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1640
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1641
	uint distance;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1642
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1643
	/* 0 cannot be accounted, and 1 is the lowest that can be reduced from town.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1644
	 * So no need to go any further*/
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1645
	if (afc->noise_level < 2) return afc->noise_level;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1646
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1647
	/* Find the airport-to-be's closest corner to the town */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1648
	if (afc->size_x == 1 && afc->size_y == 1) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1649
		distance = DistanceManhattan(town_tile, tile);  // ont tile, one corner, it's THE corner
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1650
	} else {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1651
		/* calculate manhattan distance to town of each side of the airport */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1652
		TileIndexDistance dist[4]; ///< Array that will contain all 4 corners in TileIndex and distance
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1653
		uint min_tile = UINT_MAX;  ///< Sentinel value
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1654
		uint min_indice = 4;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1655
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1656
		/* Based on the size of the airport, establish location of each corner*/
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1657
		dist[0].index = tile; // north tile
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1658
		dist[1].index = TileAddWrap(tile, afc->size_x - 1, afc->size_y - 1);  // south tile
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1659
		dist[2].index = TileAddWrap(tile, afc->size_x - 1, 0);  // west tile
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1660
		dist[3].index = TileAddWrap(tile, 0, afc->size_y - 1); //east tile
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1661
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1662
		/* now, go and find the smallest one, thus the closest to town */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1663
		for (uint i = 0; i < 4; i++) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1664
			dist[i].distance = DistanceManhattan(town_tile, dist[i].index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1665
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1666
			if (dist[i].distance < min_tile) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1667
				min_tile = dist[i].distance;  // here's a new candidate
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1668
				min_indice = i;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1669
			}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1670
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1671
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1672
		distance = dist[min_indice].distance;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1673
	}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1674
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1675
	/* The steps for measuring noise reduction are based on the "magical" (and arbitrary) 8 base distance
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1676
	 * adding the town_council_tolerance 4 times, as a way to graduate, depending of the tolerance.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1677
	 * Basically, it says that the less tolerant a town is, the bigger the distance before
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1678
	 * an actual decrease can be granted */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1679
	uint8 town_tolerance_distance = 8 + (_settings_game.difficulty.town_council_tolerance * 4);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1680
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1681
	/* now, we want to have the distance segmented using the distance judged bareable by town
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1682
	 * This will give us the coefficient of reduction the distance provides. */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1683
	uint noise_reduction = distance / town_tolerance_distance;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1684
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1685
	/* If the noise reduction equals the airport noise itself, don't give it for free.
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1686
	 * Otherwise, simply reduce the airport's level. */
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1687
	return noise_reduction >= afc->noise_level ? 1 : afc->noise_level - noise_reduction;
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1688
}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1689
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1690
/** Place an Airport.
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: 3482
diff changeset
  1691
 * @param tile tile where airport will be built
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1692
 * @param flags operation to perform
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1693
 * @param p1 various bitstuffed elements
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
  1694
 * - p1 = (bit  0-2)  - layout_set for newgrf
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1695
 * - p1 = (bit  8-15) - length
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1696
 * - p1 = (bit 16-23) - width
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1697
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1698
 * @param p2 various bitstuffed elements
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1699
 * - p2 = (bit  8-15) - custom fsmport class
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1700
 * - p2 = (bit 16-23) - custom fsmport id
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1702
CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1704
	bool airport_upgrade = true;
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
  1705
	byte layout_set = GB(p1, 0, 3);
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
  1706
	const uint32 airport_type_for_flat_check = (GB(p2, 8, 8) << 3) | layout_set;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1708
	/* Check if a valid, buildable airport was chosen for construction */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1709
	//if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1710
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1711
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
		return CMD_ERROR;
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1713
	}
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1714
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1715
	Town *t = ClosestTownFromTile(tile, UINT_MAX);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1716
	Station *st = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1717
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1718
	/* Check if the given station class is valid */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1719
	if (GB(p2, 8, 8) >= FSMPORTS_CLASS_MAX) return CMD_ERROR;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1720
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1721
	/* Check if we can allocate a custom stationspec to this station */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1722
	const FSMportsSpec *fsmportsspec = GetCustomFSMportsSpec((FSMportsClassID)GB(p2, 8, 8), GB(p2, 16, 8));
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1723
	if (fsmportsspec == NULL) return CMD_ERROR;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1724
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1725
	/* Go get the final noise level, that is base noise minus factor from distance to town center */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1726
	uint newnoise_level = GetAirportNoiseLevelForTown(fsmportsspec->portFSM, t->xy, tile);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1727
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1728
	/* Check if local auth would allow a new airport */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1729
	bool authority_refused;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1730
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1731
	if (_settings_game.economy.station_noise_level) {
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1732
		/* do not allow to build a new airport if this raise the town noise over the maximum allowed by town */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1733
		authority_refused = (t->noise_reached + newnoise_level) > t->MaxTownNoise();
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1734
	} else {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1735
		uint num = 0;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1736
		const Station *st;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1737
		FOR_ALL_STATIONS(st) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1738
			if (st->town == t && st->facilities & FACIL_AIRPORT && st->Airport() != AirportFTAClass::oil_rig) num++;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1739
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1740
		authority_refused = (num >= 2);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1741
	}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1742
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1743
	if (authority_refused) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1744
		SetDParam(0, t->index);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1745
		return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1746
	}
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1747
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1748
	/* Perform NewStation checks */
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1749
	byte w = fsmportsspec->size_x[layout_set];
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1750
	byte h = fsmportsspec->size_y[layout_set];
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1751
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1752
	if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1753
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1754
		return CMD_ERROR;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1755
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1756
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1757
	/* Check if the station is buildable */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1758
	if (HasBit(fsmportsspec->callbackmask, CBM_STATION_AVAIL) && GetFSMportsCallback(CBID_STATION_AVAILABILITY, 0, 0, fsmportsspec, NULL, INVALID_TILE) == 0) {
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1759
		return CMD_ERROR;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1760
	}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1761
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1762
	if (!_settings_game.station.adjacent_stations || !HasBit(p1, 24)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1763
		st = GetStationAround(tile, w, h, INVALID_STATION);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1764
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1765
	} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1766
		st = NULL;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1767
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1769
	/* Find a station close to us */
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
  1770
	if (st == NULL) st = GetClosestStationFromTile(tile);
0
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
	if (st != NULL) {
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1773
		if (st->owner != _current_player) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1775
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1776
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1777
		if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1778
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1779
		if (st->airport_tile != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1780
			return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1781
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
		airport_upgrade = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1785
		/* allocate and initialize new station */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1786
		if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1787
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1788
		if (flags & DC_EXEC) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1789
			st = new Station(tile);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1790
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1791
			st->town = t;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1792
			st->string_id = GenerateStationName(st, tile, !(fsmportsspec->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1793
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1794
			if (IsValidPlayer(_current_player)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1795
				SetBit(st->town->have_ratings, _current_player);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1796
			}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1797
			st->sign.width_1 = 0;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1798
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1801
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1802
	flags |= DC_NO_WATER;
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1803
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1804
	/* do FSM layout mask checks
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1805
	 * These allow placement on water, and irregular heights within layout.
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1806
	 * If building on water is allowed for one tile, permit it for whole airport. This is not the problem it appears.
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1807
	 * This routine does all the other tile validations, so although CMD_NO_WATER is cleared, it has already verified that
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1808
	 * the tiles have the correct land/water statuses.
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1809
	 */
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1810
	if (fsmportsspec->layout_mask != NULL) {
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1811
		const byte *mask_ptr = fsmportsspec->layout_mask[layout_set] + 2;  // width*length flagbytes. Also skip orientation and "filler" byte
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1812
		BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
6801
a0b87c971f44 (svn r10873) [NewGRF_ports] -Fix: layouts and layout_masks had one level of pointer indirection too much.
rubidium
parents: 6799
diff changeset
  1813
			byte mask = *mask_ptr++;
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1814
			if (mask & 0x80) {
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1815
				/* do water tests */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1816
				if (IsWaterTile(tile_cur)) {
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1817
					flags &= ~DC_NO_WATER;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1818
					if (flags & DC_EXEC) st->FSMport_flood_protected = true;
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1819
				} else {
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1820
					_error_message = STR_304B_SITE_UNSUITABLE;
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1821
					return CMD_ERROR;
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1822
				}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1823
			} else if (IsWaterTile(tile_cur)) {
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1824
				/* tile should be land, but is water */
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1825
				_error_message = STR_3807_CAN_T_BUILD_ON_WATER;
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1826
				return CMD_ERROR;
6770
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1827
			}
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1828
			//TODO: add height comparison & validation code here
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1829
		} END_TILE_LOOP(tile_cur, w, h, tile)
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1830
	}
8400b517b905 (svn r10824) [NewGRF_ports] -Feature: Added basic code for seaplane airport support.
richk
parents: 6759
diff changeset
  1831
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
  1832
	CommandCost cost = CheckFlatLandBelow(tile, w, h, flags, airport_type_for_flat_check, NULL, fsmportsspec, true);
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1833
	if (CmdFailed(cost)) return cost;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  1834
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1835
	cost.AddCost(_price.build_airport * w * h);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
	if (flags & DC_EXEC) {
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1838
		/* Always add the noise, so there will be no need to recalculate when option toggles */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1839
		st->town->noise_reached += newnoise_level;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1840
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
		st->airport_tile = tile;
5972
564f98b055d1 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5969
diff changeset
  1842
		st->AddFacility(FACIL_AIRPORT, tile);
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
  1843
		st->airport_flags.ResetAll();
6745
f45a41940079 (svn r10783) [NewGRF_ports] -Feature: Added placing FSMport in any of up to 4 different orientations. GUI now has a preview image for each orientation - not interactive, just a screenshot stored.
richk
parents: 6743
diff changeset
  1844
		st->FSMport_layout_set = layout_set;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1845
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1846
		st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1847
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1848
		/* if airport was demolished while planes were en-route to it, the
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1849
		 * positions can no longer be the same (v->u.air.pos), since different
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1850
		 * airports have different indexes. So update all planes en-route to this
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1851
		 * airport. Only update if
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1852
		 * 1. airport is upgraded
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1853
		 * 2. airport is added to existing station (unfortunately unavoideable)
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1854
		 */
10346
a1e9f8871c05 (svn r12887) [NewGRF_ports] -Fix: When upgrading an airport, remove the existing FSM first.
richk
parents: 10274
diff changeset
  1855
		if (airport_upgrade) {
a1e9f8871c05 (svn r12887) [NewGRF_ports] -Fix: When upgrading an airport, remove the existing FSM first.
richk
parents: 10274
diff changeset
  1856
			UpdateAirplanesOnNewStation(st);
a1e9f8871c05 (svn r12887) [NewGRF_ports] -Fix: When upgrading an airport, remove the existing FSM first.
richk
parents: 10274
diff changeset
  1857
			DeallocateSpecFromFSMports(st, 1);
a1e9f8871c05 (svn r12887) [NewGRF_ports] -Fix: When upgrading an airport, remove the existing FSM first.
richk
parents: 10274
diff changeset
  1858
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1859
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1860
		int fsmportspecindex = AllocateFSMportsSpecToStation(fsmportsspec, st, flags & DC_EXEC);
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1861
		if (fsmportspecindex == -1) return CMD_ERROR;
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1862
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1863
		const byte *layout_ptr = fsmportsspec->layouts[layout_set];
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1864
		st->FSMport_orientation = *layout_ptr++; //orientation
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1865
		layout_ptr++; //skip minipic ID
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1866
6867
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  1867
		byte partial_snow_desert;
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  1868
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1869
		BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
6867
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  1870
			partial_snow_desert = 0x00;
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1871
			byte layout = *layout_ptr++;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1872
			if ((GetTropicZone(tile_cur) == TROPICZONE_DESERT) || ((GetTileZ(tile_cur) >= GetSnowLine() && _settings_game.game_creation.landscape == LT_ARCTIC)))
6867
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  1873
				partial_snow_desert = 1;
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1874
			MakeAirport(tile_cur, st->owner, st->index, layout);
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
  1875
			if (layout != 255)
6867
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  1876
			{
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  1877
				if (partial_snow_desert != 0)
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  1878
					SetTropicZone(tile_cur, TROPICZONE_DESERT);
6804
2772178ef0d7 (svn r10876) [NewGRF_ports] -Feature: if layout byte is 0xFF, do not clear the tile in CheckFlatLandBelow. Current fsmportspec now passed to CheckFlatLandBelow for direct access to layouts.
richk
parents: 6802
diff changeset
  1879
				SetCustomFSMportsSpecIndex(tile_cur, fsmportspecindex);  //set top bit of m6 to indicate an fsmportsspec
6867
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  1880
			}
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1881
		} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
		UpdateStationAcceptance(st, false);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1885
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1886
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1887
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1888
		if (_settings_game.economy.station_noise_level) {
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1889
			InvalidateWindow(WC_TOWN_VIEW, st->town->index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1890
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
	}
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
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1895
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1896
static CommandCost RemoveAirport(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1898
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1899
		return CMD_ERROR;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1900
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1902
	TileIndex tile = st->airport_tile;
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1903
	byte layout_set = st->FSMport_layout_set;
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1904
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1905
	const FSMportsSpec *fsmportsspec = st->fsmportsspeclist[GetCustomStationSpecIndex(tile)].spec;
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1906
	int w = fsmportsspec->size_x[layout_set];
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1907
	int h = fsmportsspec->size_y[layout_set];
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1908
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1909
	CommandCost cost(EXPENSES_CONSTRUCTION, w * h * _price.remove_airport);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  1911
	const Vehicle *v;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1912
	FOR_ALL_VEHICLES(v) {
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1913
		if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1914
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1915
		if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1916
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1917
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1918
	const byte *layout_ptr = fsmportsspec->layouts[layout_set] + 2; // skip orientation and minipic ID
6801
a0b87c971f44 (svn r10873) [NewGRF_ports] -Fix: layouts and layout_masks had one level of pointer indirection too much.
rubidium
parents: 6799
diff changeset
  1919
	const byte *mask_ptr;
6729
76133dcea48b (svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents: 6724
diff changeset
  1920
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1921
	if (fsmportsspec->layout_mask != NULL) {
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1922
		mask_ptr = fsmportsspec->layout_mask[layout_set] + 2;  // width*length flagbytes. Also skip plus orientation byte and 'filler' byte
6729
76133dcea48b (svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents: 6724
diff changeset
  1923
	} else {
6799
2adc1052a548 (svn r10871) [NewGRF_ports] -Codechange: do not pay for clearing water tiles when placing watery tile on them anyway.
rubidium
parents: 6793
diff changeset
  1924
		mask_ptr = NULL;
6729
76133dcea48b (svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents: 6724
diff changeset
  1925
	}
76133dcea48b (svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
richk
parents: 6724
diff changeset
  1926
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1927
	BEGIN_TILE_LOOP(tile_cur, w, h, tile)
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1928
		byte layout = *layout_ptr++;
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1929
		if ((byte)layout != (byte)255) {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  1930
			if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1931
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1932
			if (flags & DC_EXEC) {
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1933
				DeleteAnimatedTile(tile_cur);
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1934
				DoClearSquare(tile_cur);
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1935
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1936
				/* It was a water tile */
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1937
				if (mask_ptr != NULL && *mask_ptr & 0x80) MakeWater(tile_cur);
6718
5a8b295aa345 (svn r9511) [NewGRF_ports] -Feature: Added ability to have irregular shaped airports. Use value 255 in airport layout, and that tile is skipped during airport placement & deletion.
richk
parents: 6717
diff changeset
  1938
			}
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1939
		}
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1940
		if (mask_ptr != NULL) mask_ptr++;
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1941
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1942
	END_TILE_LOOP(tile_cur, w,h,tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
	if (flags & DC_EXEC) {
6856
0e8e4ebf23ff (svn r10959) [NewGRF_ports] -Change: Rename FSMState to FSMCommand. nof_elements changed to num_positions. nof_depots changed to num_depots.
richk
parents: 6854
diff changeset
  1945
		for (uint i = 0; i < fsmportsspec->portFSM->num_depots; ++i) {
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1946
			DeleteWindowById(
6863
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
  1947
				WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(fsmportsspec->portFSM->depots[i].tile_pos)
6802
7e514feeb604 (svn r10874) [NewGRF_ports] -Codechange: remove the old airport remnants from the building/destruction commands.
rubidium
parents: 6801
diff changeset
  1948
			);
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1949
		}
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 709
diff changeset
  1950
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1951
		/* Go get the final noise level, that is base noise minus factor from distance to town center.
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1952
		 * And as for construction, always remove it, even if the patch is not set, in order to avoid the
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1953
		 * need of recalculation */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1954
		st->town->noise_reached -= GetAirportNoiseLevelForTown(st->Airport(), st->town->xy, tile);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1955
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1956
		st->rect.AfterRemoveRect(st, tile, w, h);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1957
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1958
		st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1959
		st->facilities &= ~FACIL_AIRPORT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1960
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1961
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1962
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1963
		if (_settings_game.economy.station_noise_level) {
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1964
			InvalidateWindow(WC_TOWN_VIEW, st->town->index);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1965
		}
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1966
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1967
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1968
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
	return cost;
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
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1974
/** Build a buoy.
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: 3482
diff changeset
  1975
 * @param tile tile where to place the bouy
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  1976
 * @param flags operation to perform
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1977
 * @param p1 unused
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1978
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1980
CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  1982
	if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
6632
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  1983
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1984
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1985
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_304B_SITE_UNSUITABLE);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  1986
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1987
	/* allocate and initialize new station */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1988
	if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1989
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1990
	if (flags & DC_EXEC) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1991
		Station *st = new Station(tile);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1992
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1993
		st->town = ClosestTownFromTile(tile, UINT_MAX);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1994
		st->string_id = GenerateStationName(st, tile, STATIONNAMING_BUOY);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1995
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1996
		if (IsValidPlayer(_current_player)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1997
			SetBit(st->town->have_ratings, _current_player);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1998
		}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  1999
		st->sign.width_1 = 0;
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
  2000
		st->dock_tile = tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2001
		st->facilities |= FACIL_DOCK;
1751
954dd2900ac9 (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  2002
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
954dd2900ac9 (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  2003
		 * braindead.. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
		st->had_vehicle_of_type |= HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
		st->owner = OWNER_NONE;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2006
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  2007
		st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2008
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2009
		MakeBuoy(tile, st->index, GetWaterClass(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2010
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2012
		UpdateStationAcceptance(st, false);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2013
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2014
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2017
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2019
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2020
/**
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2021
 * Tests whether the player's vehicles have this station in orders
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2022
 * When player == INVALID_PLAYER, then check all vehicles
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2023
 * @param station station ID
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2024
 * @param player player ID, INVALID_PLAYER to disable the check
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2025
 */
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2026
bool HasStationInUse(StationID station, PlayerID player)
1078
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2027
{
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2028
	const Vehicle *v;
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2029
	FOR_ALL_VEHICLES(v) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2030
		if (player == INVALID_PLAYER || v->owner == player) {
1078
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2031
			const Order *order;
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2032
			FOR_VEHICLE_ORDERS(v, order) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2033
				if (order->IsType(OT_GOTO_STATION) && order->GetDestination() == station) {
1078
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2034
					return true;
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2035
				}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2036
			}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2037
		}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2038
	}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2039
	return false;
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2040
}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2041
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2042
static CommandCost RemoveBuoy(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
{
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  2044
	/* XXX: strange stuff */
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2045
	if (!IsValidPlayer(_current_player)) return_cmd_error(INVALID_STRING_ID);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2046
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2047
	TileIndex tile = st->dock_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2049
	if (HasStationInUse(st->index, INVALID_PLAYER)) return_cmd_error(STR_BUOY_IS_IN_USE);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2050
	/* remove the buoy if there is a ship on tile when company goes bankrupt... */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2051
	if (!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
		st->dock_tile = 0;
1751
954dd2900ac9 (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  2055
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
954dd2900ac9 (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  2056
		 * braindead.. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2057
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2058
		st->had_vehicle_of_type &= ~HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2060
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2061
6204
c237d8081b58 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 6165
diff changeset
  2062
		/* We have to set the water tile's state to the same state as before the
c237d8081b58 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 6165
diff changeset
  2063
		 * buoy was placed. Otherwise one could plant a buoy on a canal edge,
c237d8081b58 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 6165
diff changeset
  2064
		 * remove it and flood the land (if the canal edge is at level 0) */
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2065
		MakeWaterKeepingClass(tile, GetTileOwner(tile));
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  2066
		MarkTileDirtyByTile(tile);
0
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
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2069
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2070
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2071
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2072
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_truck_station);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2073
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2074
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2075
static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2076
	{-1,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2077
	{ 0,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2078
	{ 0,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2079
	{ 0, -1}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
};
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: 4326
diff changeset
  2081
static const byte _dock_w_chk[4] = { 2, 1, 2, 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: 4326
diff changeset
  2082
static const byte _dock_h_chk[4] = { 1, 2, 1, 2 };
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2083
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2084
/** Build a dock/haven.
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: 3482
diff changeset
  2085
 * @param tile tile where dock will be built
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2086
 * @param flags operation to perform
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2087
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2088
 * @param p2 unused
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2089
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2090
CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
{
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2092
	DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2093
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2094
	direction = ReverseDiagDir(direction);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2095
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2096
	/* Docks cannot be placed on rapids */
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2097
	if (IsWaterTile(tile)) return_cmd_error(STR_304B_SITE_UNSUITABLE);
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
  2098
4619
fc11bc6a7fe7 (svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents: 4559
diff changeset
  2099
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
fc11bc6a7fe7 (svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents: 4559
diff changeset
  2100
6632
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  2101
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  2102
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2103
	if (CmdFailed(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2105
	TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2107
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
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
  2108
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
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
  2109
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
6632
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  2111
	if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  2112
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2113
	/* Get the water class of the water tile before it is cleared.*/
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2114
	WaterClass wc = GetWaterClass(tile_cur);
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2115
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2116
	if (CmdFailed(DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  2118
	tile_cur += TileOffsByDiagDir(direction);
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2119
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
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
  2121
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2122
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
	/* middle */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2124
	Station *st = NULL;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2125
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2126
	if (!_settings_game.station.adjacent_stations || !HasBit(p1, 0)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2127
		st = GetStationAround(
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2128
				tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2129
				_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2130
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2131
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2132
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2133
	/* Find a station close to us */
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
  2134
	if (st == NULL) st = GetClosestStationFromTile(tile);
0
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
	if (st != NULL) {
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2137
		if (st->owner != _current_player) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2138
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2139
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2140
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  2141
		if (!st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2142
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2143
		if (st->dock_tile != 0) return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
	} else {
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2145
		/* allocate and initialize new station */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2146
		/* allocate and initialize new station */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2147
		if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2148
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2149
		if (flags & DC_EXEC) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2150
			st = new Station(tile);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2151
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2152
			st->town = ClosestTownFromTile(tile, UINT_MAX);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2153
			st->string_id = GenerateStationName(st, tile, STATIONNAMING_DOCK);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2154
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2155
			if (IsValidPlayer(_current_player)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2156
				SetBit(st->town->have_ratings, _current_player);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2157
			}
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2158
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
	}
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
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
		st->dock_tile = tile;
5972
564f98b055d1 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5969
diff changeset
  2163
		st->AddFacility(FACIL_DOCK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2164
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  2165
		st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  2166
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2167
		MakeDock(tile, st->owner, st->index, direction, wc);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2168
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2170
		UpdateStationAcceptance(st, false);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2171
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2172
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
	}
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2174
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2175
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
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
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2178
static CommandCost RemoveDock(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2179
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2180
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2181
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2182
	TileIndex tile1 = st->dock_tile;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2183
	TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2184
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2185
	if (!EnsureNoVehicleOnGround(tile1)) return CMD_ERROR;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2186
	if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2188
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2189
		DoClearSquare(tile1);
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2190
		MakeWaterKeepingClass(tile2, st->owner);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  2191
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  2192
		st->rect.AfterRemoveTile(st, tile1);
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  2193
		st->rect.AfterRemoveTile(st, tile2);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  2194
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  2195
		MarkTileDirtyByTile(tile2);
0
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
		st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2199
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2200
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2201
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2202
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2203
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2204
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2205
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_dock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2206
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2207
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2208
#include "table/station_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2209
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2210
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx)
3763
460bbb4a8154 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3754
diff changeset
  2211
{
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2212
	return &_station_display_datas[st][gfx];
3763
460bbb4a8154 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3754
diff changeset
  2213
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2214
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2215
static void DrawTile_Station(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2216
{
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2217
	const DrawTileSprites *t = NULL;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2218
	RoadTypes roadtypes;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2219
	int32 total_offset;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2220
	int32 custom_ground_offset;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2221
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2222
	if (IsRailwayStation(ti->tile)) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2223
		const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2224
		roadtypes = ROADTYPES_NONE;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2225
		total_offset = rti->total_offset;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2226
		custom_ground_offset = rti->custom_ground_offset;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2227
	} else {
6877
889301acc299 (svn r12053) [NewGRF_ports] -Sync: with trunk r11949:12050.
rubidium
parents: 6872
diff changeset
  2228
		roadtypes = IsRoadStop(ti->tile) ? GetRoadTypes(ti->tile) : ROADTYPES_NONE;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2229
		total_offset = 0;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2230
		custom_ground_offset = 0;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2231
	}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2232
	uint32 relocation = 0;
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2233
	const Station *st = NULL;
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2234
	const StationSpec *statspec = NULL;
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2235
	const FSMportsSpec *fsmportspec = NULL;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2236
	bool FSMport = false;
4227
55651eaaedb5 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  2237
	PlayerID owner = GetTileOwner(ti->tile);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2238
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5918
diff changeset
  2239
	SpriteID palette;
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  2240
	if (IsValidPlayer(owner)) {
4227
55651eaaedb5 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  2241
		palette = PLAYER_SPRITE_COLOR(owner);
55651eaaedb5 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  2242
	} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2243
		/* Some stations are not owner by a player, namely oil rigs */
4227
55651eaaedb5 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  2244
		palette = PALETTE_TO_GREY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2245
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2246
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2247
	/* don't show foundation for docks */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2248
	if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile))
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  2249
		DrawFoundation(ti, FOUNDATION_LEVELED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2250
3568
c1abc31df35b (svn r4450) - NewStations, rename *CustomStationSprite() to *CustomStationSpecIndex() to reflect their use, and alter the test for determining if a station has customised graphics.
peter1138
parents: 3554
diff changeset
  2251
	if (IsCustomStationSpecIndex(ti->tile)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2252
		/* look for customization */
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2253
		st = GetStationByTile(ti->tile);
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2254
		int specindex = GetCustomStationSpecIndex(ti->tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2255
		FSMport = IsCustomFSMportsSpecIndex(ti->tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2256
		if (FSMport) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2257
			fsmportspec = st->fsmportsspeclist[specindex].spec;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2258
		} else {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2259
			statspec = st->speclist[specindex].spec;
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2260
		}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2261
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2262
		if (statspec != NULL) {
3576
007e6b163bf5 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2263
			uint tile = GetStationGfx(ti->tile);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2264
3751
785501c18d0d (svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents: 3742
diff changeset
  2265
			relocation = GetCustomStationRelocation(statspec, st, ti->tile);
3576
007e6b163bf5 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2266
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2267
			if (HasBit(statspec->callbackmask, CBM_STATION_SPRITE_LAYOUT)) {
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2268
				uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
4886
d89110a382ae (svn r6823) - Codechange: Ignore bit 0 of a NewStation custom tile callback result. This fixes cosmetic problems with some add on stations.
peter1138
parents: 4873
diff changeset
  2269
				if (callback != CALLBACK_FAILED) tile = (callback & ~1) + GetRailStationAxis(ti->tile);
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2270
			}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2271
3576
007e6b163bf5 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2272
			/* Ensure the chosen tile layout is valid for this custom station */
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2273
			if (statspec->renderdata != NULL) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2274
				t = &statspec->renderdata[tile < statspec->tiles ? tile : (uint)GetRailStationAxis(ti->tile)];
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2275
			}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2276
		}
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2277
		if (fsmportspec != NULL) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2278
			uint tile = GetStationGfx(ti->tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2279
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2280
			relocation = GetCustomFSMportsRelocation(fsmportspec, st, ti->tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2281
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2282
			//if (HASBIT(fsmportspec->callbackmask, CBM_CUSTOM_LAYOUT)) {
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2283
			//	uint16 callback = GetFSMportsCallback(CBID_FSMPORTS_SPRITE_LAYOUT, 0, 0, fsmportspec, st, ti->tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2284
			//	if (callback != CALLBACK_FAILED) tile = (callback & ~1) + GetRailStationAxis(ti->tile);
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2285
			//}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2286
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2287
			/* Ensure the chosen tile layout is valid for this custom station */
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2288
			if (fsmportspec->renderdata != NULL) {
6773
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2289
				t = &fsmportspec->renderdata[tile < fsmportspec->tiles ? tile : 0];
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2290
			}
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2291
		}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2292
	}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2293
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2294
	if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationType(ti->tile)][GetStationGfx(ti->tile)];
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2295
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2296
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2297
	if (IsBuoy(ti->tile) || IsDock(ti->tile)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2298
		if (ti->tileh == SLOPE_FLAT) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2299
			DrawWaterClassGround(ti);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2300
		} else {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2301
			assert(IsDock(ti->tile));
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2302
			TileIndex water_tile = ti->tile + TileOffsByDiagDir(GetDockDirection(ti->tile));
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2303
			WaterClass wc = GetWaterClass(water_tile);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2304
			if (wc == WATER_CLASS_SEA) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2305
				DrawShoreTile(ti->tileh);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2306
			} else {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2307
				DrawClearLandTile(ti, 3);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2308
			}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2309
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2310
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2311
	SpriteID image = t->ground.sprite;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2312
	if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
6722
72f280229ee1 (svn r10586) [NewGRF_ports] -Feature: Load an airport via a newgrf file. Currently, only graphics support provided.
richk
parents: 6720
diff changeset
  2313
		image += (FSMport)? GetCustomFSMportsGroundRelocation(fsmportspec, st, ti->tile) : GetCustomStationGroundRelocation(statspec, st, ti->tile);
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2314
		image += custom_ground_offset;
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2315
	} else {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2316
		SpriteID image = t->ground.sprite;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2317
		if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2318
			image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2319
			image += custom_ground_offset;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2320
		} else {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2321
			image += total_offset;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2322
		}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2323
		DrawGroundSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE);
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2324
	}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2325
6867
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  2326
	// if ground tile 0x0F8D, but tile is desert/snow, then choose desert/snow graphic
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  2327
	if ((image == 0x0F8D) && (GetTropicZone(ti->tile) == TROPICZONE_DESERT))
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  2328
		image = 0x11C6;  // snow tile (arctic) or desert tile (tropical)
a4ad48192617 (svn r10990) [NewGRF_ports] -Feature: If ground tile 0x0F8D is used in an airport tileseq, the correct snow/desert tile is displayed.
richk
parents: 6863
diff changeset
  2329
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2330
	/* station_land array has been increased from 82 elements to 114
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2331
	 * but this is something else. If AI builds station with 114 it looks all weird */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2332
	DrawGroundSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2333
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2334
	if (IsRailwayStation(ti->tile) && HasCatenaryDrawn(GetRailType(ti->tile)) && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
3355
a653b8e47f27 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3344
diff changeset
  2335
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2336
	if (HasBit(roadtypes, ROADTYPE_TRAM)) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2337
		Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2338
		DrawGroundSprite((HasBit(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2339
		DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2340
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2341
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2342
	/* End now if buildings are invisible */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2343
	if (IsInvisibilitySet(TO_BUILDINGS)) return;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2344
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2345
	const DrawTileSeqStruct *dtss;
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2346
	foreach_draw_tile_seq(dtss, t->seq) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2347
		SpriteID image = dtss->image.sprite;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2348
		if (relocation == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2349
			image += total_offset;
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2350
		} else {
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2351
			image += relocation;
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2352
		}
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2353
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2354
		SpriteID pal;
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2355
		if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOR)) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2356
			if (dtss->image.pal > 0) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2357
				pal = dtss->image.pal;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2358
			} else {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2359
				pal = palette;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2360
			}
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5918
diff changeset
  2361
		} else {
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2362
			pal = PAL_NONE;
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2363
		}
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2364
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2365
		if ((byte)dtss->delta_z != 0x80) {
4230
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2366
			AddSortableSpriteToDraw(
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5918
diff changeset
  2367
				image, pal,
4230
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2368
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2369
				dtss->size_x, dtss->size_y,
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  2370
				dtss->size_z, ti->z + dtss->delta_z,
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2371
				!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)
4230
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2372
			);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2373
		} else {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2374
			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, IsTransparencySet(TO_BUILDINGS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2375
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2376
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2377
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2378
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2379
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2380
{
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2381
	int32 total_offset = 0;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2382
	SpriteID pal = PLAYER_SPRITE_COLOR(_local_player);
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2383
	const DrawTileSprites *t = &_station_display_datas[st][image];
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2384
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2385
	if (railtype != INVALID_RAILTYPE) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2386
		const RailtypeInfo *rti = GetRailTypeInfo(railtype);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2387
		total_offset = rti->total_offset;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2388
	}
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2389
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2390
	SpriteID img = t->ground.sprite;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2391
	DrawSprite(img + total_offset, HasBit(img, PALETTE_MODIFIER_COLOR) ? pal : PAL_NONE, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2392
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2393
	if (roadtype == ROADTYPE_TRAM) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2394
		DrawSprite(SPR_TRAMWAY_TRAM + (t->ground.sprite == SPR_ROAD_PAVED_STRAIGHT_X ? 1 : 0), PAL_NONE, x, y);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2395
	}
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2396
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2397
	const DrawTileSeqStruct *dtss;
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2398
	foreach_draw_tile_seq(dtss, t->seq) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2399
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2400
		DrawSprite(dtss->image.sprite + total_offset, pal, x + pt.x, y + pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2401
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2402
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2403
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2404
static uint GetSlopeZ_Station(TileIndex tile, uint x, uint y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2405
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2406
	return GetTileMaxZ(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2407
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2408
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  2409
static Foundation GetFoundation_Station(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2410
{
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  2411
	return FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2412
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2413
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2414
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2415
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2416
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2417
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2418
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2419
static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2420
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2421
	td->owner[0] = GetTileOwner(tile);
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2422
	if (IsDriveThroughStopTile(tile) && HasTileRoadType(tile, ROADTYPE_ROAD) && GetStopBuiltOnTownRoad(tile)) {
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2423
		/* Display a second owner */
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2424
		td->owner_type[1] = STR_ROAD_OWNER;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2425
		td->owner[1] = OWNER_TOWN;
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2426
	}
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2427
	td->build_date = GetStationByTile(tile)->build_date;
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  2428
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2429
	StringID str;
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2430
	switch (GetStationType(tile)) {
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2431
		default: NOT_REACHED();
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2432
		case STATION_RAIL:    str = STR_305E_RAILROAD_STATION; break;
3882
86380e989bad (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2433
		case STATION_AIRPORT:
86380e989bad (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2434
			str = (IsHangar(tile) ? STR_305F_AIRCRAFT_HANGAR : STR_3060_AIRPORT);
86380e989bad (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2435
			break;
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2436
		case STATION_TRUCK:   str = STR_3061_TRUCK_LOADING_AREA; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2437
		case STATION_BUS:     str = STR_3062_BUS_STATION; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2438
		case STATION_OILRIG:  str = STR_4807_OIL_RIG; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2439
		case STATION_DOCK:    str = STR_3063_SHIP_DOCK; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2440
		case STATION_BUOY:    str = STR_3069_BUOY; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2441
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2442
	td->str = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2443
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2444
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2445
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2446
static TrackStatus GetTileTrackStatus_Station(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2447
{
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2448
	TrackBits trackbits = TRACK_BIT_NONE;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2449
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2450
	switch (mode) {
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2451
		case TRANSPORT_RAIL:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2452
			if (IsRailwayStation(tile) && !IsStationTileBlocked(tile)) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2453
				trackbits = TrackToTrackBits(GetRailStationTrack(tile));
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2454
			}
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2455
			break;
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2456
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2457
		case TRANSPORT_WATER:
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2458
			/* buoy is coded as a station, it is always on open water */
6165
4da5ead702ad (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 6164
diff changeset
  2459
			if (IsBuoy(tile)) {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2460
				trackbits = TRACK_BIT_ALL;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2461
				/* remove tracks that connect NE map edge */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2462
				if (TileX(tile) == 0) trackbits &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2463
				/* remove tracks that connect NW map edge */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2464
				if (TileY(tile) == 0) trackbits &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
6165
4da5ead702ad (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 6164
diff changeset
  2465
			}
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2466
			break;
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2467
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2468
		case TRANSPORT_ROAD:
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2469
			if ((GetRoadTypes(tile) & sub_mode) != 0 && IsRoadStop(tile)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2470
				DiagDirection dir = GetRoadStopDir(tile);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2471
				Axis axis = DiagDirToAxis(dir);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2472
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2473
				if (side != INVALID_DIAGDIR) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2474
					if (axis != DiagDirToAxis(side) || (IsStandardRoadStopTile(tile) && dir != side)) break;
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2475
				}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2476
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2477
				trackbits = AxisToTrackBits(axis);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2478
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2479
			break;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2480
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2481
		default:
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2482
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2483
	}
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2484
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2485
	return CombineTrackStatus(TrackBitsToTrackdirBits(trackbits), TRACKDIR_BIT_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2486
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2487
2660
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2488
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2489
static void TileLoop_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2490
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2491
	/* FIXME -- GetTileTrackStatus_Station -> animated stationtiles
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2492
	 * hardcoded.....not good */
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2493
	switch (GetStationType(tile)) {
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2494
		case STATION_AIRPORT:
6773
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2495
			//TODO: animated tiles from newgrf
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2496
			//switch (GetStationGfx(tile)) {
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2497
			//	case GFX_RADAR_LARGE_FIRST:
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2498
			//	case GFX_WINDSACK_FIRST : // for small airport
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2499
			//	case GFX_RADAR_INTERNATIONAL_FIRST:
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2500
			//	case GFX_RADAR_METROPOLITAN_FIRST:
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2501
			//	case GFX_RADAR_DISTRICTWE_FIRST: // radar district W-E airport
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2502
			//	case GFX_WINDSACK_INTERCON_FIRST : // for intercontinental airport
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2503
			//		AddAnimatedTile(tile);
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2504
			//		break;
1561fc957d15 (svn r10829) [NewGRF_ports] -Change: Animation was causing failures if the tile happened to be one of the hardcoded animated tiles. For the moment, comment out. Will be replaced with newgrf animation.
richk
parents: 6772
diff changeset
  2505
			//}
2660
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2506
			break;
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2507
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2508
		case STATION_DOCK:
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2509
			if (GetTileSlope(tile, NULL) != SLOPE_FLAT) break; // only handle water part
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2510
		/* FALL THROUGH */
6730
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2511
		case STATION_OILRIG: //(station part)
f09255ea0123 (svn r10602) [NewGRF_ports] -Sync: with trunk r10593:10601.
rubidium
parents: 6729
diff changeset
  2512
		case STATION_BUOY:
2660
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2513
			TileLoop_Water(tile);
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2514
			break;
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2515
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2516
		default: break;
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2517
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2518
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2519
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2520
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2521
static void AnimateTile_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2522
{
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
  2523
	struct AnimData {
4467
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2524
		StationGfx from; // first sprite
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2525
		StationGfx to;   // last sprite
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2526
		byte delay;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
  2527
	};
4467
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2528
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2529
	static const AnimData data[] = {
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2530
		{ GFX_RADAR_LARGE_FIRST,         GFX_RADAR_LARGE_LAST,         3 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2531
		{ GFX_WINDSACK_FIRST,            GFX_WINDSACK_LAST,            1 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2532
		{ GFX_RADAR_INTERNATIONAL_FIRST, GFX_RADAR_INTERNATIONAL_LAST, 3 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2533
		{ GFX_RADAR_METROPOLITAN_FIRST,  GFX_RADAR_METROPOLITAN_LAST,  3 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2534
		{ GFX_RADAR_DISTRICTWE_FIRST,    GFX_RADAR_DISTRICTWE_LAST,    3 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2535
		{ GFX_WINDSACK_INTERCON_FIRST,   GFX_WINDSACK_INTERCON_LAST,   1 }
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2536
	};
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2537
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2538
	if (IsRailwayStation(tile)) {
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2539
		AnimateStationTile(tile);
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2540
		return;
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2541
	}
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2542
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2543
	StationGfx gfx = GetStationGfx(tile);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2544
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2545
	for (const AnimData *i = data; i != endof(data); i++) {
4467
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2546
		if (i->from <= gfx && gfx <= i->to) {
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2547
			if ((_tick_counter & i->delay) == 0) {
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2548
				SetStationGfx(tile, gfx < i->to ? gfx + 1 : i->from);
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2549
				MarkTileDirtyByTile(tile);
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2550
			}
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2551
			break;
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2552
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2553
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2554
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2555
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  2556
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2557
static void ClickTile_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2558
{
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2559
	if (IsHangar(tile)) {
6863
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
  2560
		//find the main tile for this depot
13335bf10adb (svn r10977) [NewGRF_ports] -Feature: Added multi-tile depot support.
richk
parents: 6856
diff changeset
  2561
		ShowDepotWindow(GetKeyDepotTile(tile), VEH_AIRCRAFT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2562
	} else {
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2563
		ShowStationViewWindow(GetStationIndex(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2564
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2565
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2566
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2567
static const byte _enter_station_speedtable[12] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2568
	215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2569
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2570
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2571
static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2572
{
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2573
	StationID station_id = GetStationIndex(tile);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2574
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  2575
	if (v->type == VEH_TRAIN) {
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2576
		if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2577
		if (IsRailwayStation(tile) && IsFrontEngine(v) &&
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  2578
				!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2579
			DiagDirection dir = DirToDiagDir(v->direction);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2580
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2581
			x &= 0xF;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2582
			y &= 0xF;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2583
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2584
			if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2585
			if (y == TILE_SIZE / 2) {
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2586
				if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2587
				if (x == 12) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); /* enter station */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2588
				if (x < 12) {
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2589
					uint16 spd;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2590
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2591
					v->vehstatus |= VS_TRAIN_SLOWING;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2592
					spd = _enter_station_speedtable[x];
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2593
					if (spd < v->cur_speed) v->cur_speed = spd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2594
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2595
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2596
		}
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  2597
	} else if (v->type == VEH_ROAD) {
6402
d8d29aef051f (svn r8809) -Fix (r8715): accidentally removed a part of an expression.
rubidium
parents: 6396
diff changeset
  2598
		if (v->u.road.state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)v->u.road.state) && v->u.road.frame == 0) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2599
			if (IsRoadStop(tile) && IsRoadVehFront(v)) {
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2600
				/* Attempt to allocate a parking bay in a road stop */
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2601
				RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2602
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2603
				if (IsDriveThroughStopTile(tile)) {
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2604
					if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  2605
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2606
					/* Vehicles entering a drive-through stop from the 'normal' side use first bay (bay 0). */
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2607
					byte side = ((DirToDiagDir(v->direction) == ReverseDiagDir(GetRoadStopDir(tile))) == (v->u.road.overtaking == 0)) ? 0 : 1;
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2608
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2609
					if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER;
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2610
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2611
					/* Check if the vehicle is stopping at this road stop */
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2612
					if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2613
							v->current_order.GetDestination() == GetStationIndex(tile)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2614
						SetBit(v->u.road.state, RVS_IS_STOPPING);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2615
						rs->AllocateDriveThroughBay(side);
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2616
					}
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2617
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2618
					/* Indicate if vehicle is using second bay. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2619
					if (side == 1) SetBit(v->u.road.state, RVS_USING_SECOND_BAY);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2620
					/* Indicate a drive-through stop */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2621
					SetBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2622
					return VETSB_CONTINUE;
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2623
				}
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2624
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2625
				/* For normal (non drive-through) road stops */
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  2626
				/* Check if station is busy or if there are no free bays or whether it is a articulated vehicle. */
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  2627
				if (rs->IsEntranceBusy() || !rs->HasFreeBay() || RoadVehHasArticPart(v)) return VETSB_CANNOT_ENTER;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2628
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2629
				SetBit(v->u.road.state, RVS_IN_ROAD_STOP);
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2630
6316
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2631
				/* Allocate a bay and update the road state */
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2632
				uint bay_nr = rs->AllocateBay();
6326
c904c7ea1c8d (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 6324
diff changeset
  2633
				SB(v->u.road.state, RVS_USING_SECOND_BAY, 1, bay_nr);
6316
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2634
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2635
				/* Mark the station entrace as busy */
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2636
				rs->SetEntranceBusy(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2637
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2638
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2639
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2640
6317
c73bda71ac16 (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 6316
diff changeset
  2641
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2642
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2644
/* this function is called for one station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2645
static void StationHandleBigTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2646
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2647
	UpdateStationAcceptance(st, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2648
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2649
	if (st->facilities == 0 && ++st->delete_ctr >= 8) delete st;
1239
6e61c510580e (svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents: 1231
diff changeset
  2650
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2651
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2652
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2653
static inline void byte_inc_sat(byte *p)
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2654
{
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2655
	byte b = *p + 1;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2656
	if (b != 0) *p = b;
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2657
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2658
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2659
static void UpdateStationRating(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2660
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2661
	bool waiting_changed = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2662
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2663
	byte_inc_sat(&st->time_since_load);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2664
	byte_inc_sat(&st->time_since_unload);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2665
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2666
	GoodsEntry *ge = st->goods;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2667
	do {
6587
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2668
		/* Slowly increase the rating back to his original level in the case we
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2669
		 *  didn't deliver cargo yet to this station. This happens when a bribe
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2670
		 *  failed while you didn't moved that cargo yet to a station. */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2671
		if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP) && ge->rating < INITIAL_STATION_RATING) {
6587
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2672
			ge->rating++;
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  2673
		}
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  2674
6587
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2675
		/* Only change the rating if we are moving this cargo */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2676
		if (HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2677
			byte_inc_sat(&ge->days_since_pickup);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2678
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2679
			int rating = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2680
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2681
			{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2682
				int b = ge->last_speed - 85;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  2683
				if (b >= 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2684
					rating += b >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2685
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2686
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2687
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2688
				byte age = ge->last_age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2689
				(age >= 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2690
				(rating += 10, age >= 2) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2691
				(rating += 10, age >= 1) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2692
				(rating += 13, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2693
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2694
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2695
			if (IsValidPlayer(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2696
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2697
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2698
				byte days = ge->days_since_pickup;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2699
				if (st->last_vehicle_type == VEH_SHIP) days >>= 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2700
				(days > 21) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2701
				(rating += 25, days > 12) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2702
				(rating += 25, days > 6) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2703
				(rating += 45, days > 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2704
				(rating += 35, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2705
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2706
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2707
			uint waiting = ge->cargo.Count();
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2708
			(rating -= 90, waiting > 1500) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2709
			(rating += 55, waiting > 1000) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2710
			(rating += 35, waiting > 600) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2711
			(rating += 10, waiting > 300) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2712
			(rating += 20, waiting > 100) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2713
			(rating += 10, true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2714
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2715
			{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2716
				int or_ = ge->rating; // old rating
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2717
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2718
				/* only modify rating in steps of -2, -1, 0, 1 or 2 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2719
				ge->rating = rating = or_ + Clamp(Clamp(rating, 0, 255) - or_, -2, 2);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2720
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2721
				/* if rating is <= 64 and more than 200 items waiting,
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2722
				 * remove some random amount of goods from the station */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2723
				if (rating <= 64 && waiting >= 200) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2724
					int dec = Random() & 0x1F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2725
					if (waiting < 400) dec &= 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2726
					waiting -= dec + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2727
					waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2728
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2729
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2730
				/* if rating is <= 127 and there are any items waiting, maybe remove some goods. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2731
				if (rating <= 127 && waiting != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2732
					uint32 r = Random();
5911
bb8088c97103 (svn r8120) -Fix (r8055): Station cargo waiting value clamp should be signed not unsigned. This resulted in cargo magically appearing...
peter1138
parents: 5860
diff changeset
  2733
					if (rating <= (int)GB(r, 0, 7)) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2734
						/* Need to have int, otherwise it will just overflow etc. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2735
						waiting = max((int)waiting - (int)GB(r, 8, 2) - 1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2736
						waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2737
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2738
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2739
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2740
				/* At some point we really must cap the cargo. Previously this
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2741
				 * was a strict 4095, but now we'll have a less strict, but
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2742
				 * increasingly agressive truncation of the amount of cargo. */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2743
				static const uint WAITING_CARGO_THRESHOLD  = 1 << 12;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2744
				static const uint WAITING_CARGO_CUT_FACTOR = 1 <<  6;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2745
				static const uint MAX_WAITING_CARGO        = 1 << 15;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2746
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2747
				if (waiting > WAITING_CARGO_THRESHOLD) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2748
					uint difference = waiting - WAITING_CARGO_THRESHOLD;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2749
					waiting -= (difference / WAITING_CARGO_CUT_FACTOR);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2750
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2751
					waiting = min(waiting, MAX_WAITING_CARGO);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2752
					waiting_changed = true;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2753
				}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2754
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2755
				if (waiting_changed) ge->cargo.Truncate(waiting);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2756
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2757
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2758
	} while (++ge != endof(st->goods));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2759
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2760
	StationID index = st->index;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2761
	if (waiting_changed) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2762
		InvalidateWindow(WC_STATION_VIEW, index); // update whole window
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2763
	} else {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2764
		InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_RATINGLIST); // update only ratings list
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2765
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2766
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2767
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2768
/* called for every station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2769
static void StationHandleSmallTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2770
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2771
	if (st->facilities == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2772
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2773
	byte b = st->delete_ctr + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2774
	if (b >= 185) b = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2775
	st->delete_ctr = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2776
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2777
	if (b == 0) UpdateStationRating(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2778
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2779
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  2780
void OnTick_Station()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2781
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2782
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2783
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2784
	uint i = _station_tick_ctr;
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5220
diff changeset
  2785
	if (++_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2786
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2787
	if (IsValidStationID(i)) StationHandleBigTick(GetStation(i));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2788
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2789
	Station *st;
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2790
	FOR_ALL_STATIONS(st) {
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2791
		StationHandleSmallTick(st);
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2792
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2793
		/* Run 250 tick interval trigger for station animation.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2794
		 * Station index is included so that triggers are not all done
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2795
		 * at the same time. */
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2796
		if ((_tick_counter + st->index) % 250 == 0) {
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2797
			StationAnimationTrigger(st, st->xy, STAT_ANIM_250_TICKS);
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2798
		}
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2799
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2800
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2801
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  2802
void StationMonthlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2803
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2804
	/* not used */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2805
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2806
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2807
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
  2808
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2809
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2810
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2811
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2812
	FOR_ALL_STATIONS(st) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2813
		if (st->owner == owner &&
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1239
diff changeset
  2814
				DistanceManhattan(tile, st->xy) <= radius) {
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
  2815
			for (CargoID i = 0; i < NUM_CARGO; i++) {
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2816
				GoodsEntry *ge = &st->goods[i];
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2817
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  2818
				if (ge->acceptance_pickup != 0) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2819
					ge->rating = Clamp(ge->rating + amount, 0, 255);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2820
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2821
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2822
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2823
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2824
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2825
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
  2826
static void UpdateStationWaiting(Station *st, CargoID type, uint amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2827
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2828
	st->goods[type].cargo.Append(new CargoPacket(st->index, amount));
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2829
	SetBit(st->goods[type].acceptance_pickup, GoodsEntry::PICKUP);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2830
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2831
	StationAnimationTrigger(st, st->xy, STAT_ANIM_NEW_CARGO, type);
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2832
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2833
	InvalidateWindow(WC_STATION_VIEW, st->index);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2834
	st->MarkTilesDirty(true);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2835
}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2836
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2837
static bool IsUniqueStationName(const char *name)
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2838
{
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2839
	const Station *st;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2840
	char buf[512];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2841
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2842
	FOR_ALL_STATIONS(st) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2843
		SetDParam(0, st->index);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2844
		GetString(buf, STR_STATION, lastof(buf));
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2845
		if (strcmp(buf, name) == 0) return false;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2846
	}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2847
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2848
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2849
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2850
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2851
/** Rename a station
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: 3482
diff changeset
  2852
 * @param tile unused
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  2853
 * @param flags operation to perform
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2854
 * @param p1 station ID that is to be renamed
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2855
 * @param p2 unused
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2856
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2857
CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2858
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2859
	if (!IsValidStationID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2860
	Station *st = GetStation(p1);
1774
0fc4a31265c2 (svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents: 1751
diff changeset
  2861
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2862
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
1774
0fc4a31265c2 (svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents: 1751
diff changeset
  2863
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2864
	if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2865
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2866
	if (flags & DC_EXEC) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2867
		free(st->name);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2868
		st->name = strdup(_cmd_text);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2869
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2870
		UpdateStationVirtCoord(st);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  2871
		InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2872
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2873
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2874
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  2875
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2876
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2877
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2878
/**
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2879
 * Find all (non-buoy) stations around an industry tile
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2880
 *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2881
 * @param tile: Center tile to search from
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2882
 * @param w: Width of the center
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2883
 * @param h: Height of the center
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2884
 *
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2885
 * @return: Set of found stations
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2886
 */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2887
StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2888
{
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2889
	StationSet station_set;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2890
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2891
	int w_prod; // width and height of the "producer" of the cargo
3000
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2892
	int h_prod;
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2893
	int max_rad;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2894
	if (_settings_game.station.modified_catchment) {
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2895
		w_prod = w;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2896
		h_prod = h;
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  2897
		w += 2 * MAX_CATCHMENT;
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  2898
		h += 2 * MAX_CATCHMENT;
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  2899
		max_rad = MAX_CATCHMENT;
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2900
	} else {
3000
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2901
		w_prod = 0;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2902
		h_prod = 0;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2903
		w += 8;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2904
		h += 8;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  2905
		max_rad = CA_UNMODIFIED;
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2906
	}
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2907
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  2908
	BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2909
		cur_tile = TILE_MASK(cur_tile);
3000
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2910
		if (!IsTileType(cur_tile, MP_STATION)) continue;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2911
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2912
		Station *st = GetStationByTile(cur_tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2913
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2914
		if (st->IsBuoy()) continue; // bouys don't accept cargo
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2915
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2916
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2917
		if (_settings_game.station.modified_catchment) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2918
			/* min and max coordinates of the producer relative */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2919
			const int x_min_prod = max_rad + 1;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2920
			const int x_max_prod = max_rad + w_prod;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2921
			const int y_min_prod = max_rad + 1;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2922
			const int y_max_prod = max_rad + h_prod;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2923
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2924
			int rad = FindCatchmentRadius(st);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2925
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2926
			int x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2927
			if (w_cur < x_min_prod) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2928
				x_dist = x_min_prod - w_cur;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2929
			} else if (w_cur > x_max_prod) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2930
				x_dist = w_cur - x_max_prod;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2931
			}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2932
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2933
			if (x_dist > rad) continue;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2934
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2935
			int y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2936
			if (h_cur < y_min_prod) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2937
				y_dist = y_min_prod - h_cur;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2938
			} else if (h_cur > y_max_prod) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2939
				y_dist = h_cur - y_max_prod;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2940
			}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2941
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2942
			if (y_dist > rad) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2943
		}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2944
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2945
		/* Insert the station in the set. This will fail if it has
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2946
		 * already been added.
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2947
		 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2948
		station_set.insert(st);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2949
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  2950
	END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2951
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2952
	return station_set;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2953
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2954
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2955
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2956
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2957
	Station *st1 = NULL;   // Station with best rating
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2958
	Station *st2 = NULL;   // Second best station
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2959
	uint best_rating1 = 0; // rating of st1
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  2960
	uint best_rating2 = 0; // rating of st2
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2961
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2962
	StationSet all_stations = FindStationsAroundIndustryTile(tile, w, h);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2963
	for (StationSet::iterator st_iter = all_stations.begin(); st_iter != all_stations.end(); ++st_iter) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2964
		Station *st = *st_iter;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2965
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2966
		/* Is the station reserved exclusively for somebody else? */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2967
		if (st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2968
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2969
		if (st->goods[type].rating == 0) continue; // Lowest possible rating, better not to give cargo anymore
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2970
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2971
		if (_settings_game.order.selectgoods && st->goods[type].last_speed == 0) continue; // Selectively servicing stations, and not this one
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2972
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2973
		if (IsCargoInClass(type, CC_PASSENGERS)) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2974
			if (st->facilities == FACIL_TRUCK_STOP) continue; // passengers are never served by just a truck stop
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2975
		} else {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2976
			if (st->facilities == FACIL_BUS_STOP) continue; // non-passengers are never served by just a bus stop
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2977
		}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2978
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2979
		/* This station can be used, add it to st1/st2 */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2980
		if (st1 == NULL || st->goods[type].rating >= best_rating1) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2981
			st2 = st1; best_rating2 = best_rating1; st1 = st; best_rating1 = st->goods[type].rating;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2982
		} else if (st2 == NULL || st->goods[type].rating >= best_rating2) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2983
			st2 = st; best_rating2 = st->goods[type].rating;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2984
		}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2985
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2986
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2987
	/* no stations around at all? */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2988
	if (st1 == NULL) return 0;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2989
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2990
	if (st2 == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2991
		/* only one station around */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2992
		uint moved = amount * best_rating1 / 256 + 1;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2993
		UpdateStationWaiting(st1, type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2994
		return moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2995
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2996
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  2997
	/* several stations around, the best two (highest rating) are in st1 and st2 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2998
	assert(st1 != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2999
	assert(st2 != NULL);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3000
	assert(best_rating1 != 0 || best_rating2 != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3001
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3002
	/* the 2nd highest one gets a penalty */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3003
	best_rating2 >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3004
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3005
	/* amount given to station 1 */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3006
	uint t = (best_rating1 * (amount + 1)) / (best_rating1 + best_rating2);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3007
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3008
	uint moved = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3009
	if (t != 0) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3010
		moved = t * best_rating1 / 256 + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3011
		amount -= t;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  3012
		UpdateStationWaiting(st1, type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3013
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3014
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3015
	if (amount != 0) {
3000
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  3016
		amount = amount * best_rating2 / 256 + 1;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  3017
		moved += amount;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3018
		UpdateStationWaiting(st2, type, amount);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3019
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3020
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3021
	return moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3022
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3023
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  3024
void BuildOilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3025
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  3026
	Station *st = new Station(tile);
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3027
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3028
	if (st == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5550
diff changeset
  3029
		DEBUG(misc, 0, "Can't allocate station for oilrig at 0x%X, reverting to oilrig only", tile);
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3030
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3031
	}
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3032
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  3033
	st->town = ClosestTownFromTile(tile, UINT_MAX);
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3034
	st->sign.width_1 = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3035
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10346
diff changeset
  3036
	st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3037
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3038
	MakeOilrig(tile, st->index);
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3039
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3040
	st->owner = OWNER_NONE;
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
  3041
	st->airport_flags.ResetAll();
6793
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6777
diff changeset
  3042
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6777
diff changeset
  3043
	//add assignment of fsmportspec, and paint tile of North corner as fsmport
6854
92ca286e9466 (svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
rubidium
parents: 6853
diff changeset
  3044
	int fsmportspecindex = AllocateFSMportsSpecToStation(AirportFTAClass::oil_rig->spec, st, true);
6793
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6777
diff changeset
  3045
	SetCustomFSMportsSpecIndex(tile, fsmportspecindex);
1574da7d2297 (svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
richk
parents: 6777
diff changeset
  3046
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3047
	st->xy = tile;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3048
	st->bus_stops = NULL;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3049
	st->truck_stops = NULL;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3050
	st->airport_tile = tile;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3051
	st->dock_tile = tile;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3052
	st->train_tile = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3053
	st->had_vehicle_of_type = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3054
	st->time_since_load = 255;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3055
	st->time_since_unload = 255;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3056
	st->delete_ctr = 0;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  3057
	st->last_vehicle_type = VEH_INVALID;
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3058
	st->facilities = FACIL_AIRPORT | FACIL_DOCK;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3059
	st->build_date = _date;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3060
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
  3061
	for (CargoID j = 0; j < NUM_CARGO; j++) {
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3062
		st->goods[j].acceptance_pickup = 0;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3063
		st->goods[j].days_since_pickup = 255;
6587
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  3064
		st->goods[j].rating = INITIAL_STATION_RATING;
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3065
		st->goods[j].last_speed = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3066
		st->goods[j].last_age = 255;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3067
	}
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3068
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3069
	UpdateStationVirtCoordDirty(st);
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  3070
	UpdateStationAcceptance(st, false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3071
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3072
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  3073
void DeleteOilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3074
{
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3075
	Station *st = GetStationByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3076
6138
c9a4aadfaaac (svn r8499) -Fix
tron
parents: 6130
diff changeset
  3077
	MakeWater(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3078
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3079
	st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3080
	st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3081
	st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK);
6739
3f2ca4d0abda (svn r10738) [NewGRF_ports] -Feature: FSMblockmap class added. Basic FSM import complete. Need to handle multiple blocks on import. Aircraft controller recoded to work with new 128 bit blocks. Still need to write saveload for new blocks.
richk
parents: 6738
diff changeset
  3082
	st->airport_flags.ResetAll();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3083
	UpdateStationVirtCoordDirty(st);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  3084
	if (st->facilities == 0) delete st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3085
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3086
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2427
diff changeset
  3087
static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3088
{
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  3089
	if (!IsTileOwner(tile, old_player)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3090
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4638
diff changeset
  3091
	if (new_player != PLAYER_SPECTATOR) {
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3092
		Station *st = GetStationByTile(tile);
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  3093
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  3094
		SetTileOwner(tile, new_player);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3095
		if (!IsBuoy(tile)) st->owner = new_player; // do not set st->owner for buoys
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  3096
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3097
	} else {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3098
		if (IsDriveThroughStopTile(tile)) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3099
			/* Remove the drive-through road stop */
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  3100
			DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3101
			assert(IsTileType(tile, MP_ROAD));
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3102
			/* Change owner of tile and all roadtypes */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3103
			ChangeTileOwner(tile, old_player, new_player);
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3104
		} else {
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3105
			DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3106
			/* Set tile owner of water under (now removed) buoy and dock to OWNER_NONE.
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3107
			 * Update owner of buoy if it was not removed (was in orders).
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3108
			 * Do not update when owned by OWNER_WATER (sea and rivers). */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3109
			if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && IsTileOwner(tile, old_player)) SetTileOwner(tile, OWNER_NONE);
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3110
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3111
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3112
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3113
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3114
/**
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3115
 * Check if a drive-through road stop tile can be cleared.
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3116
 * Road stops built on town-owned roads check the conditions
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3117
 * that would allow clearing of the original road.
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3118
 * @param tile road stop tile to check
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  3119
 * @param flags command flags
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3120
 * @return true if the road can be cleared
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3121
 */
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  3122
static bool CanRemoveRoadWithStop(TileIndex tile, uint32 flags)
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3123
{
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3124
	/* The road can always be cleared if it was not a town-owned road */
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3125
	if (!GetStopBuiltOnTownRoad(tile)) return true;
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3126
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  3127
	return CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, ROADTYPE_ROAD, flags);
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3128
}
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  3129
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3130
static CommandCost ClearTile_Station(TileIndex tile, byte flags)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  3131
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3132
	if (flags & DC_AUTO) {
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3133
		switch (GetStationType(tile)) {
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3134
			case STATION_RAIL:    return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3135
			case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST);
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3136
			case STATION_TRUCK:   return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_CARGO_TRAM_STATION : STR_3047_MUST_DEMOLISH_TRUCK_STATION);
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6877
diff changeset
  3137
			case STATION_BUS:     return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_PASSENGER_TRAM_STATION : STR_3046_MUST_DEMOLISH_BUS_STATION);
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3138
			case STATION_BUOY:    return_cmd_error(STR_306A_BUOY_IN_THE_WAY);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3139
			case STATION_DOCK:    return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3140
			case STATION_OILRIG:
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3141
				SetDParam(0, STR_4807_OIL_RIG);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3142
				return_cmd_error(STR_4800_IN_THE_WAY);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3143
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3144
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3145
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3146
	Station *st = GetStationByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3147
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3148
	switch (GetStationType(tile)) {
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3149
		case STATION_RAIL:    return RemoveRailroadStation(st, tile, flags);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3150
		case STATION_AIRPORT: return RemoveAirport(st, flags);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3151
		case STATION_TRUCK:
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  3152
			if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags))
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  3153
				return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION);
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  3154
			return RemoveRoadStop(st, flags, tile);
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  3155
		case STATION_BUS:
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  3156
			if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags))
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  3157
				return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION);
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  3158
			return RemoveRoadStop(st, flags, tile);
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3159
		case STATION_BUOY:    return RemoveBuoy(st, flags);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3160
		case STATION_DOCK:    return RemoveDock(st, flags);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3161
		default: break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3162
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3163
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3164
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3165
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3166
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3167
void InitializeStations()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3168
{
1272
d3e09adb7736 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
  3169
	/* Clean the station pool and create 1 block in it */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  3170
	_Station_pool.CleanPool();
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  3171
	_Station_pool.AddBlockToPool();
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  3172
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3173
	/* Clean the roadstop pool and create 1 block in it */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  3174
	_RoadStop_pool.CleanPool();
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  3175
	_RoadStop_pool.AddBlockToPool();
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  3176
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3177
	_station_tick_ctr = 0;
6758
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6746
diff changeset
  3178
	/* Check whether our &fsmblocks == &fsmblocks.blocks "hack" works */
1545d187ab64 (svn r10800) [NewGRF_ports] -Add: saving of FSMblockmaps.
rubidium
parents: 6746
diff changeset
  3179
	FSMblockmap::AssertOnWrongBlockOffset();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3180
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3181
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3182
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3183
void AfterLoadStations()
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3184
{
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3185
	/* Update the speclists of all stations to point to the currently loaded custom stations. */
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3186
	Station *st;
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3187
	FOR_ALL_STATIONS(st) {
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3188
		for (uint i = 0; i < st->num_specs; i++) {
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3189
			if (st->speclist[i].grfid == 0) continue;
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3190
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3191
			st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx);
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3192
		}
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3193
6733
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3194
		for (uint i = 0; i < st->num_fsmportsspecs; i++) {
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3195
			if (st->fsmportsspeclist[i].grfid == 0) continue;
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3196
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3197
			st->fsmportsspeclist[i].spec = GetCustomFSMportsSpecByGrf(st->fsmportsspeclist[i].grfid, st->fsmportsspeclist[i].localidx);
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3198
		}
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3199
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3200
		for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  3201
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  3202
		StationUpdateAnimTriggers(st);
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3203
	}
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3204
}
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3205
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3206
static CommandCost TerraformTile_Station(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3207
{
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  3208
	if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3209
		/* TODO: If you implement newgrf callback 149 'land slope check', you have to decide what to do with it here.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3210
		 *       TTDP does not call it.
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3211
		 */
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3212
		if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3213
			switch (GetStationType(tile)) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3214
				case STATION_RAIL: {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3215
					DiagDirection direction = AxisToDiagDir(GetRailStationAxis(tile));
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3216
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3217
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3218
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3219
				}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3220
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3221
				case STATION_AIRPORT:
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3222
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3223
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3224
				case STATION_TRUCK:
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3225
				case STATION_BUS: {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3226
					DiagDirection direction = GetRoadStopDir(tile);
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3227
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3228
					if (IsDriveThroughStopTile(tile)) {
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3229
						if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3230
					}
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3231
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
6870
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3232
				}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3233
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3234
				default: break;
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3235
			}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3236
		}
ca3fd1fbe311 (svn r11219) [NewGRF_ports] -Sync: with trunk r11035:11218.
rubidium
parents: 6868
diff changeset
  3237
	}
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3238
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3239
}
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3240
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3241
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  3242
extern const TileTypeProcs _tile_type_station_procs = {
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3243
	DrawTile_Station,           /* draw_tile_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3244
	GetSlopeZ_Station,          /* get_slope_z_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3245
	ClearTile_Station,          /* clear_tile_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3246
	GetAcceptedCargo_Station,   /* get_accepted_cargo_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3247
	GetTileDesc_Station,        /* get_tile_desc_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3248
	GetTileTrackStatus_Station, /* get_tile_track_status_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3249
	ClickTile_Station,          /* click_tile_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3250
	AnimateTile_Station,        /* animate_tile_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3251
	TileLoop_Station,           /* tile_loop_clear */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3252
	ChangeTileOwner_Station,    /* change_tile_owner_clear */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3253
	NULL,                       /* get_produced_cargo_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3254
	VehicleEnter_Station,       /* vehicle_enter_tile_proc */
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6739
diff changeset
  3255
	GetFoundation_Station,      /* get_foundation_proc */
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3256
	TerraformTile_Station,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3257
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3258
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: 1876
diff changeset
  3259
static const SaveLoad _roadstop_desc[] = {
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3260
	SLE_VAR(RoadStop, xy,           SLE_UINT32),
5969
8aa5b3220178 (svn r8212) -Fix
tron
parents: 5967
diff changeset
  3261
	SLE_CONDNULL(1, 0, 44),
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3262
	SLE_VAR(RoadStop, status,       SLE_UINT8),
1285
dee20e32bffe (svn r1789) -Fix: there is no need to save the index, it is done for us
truelight
parents: 1284
diff changeset
  3263
	/* Index was saved in some versions, but this is not needed */
3222
8bfed4267cba (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  3264
	SLE_CONDNULL(4, 0, 8),
5967
d862ebaf5035 (svn r8207) -Fix
tron
parents: 5960
diff changeset
  3265
	SLE_CONDNULL(2, 0, 44),
3479
a4d992b5d24d (svn r4324) Remove the unused road stop type attribute from struct RoadStop
tron
parents: 3478
diff changeset
  3266
	SLE_CONDNULL(1, 0, 25),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3267
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3268
	SLE_REF(RoadStop, next,         REF_ROADSTOPS),
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  3269
	SLE_CONDNULL(2, 0, 44),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3270
3431
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3429
diff changeset
  3271
	SLE_CONDNULL(4, 0, 24),
3475
1b68d263ae0e (svn r4320) -Fix/Codechange: rs->num_vehicles is no longer saved or loaded, but computed on the fly. Partly fixes FS#101
celestar
parents: 3474
diff changeset
  3272
	SLE_CONDNULL(1, 25, 25),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3273
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3274
	SLE_END()
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3275
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3276
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: 1876
diff changeset
  3277
static const SaveLoad _station_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: 4326
diff changeset
  3278
	SLE_CONDVAR(Station, 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: 4326
diff changeset
  3279
	SLE_CONDVAR(Station, xy,                         SLE_UINT32,                  6, SL_MAX_VERSION),
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3280
	SLE_CONDNULL(4, 0, 5),  ///< bus/lorry tile
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: 4326
diff changeset
  3281
	SLE_CONDVAR(Station, train_tile,                 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: 4326
diff changeset
  3282
	SLE_CONDVAR(Station, train_tile,                 SLE_UINT32,                  6, 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: 4326
diff changeset
  3283
	SLE_CONDVAR(Station, airport_tile,               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: 4326
diff changeset
  3284
	SLE_CONDVAR(Station, airport_tile,               SLE_UINT32,                  6, 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: 4326
diff changeset
  3285
	SLE_CONDVAR(Station, dock_tile,                  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: 4326
diff changeset
  3286
	SLE_CONDVAR(Station, dock_tile,                  SLE_UINT32,                  6, 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: 4326
diff changeset
  3287
	    SLE_REF(Station, town,                       REF_TOWN),
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: 4326
diff changeset
  3288
	    SLE_VAR(Station, trainst_w,                  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: 4326
diff changeset
  3289
	SLE_CONDVAR(Station, trainst_h,                  SLE_UINT8,                   2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3290
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3291
	SLE_CONDNULL(1, 0, 3),  ///< alpha_order
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3292
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: 4326
diff changeset
  3293
	    SLE_VAR(Station, string_id,                  SLE_STRINGID),
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  3294
	SLE_CONDSTR(Station, name,                       SLE_STR, 0,                 84, 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: 4326
diff changeset
  3295
	    SLE_VAR(Station, had_vehicle_of_type,        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: 4326
diff changeset
  3296
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: 4326
diff changeset
  3297
	    SLE_VAR(Station, time_since_load,            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: 4326
diff changeset
  3298
	    SLE_VAR(Station, time_since_unload,          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: 4326
diff changeset
  3299
	    SLE_VAR(Station, delete_ctr,                 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: 4326
diff changeset
  3300
	    SLE_VAR(Station, owner,                      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: 4326
diff changeset
  3301
	    SLE_VAR(Station, facilities,                 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: 4326
diff changeset
  3302
	    SLE_VAR(Station, airport_type,               SLE_UINT8),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3303
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3304
	SLE_CONDNULL(2, 0, 5),  ///< Truck/bus stop status
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3305
	SLE_CONDNULL(1, 0, 4),  ///< Blocked months
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: 4326
diff changeset
  3306
6321
62564548351b (svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents: 6317
diff changeset
  3307
	SLE_CONDVAR(Station, airport_flags,              SLE_VAR_U64 | SLE_FILE_U16,  0,  2),
62564548351b (svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents: 6317
diff changeset
  3308
	SLE_CONDVAR(Station, airport_flags,              SLE_VAR_U64 | SLE_FILE_U32,  3, 45),
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3309
	SLE_CONDVAR(Station, airport_flags,              SLE_UINT64,                 46, NEWGRF_AIRPORTS_SAVEGAME - 1),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3310
	SLE_CONDARR(Station, airport_flags,              SLE_UINT64, 2,              NEWGRF_AIRPORTS_SAVEGAME, SL_MAX_VERSION),
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3311
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3312
	SLE_CONDNULL(2, 0, 25), ///< last-vehicle
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: 4326
diff changeset
  3313
	SLE_CONDVAR(Station, last_vehicle_type,          SLE_UINT8,                  26, SL_MAX_VERSION),
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3314
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10210
diff changeset
  3315
	SLE_CONDNULL(2, 3, 25), ///< custom station class and id
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: 4326
diff changeset
  3316
	SLE_CONDVAR(Station, build_date,                 SLE_FILE_U16 | SLE_VAR_I32,  3, 30),
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: 4326
diff changeset
  3317
	SLE_CONDVAR(Station, build_date,                 SLE_INT32,                  31, 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: 4326
diff changeset
  3318
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: 4326
diff changeset
  3319
	SLE_CONDREF(Station, bus_stops,                  REF_ROADSTOPS,               6, 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: 4326
diff changeset
  3320
	SLE_CONDREF(Station, truck_stops,                REF_ROADSTOPS,               6, SL_MAX_VERSION),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3321
3687
109ec5cdb932 (svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents: 3682
diff changeset
  3322
	/* Used by newstations for graphic variations */
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: 4326
diff changeset
  3323
	SLE_CONDVAR(Station, random_bits,                SLE_UINT16,                 27, 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: 4326
diff changeset
  3324
	SLE_CONDVAR(Station, waiting_triggers,           SLE_UINT8,                  27, 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: 4326
diff changeset
  3325
	SLE_CONDVAR(Station, num_specs,                  SLE_UINT8,                  27, SL_MAX_VERSION),
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3326
	SLE_CONDVAR(Station, num_fsmportsspecs,          SLE_UINT8,                  NEWGRF_AIRPORTS_SAVEGAME, SL_MAX_VERSION),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3327
	SLE_CONDVAR(Station, FSMport_layout_set,         SLE_UINT8,                  NEWGRF_AIRPORTS_SAVEGAME, SL_MAX_VERSION),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3328
	SLE_CONDVAR(Station, FSMport_orientation,        SLE_UINT8,                  NEWGRF_AIRPORTS_SAVEGAME, SL_MAX_VERSION),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3329
	SLE_CONDVAR(Station, FSMport_flood_protected,    SLE_BOOL,                   NEWGRF_AIRPORTS_SAVEGAME, SL_MAX_VERSION),
3687
109ec5cdb932 (svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents: 3682
diff changeset
  3330
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  3331
	SLE_CONDLST(Station, loading_vehicles,           REF_VEHICLE,                57, SL_MAX_VERSION),
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  3332
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3333
	/* reserve extra space in savegame here. (currently 32 bytes) */
3222
8bfed4267cba (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  3334
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3336
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3337
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3338
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3339
static uint16 _waiting_acceptance;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3340
static uint16 _cargo_source;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3341
static uint32 _cargo_source_xy;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3342
static uint16 _cargo_days;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3343
static Money  _cargo_feeder_share;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3344
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3345
static const SaveLoad _station_speclist_desc[] = {
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3346
	SLE_CONDVAR(StationSpecList, grfid,    SLE_UINT32, 27, SL_MAX_VERSION),
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3347
	SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8,  27, SL_MAX_VERSION),
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3348
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3349
	SLE_END()
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3350
};
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3351
6733
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3352
static const SaveLoad _fsmports_speclist_desc[] = {
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3353
	SLE_CONDVAR(FSMportsSpecList, grfid,    SLE_UINT32, NEWGRF_AIRPORTS_SAVEGAME, SL_MAX_VERSION),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3354
	SLE_CONDVAR(FSMportsSpecList, localidx, SLE_UINT8,  NEWGRF_AIRPORTS_SAVEGAME, SL_MAX_VERSION),
6733
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3355
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3356
	SLE_END()
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3357
};
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3358
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3359
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3360
void SaveLoad_STNS(Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3361
{
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3362
	static const SaveLoad _goods_desc[] = {
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3363
		SLEG_CONDVAR(            _waiting_acceptance, SLE_UINT16,                  0, 67),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3364
		 SLE_CONDVAR(GoodsEntry, acceptance_pickup,   SLE_UINT8,                  68, SL_MAX_VERSION),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3365
		SLE_CONDNULL(2,                                                           51, 67),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3366
		     SLE_VAR(GoodsEntry, days_since_pickup,   SLE_UINT8),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3367
		     SLE_VAR(GoodsEntry, rating,              SLE_UINT8),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3368
		SLEG_CONDVAR(            _cargo_source,       SLE_FILE_U8 | SLE_VAR_U16,   0, 6),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3369
		SLEG_CONDVAR(            _cargo_source,       SLE_UINT16,                  7, 67),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3370
		SLEG_CONDVAR(            _cargo_source_xy,    SLE_UINT32,                 44, 67),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3371
		SLEG_CONDVAR(            _cargo_days,         SLE_UINT8,                   0, 67),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3372
		     SLE_VAR(GoodsEntry, last_speed,          SLE_UINT8),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3373
		     SLE_VAR(GoodsEntry, last_age,            SLE_UINT8),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3374
		SLEG_CONDVAR(            _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3375
		SLEG_CONDVAR(            _cargo_feeder_share, SLE_INT64,                  65, 67),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3376
		 SLE_CONDLST(GoodsEntry, cargo.packets,       REF_CARGO_PACKET,           68, SL_MAX_VERSION),
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3377
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3378
		SLE_END()
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3379
};
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3380
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3381
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3382
	SlObject(st, _station_desc);
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  3383
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3384
	_waiting_acceptance = 0;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3385
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  3386
	uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6718
diff changeset
  3387
	for (CargoID i = 0; i < num_cargo; i++) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3388
		GoodsEntry *ge = &st->goods[i];
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3389
		SlObject(ge, _goods_desc);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3390
		if (CheckSavegameVersion(68)) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3391
			SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3392
			if (GB(_waiting_acceptance, 0, 12) != 0) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3393
				/* Don't construct the packet with station here, because that'll fail with old savegames */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3394
				CargoPacket *cp = new CargoPacket();
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3395
				/* In old versions, enroute_from used 0xFF as INVALID_STATION */
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3396
				cp->source          = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3397
				cp->count           = GB(_waiting_acceptance, 0, 12);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3398
				cp->days_in_transit = _cargo_days;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3399
				cp->feeder_share    = _cargo_feeder_share;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3400
				cp->source_xy       = _cargo_source_xy;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3401
				cp->days_in_transit = _cargo_days;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3402
				cp->feeder_share    = _cargo_feeder_share;
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6867
diff changeset
  3403
				SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, 1);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3404
				ge->cargo.Append(cp);
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3405
			}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  3406
		}
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  3407
	}
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3408
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3409
	if (st->num_specs != 0) {
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3410
		/* Allocate speclist memory when loading a game */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5852
diff changeset
  3411
		if (st->speclist == NULL) st->speclist = CallocT<StationSpecList>(st->num_specs);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3412
		for (uint i = 0; i < st->num_specs; i++) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3413
			SlObject(&st->speclist[i], _station_speclist_desc);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3414
		}
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3415
	}
6733
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3416
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3417
	if (st->num_fsmportsspecs != 0) {
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3418
		/* Allocate fsmspeclist memory when loading a game */
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3419
		if (st->fsmportsspeclist == NULL) st->fsmportsspeclist = CallocT<FSMportsSpecList>(st->num_fsmportsspecs);
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3420
		for (uint i = 0; i < st->num_fsmportsspecs; i++) {
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3421
			SlObject(&st->fsmportsspeclist[i], _fsmports_speclist_desc);
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3422
		}
240d846d5149 (svn r10654) [NewGRF_ports] -Change: Can now load and save newgrf airports. Graphics correctly reloaded after save.
richk
parents: 6732
diff changeset
  3423
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3424
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3425
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3426
static void Save_STNS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3427
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3428
	Station *st;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3429
	/* Write the stations */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3430
	FOR_ALL_STATIONS(st) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3431
		SlSetArrayIndex(st->index);
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3432
		SlAutolength((AutolengthProc*)SaveLoad_STNS, st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3433
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3434
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3435
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3436
static void Load_STNS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3437
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3438
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3439
	while ((index = SlIterateArray()) != -1) {
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  3440
		Station *st = new (index) Station();
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  3441
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3442
		SaveLoad_STNS(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3443
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6870
diff changeset
  3444
		/* this means it's an oldstyle savegame without support for nonuniform stations */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  3445
		if (st->train_tile != 0 && st->trainst_h == 0) {
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3446
			uint w = GB(st->trainst_w, 4, 4);
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3447
			uint h = GB(st->trainst_w, 0, 4);
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3448
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6424
diff changeset
  3449
			if (GetRailStationAxis(st->train_tile) != AXIS_X) Swap(w, h);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3450
			st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3451
			st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3452
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3453
	}
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  3454
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
  3455
	/* This is to ensure all pointers are within the limits of _stations_size */
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5220
diff changeset
  3456
	if (_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3457
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3458
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3459
static void Save_ROADSTOP()
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3460
{
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3461
	RoadStop *rs;
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3462
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3463
	FOR_ALL_ROADSTOPS(rs) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3464
		SlSetArrayIndex(rs->index);
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3465
		SlObject(rs, _roadstop_desc);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3466
	}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3467
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3468
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3469
static void Load_ROADSTOP()
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3470
{
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3471
	int index;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3472
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3473
	while ((index = SlIterateArray()) != -1) {
5967
d862ebaf5035 (svn r8207) -Fix
tron
parents: 5960
diff changeset
  3474
		RoadStop *rs = new (index) RoadStop(INVALID_TILE);
5959
6a4c261987c3 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5948
diff changeset
  3475
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3476
		SlObject(rs, _roadstop_desc);
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3477
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3478
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3479
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  3480
extern const ChunkHandler _station_chunk_handlers[] = {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3481
	{ 'STNS', Save_STNS,      Load_STNS,      CH_ARRAY },
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3482
	{ 'ROAD', Save_ROADSTOP,  Load_ROADSTOP,  CH_ARRAY | CH_LAST},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3483
};