src/station_cmd.cpp
author terom@frrb.lan
Fri, 19 Dec 2008 01:38:09 +0200
changeset 10439 50f056aa3024
parent 10355 8a930759b457
permissions -rw-r--r--
industries, unmoveables... everything but the landscape
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9075
diff changeset
     3
/** @file station_cmd.cpp Handling of station tiles. */
2213
bab9abeaa644 (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
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
6087
bfa159e740d9 (svn r8822) -Fix
tron
parents: 6076
diff changeset
     7
#include "aircraft.h"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
     8
#include "bridge_map.h"
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
     9
#include "cmd_helper.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1295
diff changeset
    10
#include "debug.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
    11
#include "tile_cmd.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6427
diff changeset
    12
#include "landscape.h"
3315
c9d989783c55 (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"
8225
cd84a95b6630 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8214
diff changeset
    14
#include "viewport_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
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"
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8732
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
415546028e8d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    20
#include "sprite.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2671
diff changeset
    21
#include "train.h"
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6823
diff changeset
    22
#include "roadveh.h"
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
    23
#include "water_map.h"
3515
86dccaaef457 (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
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
    25
#include "newgrf_callbacks.h"
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
    26
#include "newgrf_station.h"
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10353
diff changeset
    27
#include "newgrf_commons.h"
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
    28
#include "yapf/yapf.h"
8102
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8098
diff changeset
    29
#include "road_type.h"
906a3d3b6df1 (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8098
diff changeset
    30
#include "road_internal.h" /* For drawing catenary/checking road removal */
6091
c8827d9ae04a (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: 6087
diff changeset
    31
#include "cargotype.h"
8211
29a8510dfd62 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8166
diff changeset
    32
#include "variables.h"
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
    33
#include "autoslope.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7826
diff changeset
    34
#include "transparency.h"
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7931
diff changeset
    35
#include "water.h"
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8015
diff changeset
    36
#include "station_gui.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8109
diff changeset
    37
#include "strings_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    38
#include "functions.h"
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    39
#include "window_func.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    40
#include "date_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    41
#include "vehicle_func.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8211
diff changeset
    42
#include "string_func.h"
8238
d47a86c79603 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8236
diff changeset
    43
#include "signal_func.h"
8847
426dd2d582e7 (svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents: 8846
diff changeset
    44
#include "oldpool_func.h"
9005
d6b0e0a54ef2 (svn r12800) -Codechange: move the animated tile related functions out of texteff.cpp (it isn't a text effect after all). Also remove a few more functions from functions.
rubidium
parents: 9003
diff changeset
    45
#include "animated_tile_func.h"
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9111
diff changeset
    46
#include "elrail_func.h"
9714
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
    47
#include "newgrf.h"
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
    48
#include "core/smallvec_type.hpp"
8238
d47a86c79603 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8236
diff changeset
    49
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    50
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    51
#include "table/strings.h"
5666
d0e00c728f41 (svn r8126) -Fix (r8125): missing #include fixes compilation error on g++ (still some warnings, working on it)
KUDr
parents: 5665
diff changeset
    52
7376
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7370
diff changeset
    53
DEFINE_OLD_POOL_GENERIC(Station, Station)
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7370
diff changeset
    54
DEFINE_OLD_POOL_GENERIC(RoadStop, RoadStop)
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    55
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    56
7320
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    57
/**
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    58
 * Check whether the given tile is a hangar.
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    59
 * @param t the tile to of whether it is a hangar.
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    60
 * @pre IsTileType(t, MP_STATION)
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    61
 * @return true if and only if the tile is a hangar.
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    62
 */
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    63
bool IsHangar(TileIndex t)
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    64
{
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    65
	assert(IsTileType(t, MP_STATION));
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    66
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    67
	const Station *st = GetStationByTile(t);
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    68
	const AirportFTAClass *apc = st->Airport();
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    69
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    70
	for (uint i = 0; i < apc->nof_depots; i++) {
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    71
		if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == t) return true;
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    72
	}
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    73
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    74
	return false;
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    75
}
96d5862ec06a (svn r10681) -Codechange: do not determine whether a tile is a hangar based on the graphics index to be drawn on the given tile, but do it based on the specification of the location of hangars of the airport.
rubidium
parents: 7319
diff changeset
    76
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
    77
RoadStop *GetRoadStopByTile(TileIndex tile, RoadStopType type)
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    78
{
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
    79
	const Station *st = GetStationByTile(tile);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
    80
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
    81
	for (RoadStop *rs = st->GetPrimaryRoadStop(type);; rs = rs->next) {
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
    82
		if (rs->xy == tile) return rs;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    83
		assert(rs->next != NULL);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    84
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    85
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    86
5913
727fc088635a (svn r8539) -Fix
tron
parents: 5906
diff changeset
    87
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
    88
static uint GetNumRoadStopsInStation(const Station *st, RoadStopType type)
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    89
{
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
    90
	uint num = 0;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    91
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    92
	assert(st != NULL);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
    93
	for (const RoadStop *rs = st->GetPrimaryRoadStop(type); rs != NULL; rs = rs->next) {
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
    94
		num++;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
    95
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    96
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    97
	return num;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    98
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    99
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   100
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
#define CHECK_STATIONS_ERR ((Station*)-1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   103
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
   104
{
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6402
diff changeset
   105
	/* check around to see if there's any stations there */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   106
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   107
		if (IsTileType(tile_cur, MP_STATION)) {
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
   108
			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
   109
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   110
			if (closest_station == INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
				closest_station = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
			} else if (closest_station != t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
				_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
				return CHECK_STATIONS_ERR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
		}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   117
	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   118
	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
   119
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   121
/**
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   122
 * Function to check whether the given tile matches some criterion.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   123
 * @param tile the tile to check
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   124
 * @return true if it matches, false otherwise
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   125
 */
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   126
typedef bool (*CMSAMatcher)(TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
3515
86dccaaef457 (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
   128
/**
86dccaaef457 (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
   129
 * Counts the numbers of tiles matching a specific type in the area around
86dccaaef457 (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
   130
 * @param tile the center tile of the 'count area'
86dccaaef457 (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
   131
 * @param type the type of tile searched for
86dccaaef457 (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
   132
 * @param industry when type == MP_INDUSTRY, the type of the industry,
86dccaaef457 (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
   133
 *                 in all other cases this parameter is ignored
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6198
diff changeset
   134
 * @return the result the noumber of matching tiles around
3515
86dccaaef457 (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
   135
 */
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   136
static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   137
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   140
	for (int dx = -3; dx <= 3; dx++) {
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   141
		for (int dy = -3; dy <= 3; dy++) {
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   142
			if (cmp(TILE_MASK(tile + TileDiffXY(dx, dy)))) num++;
3515
86dccaaef457 (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
   143
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	return num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   149
/**
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   150
 * Check whether the tile is a mine.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   151
 * @param tile the tile to investigate.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   152
 * @return true if and only if the tile is a mine
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   153
 */
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   154
static bool CMSAMine(TileIndex tile)
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   155
{
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   156
	/* No industry */
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   157
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   158
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   159
	const Industry *ind = GetIndustryByTile(tile);
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   160
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   161
	/* No extractive industry */
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   162
	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   163
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   164
	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   165
		/* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine */
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   166
		if (ind->produced_cargo[i] != CT_INVALID && (GetCargo(ind->produced_cargo[i])->classes & CC_LIQUID) == 0) return true;
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   167
	}
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   168
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   169
	return false;
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   170
}
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   171
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   172
/**
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   173
 * Check whether the tile is water.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   174
 * @param tile the tile to investigate.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   175
 * @return true if and only if the tile is a mine
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   176
 */
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   177
static bool CMSAWater(TileIndex tile)
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   178
{
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   179
	return IsTileType(tile, MP_WATER) && IsWater(tile);
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   180
}
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   181
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   182
/**
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   183
 * Check whether the tile is a tree.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   184
 * @param tile the tile to investigate.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   185
 * @return true if and only if the tile is a mine
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   186
 */
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   187
static bool CMSATree(TileIndex tile)
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   188
{
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   189
	return IsTileType(tile, MP_TREES);
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   190
}
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   191
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   192
/**
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   193
 * Check whether the tile is a forest.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   194
 * @param tile the tile to investigate.
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   195
 * @return true if and only if the tile is a mine
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   196
 */
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   197
static bool CMSAForest(TileIndex tile)
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   198
{
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   199
	/* No industry */
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   200
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   201
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   202
	const Industry *ind = GetIndustryByTile(tile);
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   203
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   204
	/* No extractive industry */
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   205
	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   206
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   207
	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   208
		/* The industry produces wood. */
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7642
diff changeset
   209
		if (ind->produced_cargo[i] != CT_INVALID && GetCargo(ind->produced_cargo[i])->label == 'WOOD') return true;
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   210
	}
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   211
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   212
	return false;
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   213
}
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   214
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
#define M(x) ((x) - STR_SV_STNAME)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
7814
92bfbfa6bca8 (svn r11364) -Fix (r11363): compilation broken
glx
parents: 7813
diff changeset
   217
enum StationNaming {
7813
8d6600887f9d (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 7795
diff changeset
   218
	STATIONNAMING_RAIL = 0,
8d6600887f9d (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 7795
diff changeset
   219
	STATIONNAMING_ROAD = 0,
8d6600887f9d (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 7795
diff changeset
   220
	STATIONNAMING_AIRPORT,
8d6600887f9d (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 7795
diff changeset
   221
	STATIONNAMING_OILRIG,
8d6600887f9d (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 7795
diff changeset
   222
	STATIONNAMING_DOCK,
8d6600887f9d (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 7795
diff changeset
   223
	STATIONNAMING_BUOY,
8d6600887f9d (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 7795
diff changeset
   224
	STATIONNAMING_HELIPORT,
7814
92bfbfa6bca8 (svn r11364) -Fix (r11363): compilation broken
glx
parents: 7813
diff changeset
   225
};
7813
8d6600887f9d (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 7795
diff changeset
   226
10347
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   227
/** Information to handle station action 0 property 24 correctly */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   228
struct StationNameInformation {
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   229
	uint32 free_names; ///< Current bitset of free names (we can remove names).
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   230
	bool *indtypes;    ///< Array of bools telling whether an industry type has been found.
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   231
};
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   232
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   233
/**
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   234
 * Find a station action 0 property 24 station name, or reduce the
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   235
 * free_names if needed.
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   236
 * @param tile the tile to search
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   237
 * @param user_data the StationNameInformation to base the search on
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   238
 * @return true if the tile contains an industry that has not given
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   239
 *              it's name to one of the other stations in town.
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   240
 */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   241
static bool FindNearIndustryName(TileIndex tile, void *user_data)
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   242
{
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   243
	/* All already found industry types */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   244
	StationNameInformation *sni = (StationNameInformation*)user_data;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   245
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   246
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   247
	/* If the station name is undefined it means that it doesn't name a station */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   248
	IndustryType indtype = GetIndustryType(tile);
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   249
	if (GetIndustrySpec(indtype)->station_name == STR_UNDEFINED) return false;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   250
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   251
	/* In all cases if an industry that provides a name is found two of
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   252
	 * the standard names will be disabled. */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   253
	sni->free_names &= ~(1 << M(STR_SV_STNAME_OILFIELD) | 1 << M(STR_SV_STNAME_MINES));
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   254
	return !sni->indtypes[indtype];
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   255
}
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   256
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   257
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
   258
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	static const uint32 _gen_station_name_bits[] = {
1454
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   260
		0,                                      /* 0 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   261
		1 << M(STR_SV_STNAME_AIRPORT),          /* 1 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   262
		1 << M(STR_SV_STNAME_OILFIELD),         /* 2 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   263
		1 << M(STR_SV_STNAME_DOCKS),            /* 3 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   264
		0x1FF << M(STR_SV_STNAME_BUOY_1),       /* 4 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   265
		1 << M(STR_SV_STNAME_HELIPORT),         /* 5 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   268
	const Town *t = st->town;
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   269
	uint32 free_names = UINT32_MAX;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
10347
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   271
	bool indtypes[NUM_INDUSTRYTYPES];
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   272
	memset(indtypes, 0, sizeof(indtypes));
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   273
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   274
	const Station *s;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   275
	FOR_ALL_STATIONS(s) {
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   276
		if (s != st && s->town == t) {
10347
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   277
			if (s->indtype != IT_INVALID) {
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   278
				indtypes[s->indtype] = true;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   279
				continue;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   280
			}
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   281
			uint str = M(s->string_id);
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   282
			if (str <= 0x20) {
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   283
				if (str == M(STR_SV_STNAME_FOREST)) {
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   284
					str = M(STR_SV_STNAME_WOODS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
				}
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   286
				ClrBit(free_names, str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   288
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   290
10347
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   291
	if (flag != STATIONNAMING_BUOY) {
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   292
		TileIndex indtile = tile;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   293
		StationNameInformation sni = { free_names, indtypes };
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   294
		if (CircularTileSearch(&indtile, 7, FindNearIndustryName, &sni)) {
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   295
			/* An industry has been found nearby */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   296
			IndustryType indtype = GetIndustryType(indtile);
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   297
			const IndustrySpec *indsp = GetIndustrySpec(indtype);
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   298
			/* STR_NULL means it only disables oil rig/mines */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   299
			if (indsp->station_name != STR_NULL) {
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   300
				st->indtype = indtype;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   301
				return STR_SV_STNAME_FALLBACK;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   302
			}
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   303
		}
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   304
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   305
		/* Oil rigs/mines name could be marked not free by looking for a near by industry. */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   306
		free_names = sni.free_names;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   307
	}
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
   308
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	/* check default names */
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   310
	uint32 tmp = free_names & _gen_station_name_bits[flag];
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   311
	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
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	/* check mine? */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   314
	if (HasBit(free_names, M(STR_SV_STNAME_MINES))) {
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   315
		if (CountMapSquareAround(tile, CMSAMine) >= 2) {
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   316
			return STR_SV_STNAME_MINES;
1454
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   317
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	/* check close enough to town to get central as name? */
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6488
diff changeset
   321
	if (DistanceMax(tile, t->xy) < 8) {
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   322
		if (HasBit(free_names, M(STR_SV_STNAME))) return STR_SV_STNAME;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   323
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   324
		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
   325
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	/* Check lakeside */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   328
	if (HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   329
			DistanceFromEdge(tile) < 20 &&
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   330
			CountMapSquareAround(tile, CMSAWater) >= 5) {
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   331
		return STR_SV_STNAME_LAKESIDE;
1454
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   332
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
	/* Check woods */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   335
	if (HasBit(free_names, M(STR_SV_STNAME_WOODS)) && (
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   336
				CountMapSquareAround(tile, CMSATree) >= 8 ||
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7298
diff changeset
   337
				CountMapSquareAround(tile, CMSAForest) >= 2)
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   338
			) {
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
   339
		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
   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 elevation compared to town */
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   343
	uint z = GetTileZ(tile);
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   344
	uint z2 = GetTileZ(t->xy);
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   345
	if (z < z2) {
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   346
		if (HasBit(free_names, M(STR_SV_STNAME_VALLEY))) return STR_SV_STNAME_VALLEY;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   347
	} else if (z > z2) {
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   348
		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
   349
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	/* check direction compared to town */
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   352
	static const int8 _direction_and_table[] = {
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   353
		~( (1 << M(STR_SV_STNAME_WEST))  | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   354
		~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   355
		~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   356
		~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) ),
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   357
	};
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   358
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   359
	free_names &= _direction_and_table[
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   360
		(TileX(tile) < TileX(t->xy)) +
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   361
		(TileY(tile) < TileY(t->xy)) * 2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6488
diff changeset
   363
	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));
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   364
	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
   365
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
#undef M
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   368
static Station *GetClosestStationFromTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
{
6052
ed3d260a32bc (svn r8782) -Fix
tron
parents: 6051
diff changeset
   370
	uint threshold = 8;
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   371
	Station *best_station = NULL;
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   372
	Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
	FOR_ALL_STATIONS(st) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   375
		if (st->facilities == 0 && st->owner == _current_company) {
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   376
			uint cur_dist = DistanceManhattan(tile, st->xy);
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   377
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   378
			if (cur_dist < threshold) {
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   379
				threshold = cur_dist;
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   380
				best_station = st;
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   381
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
	return best_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   388
/** Update the virtual coords needed to draw the station sign.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   389
 * @param st Station to update for.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   390
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
static void UpdateStationVirtCoord(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
{
3422
a6eba3443452 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 3418
diff changeset
   393
	Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   394
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
	pt.y -= 32;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   396
	if (st->facilities & FACIL_AIRPORT && st->airport_type == AT_OILRIG) pt.y -= 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   398
	SetDParam(0, st->index);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   399
	SetDParam(1, st->facilities);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	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
   401
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   403
/** Update the virtual coords needed to draw the station sign for all stations. */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   404
void UpdateAllStationVirtCoord()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
{
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   406
	Station *st;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   407
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
	FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   409
		UpdateStationVirtCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7539
diff changeset
   413
/**
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7539
diff changeset
   414
 * Update the station virt coords while making the modified parts dirty.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7539
diff changeset
   415
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7539
diff changeset
   416
 * This function updates the virt coords and mark the modified parts as dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7539
diff changeset
   417
 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7539
diff changeset
   418
 * @param st The station to update the virt coords
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7539
diff changeset
   419
 * @ingroup dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7539
diff changeset
   420
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
static void UpdateStationVirtCoordDirty(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
{
5665
d6b5c720ad67 (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: 5660
diff changeset
   423
	st->MarkDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	UpdateStationVirtCoord(st);
5665
d6b5c720ad67 (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: 5660
diff changeset
   425
	st->MarkDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   428
/** Get a mask of the cargo types that the station accepts.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   429
 * @param st Station to query
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   430
 * @return the expected mask
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   431
 */
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   432
static uint GetAcceptanceMask(const Station *st)
0
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
	uint mask = 0;
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   435
6350
04b19f551aec (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6329
diff changeset
   436
	for (CargoID i = 0; i < NUM_CARGO; i++) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   437
		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
   438
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	return mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   442
/** Items contains the two cargo names that are to be accepted or rejected.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   443
 * msg is the string id of the message to display.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   444
 */
5690
2f290fd103cd (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: 5683
diff changeset
   445
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
   446
{
5690
2f290fd103cd (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: 5683
diff changeset
   447
	for (uint i = 0; i < num_items; i++) {
6091
c8827d9ae04a (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: 6087
diff changeset
   448
		SetDParam(i + 1, GetCargo(cargo[i])->name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	}
5690
2f290fd103cd (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: 5683
diff changeset
   450
2f290fd103cd (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: 5683
diff changeset
   451
	SetDParam(0, st->index);
10123
f73d96619303 (svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz
parents: 10109
diff changeset
   452
	AddNewsItem(msg, NS_ACCEPTANCE, st->xy, st->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
   455
/**
8970
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
   456
 * Get a list of the cargo types being produced around the tile (in a rectangle).
10353
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   457
 * @param produced Destination array of produced cargo
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   458
 * @param tile Northtile of area
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   459
 * @param w X extent of the area
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   460
 * @param h Y extent of the area
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   461
 * @param rad Search radius in addition to the given area
8970
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
   462
 */
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   463
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile,
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   464
	int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
{
10273
7ab559547892 (svn r14508) -Fix (r14501): arrays were not properly zeroed
smatz
parents: 10267
diff changeset
   466
	memset(produced, 0, sizeof(AcceptedCargo)); // sizeof(AcceptedCargo) != sizeof(produced) (== sizeof(uint *))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   468
	int x = TileX(tile);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   469
	int y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   471
	/* expand the region by rad tiles on each side
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   472
	 * while making sure that we remain inside the board. */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   473
	int x2 = min(x + w + rad, MapSizeX());
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   474
	int x1 = max(x - rad, 0);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   475
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   476
	int y2 = min(y + h + rad, MapSizeY());
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   477
	int y1 = max(y - rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   484
	for (int yc = y1; yc != y2; yc++) {
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   485
		for (int xc = x1; xc != x2; xc++) {
8846
1b90782b2c4e (svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium
parents: 8840
diff changeset
   486
			TileIndex tile = TileXY(xc, yc);
1b90782b2c4e (svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium
parents: 8840
diff changeset
   487
1b90782b2c4e (svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium
parents: 8840
diff changeset
   488
			if (!IsTileType(tile, MP_STATION)) {
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   489
				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
   490
				if (gpc != NULL) {
8846
1b90782b2c4e (svn r12596) -Feature: show what cargos a station could be supplied with. Patch by Roujin.
rubidium
parents: 8840
diff changeset
   491
					CargoID cargos[256]; // Required for CBID_HOUSE_PRODUCE_CARGO.
10267
eb318bb95dc1 (svn r14501) -Codechange: use sizeof(variable) instead of sizeof(type) or hardcoded amounts (magic constant) for memset (Alberth)
rubidium
parents: 10257
diff changeset
   492
					memset(cargos, CT_INVALID, sizeof(cargos));
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   493
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
					gpc(tile, cargos);
8637
c282b7ea972e (svn r12258) -Fix: GetProductionAroundTiles() may fail if only the second production slot exists
glx
parents: 8616
diff changeset
   495
					for (uint i = 0; i < lengthof(cargos); ++i) {
c282b7ea972e (svn r12258) -Fix: GetProductionAroundTiles() may fail if only the second production slot exists
glx
parents: 8616
diff changeset
   496
						if (cargos[i] != CT_INVALID) produced[cargos[i]]++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
			}
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   500
		}
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   501
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
   504
/**
8970
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
   505
 * Get a list of the cargo types that are accepted around the tile.
10353
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   506
 * @param accepts Destination array of accepted cargo
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   507
 * @param tile Center of the search area
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   508
 * @param w X extent of area
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   509
 * @param h Y extent of area
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
   510
 * @param rad Search radius in addition to given area
8970
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
   511
 */
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   512
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile,
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   513
	int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
{
10273
7ab559547892 (svn r14508) -Fix (r14501): arrays were not properly zeroed
smatz
parents: 10267
diff changeset
   515
	memset(accepts, 0, sizeof(AcceptedCargo)); // sizeof(AcceptedCargo) != sizeof(accepts) (== sizeof(uint *))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   517
	int x = TileX(tile);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   518
	int y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   520
	/* expand the region by rad tiles on each side
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   521
	 * while making sure that we remain inside the board. */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   522
	int x2 = min(x + w + rad, MapSizeX());
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   523
	int y2 = min(y + h + rad, MapSizeY());
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   524
	int x1 = max(x - rad, 0);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   525
	int y1 = max(y - rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   532
	for (int yc = y1; yc != y2; yc++) {
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   533
		for (int xc = x1; xc != x2; xc++) {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   534
			TileIndex tile = TileXY(xc, yc);
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   535
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   536
			if (!IsTileType(tile, MP_STATION)) {
473
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   537
				AcceptedCargo ac;
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   538
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   539
				GetAcceptedCargo(tile, ac);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   540
				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
   541
			}
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   542
		}
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   543
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   546
static inline void MergePoint(Rect *rect, TileIndex tile)
1423
11cd644bf8f8 (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
   547
{
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   548
	int x = TileX(tile);
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   549
	int y = TileY(tile);
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   550
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   551
	if (rect->left   > x) rect->left   = x;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   552
	if (rect->bottom > y) rect->bottom = y;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   553
	if (rect->right  < x) rect->right  = x;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   554
	if (rect->top    < y) rect->top    = y;
1423
11cd644bf8f8 (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
   555
}
11cd644bf8f8 (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
   556
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   557
/** Update the acceptance for a station.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   558
 * @param st Station to update
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   559
 * @param show_msg controls whether to display a message that acceptance was changed.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   560
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
static void UpdateStationAcceptance(Station *st, bool show_msg)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
{
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   563
	/* Don't update acceptance for a buoy */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   564
	if (st->IsBuoy()) return;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   565
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   566
	Rect rect;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   567
	rect.left   = MapSizeX();
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   568
	rect.bottom = MapSizeY();
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   569
	rect.right  = 0;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   570
	rect.top    = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
	/* old accepted goods types */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   573
	uint old_acc = GetAcceptanceMask(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   575
	/* 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
   576
	if (st->train_tile != 0) {
1423
11cd644bf8f8 (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
		MergePoint(&rect, st->train_tile);
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   578
		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
   579
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   580
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	if (st->airport_tile != 0) {
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   582
		const AirportFTAClass *afc = st->Airport();
3876
468642825a10 (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
   583
1423
11cd644bf8f8 (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
   584
		MergePoint(&rect, st->airport_tile);
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   585
		MergePoint(&rect, st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1));
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   586
	}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   587
10228
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   588
	if (st->dock_tile != 0) {
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   589
		MergePoint(&rect, st->dock_tile);
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   590
		if (IsDockTile(st->dock_tile)) {
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   591
			MergePoint(&rect, st->dock_tile + TileOffsByDiagDir(GetDockDirection(st->dock_tile)));
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   592
		} // else OilRig
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   593
	}
1423
11cd644bf8f8 (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
   594
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   595
	for (const RoadStop *rs = st->bus_stops; rs != NULL; rs = rs->next) {
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   596
		MergePoint(&rect, rs->xy);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   597
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   599
	for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) {
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   600
		MergePoint(&rect, rs->xy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   602
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   603
	/* And retrieve the acceptance. */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   604
	AcceptedCargo accepts;
10228
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   605
	assert((rect.right >= rect.left) == !st->rect.IsEmpty());
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   606
	if (rect.right >= rect.left) {
10228
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   607
		assert(rect.left == st->rect.left);
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   608
		assert(rect.top == st->rect.bottom);
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   609
		assert(rect.right == st->rect.right);
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
   610
		assert(rect.bottom == st->rect.top);
1423
11cd644bf8f8 (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
		GetAcceptanceAroundTiles(
11cd644bf8f8 (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
   612
			accepts,
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   613
			TileXY(rect.left, rect.bottom),
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   614
			rect.right - rect.left   + 1,
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
   615
			rect.top   - rect.bottom + 1,
10290
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10289
diff changeset
   616
			st->GetCatchmentRadius()
1423
11cd644bf8f8 (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
   617
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
		memset(accepts, 0, sizeof(accepts));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   622
	/* Adjust in case our station only accepts fewer kinds of goods */
6350
04b19f551aec (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6329
diff changeset
   623
	for (CargoID i = 0; i < NUM_CARGO; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
		uint amt = min(accepts[i], 15);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   626
		/* Make sure the station can accept the goods type. */
6329
a492d5e61d7b (svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents: 6306
diff changeset
   627
		bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
a492d5e61d7b (svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents: 6306
diff changeset
   628
		if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   629
				(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP))) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
			amt = 0;
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   631
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
7474
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7469
diff changeset
   633
		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
   634
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   636
	/* Only show a message in case the acceptance was actually changed. */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   637
	uint new_acc = GetAcceptanceMask(st);
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   638
	if (old_acc == new_acc) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   639
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   640
	/* show a message to report that the acceptance was changed? */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   641
	if (show_msg && st->owner == _local_company && st->facilities) {
5690
2f290fd103cd (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: 5683
diff changeset
   642
		/* List of accept and reject strings for different number of
2f290fd103cd (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: 5683
diff changeset
   643
		 * cargo types */
2f290fd103cd (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: 5683
diff changeset
   644
		static const StringID accept_msg[] = {
2f290fd103cd (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: 5683
diff changeset
   645
			STR_3040_NOW_ACCEPTS,
2f290fd103cd (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: 5683
diff changeset
   646
			STR_3041_NOW_ACCEPTS_AND,
2f290fd103cd (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: 5683
diff changeset
   647
		};
2f290fd103cd (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: 5683
diff changeset
   648
		static const StringID reject_msg[] = {
2f290fd103cd (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: 5683
diff changeset
   649
			STR_303E_NO_LONGER_ACCEPTS,
2f290fd103cd (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: 5683
diff changeset
   650
			STR_303F_NO_LONGER_ACCEPTS_OR,
2f290fd103cd (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: 5683
diff changeset
   651
		};
2f290fd103cd (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: 5683
diff changeset
   652
2f290fd103cd (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: 5683
diff changeset
   653
		/* Array of accepted and rejected cargo types */
2f290fd103cd (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: 5683
diff changeset
   654
		CargoID accepts[2] = { CT_INVALID, CT_INVALID };
2f290fd103cd (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: 5683
diff changeset
   655
		CargoID rejects[2] = { CT_INVALID, CT_INVALID };
2f290fd103cd (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: 5683
diff changeset
   656
		uint num_acc = 0;
2f290fd103cd (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: 5683
diff changeset
   657
		uint num_rej = 0;
2f290fd103cd (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: 5683
diff changeset
   658
2f290fd103cd (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: 5683
diff changeset
   659
		/* Test each cargo type to see if its acceptange has changed */
2f290fd103cd (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: 5683
diff changeset
   660
		for (CargoID i = 0; i < NUM_CARGO; i++) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   661
			if (HasBit(new_acc, i)) {
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   662
				if (!HasBit(old_acc, i) && num_acc < lengthof(accepts)) {
5690
2f290fd103cd (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: 5683
diff changeset
   663
					/* New cargo is accepted */
2f290fd103cd (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: 5683
diff changeset
   664
					accepts[num_acc++] = i;
2f290fd103cd (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: 5683
diff changeset
   665
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
			} else {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   667
				if (HasBit(old_acc, i) && num_rej < lengthof(rejects)) {
5690
2f290fd103cd (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: 5683
diff changeset
   668
					/* Old cargo is no longer accepted */
2f290fd103cd (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: 5683
diff changeset
   669
					rejects[num_rej++] = i;
2f290fd103cd (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: 5683
diff changeset
   670
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
			}
5690
2f290fd103cd (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: 5683
diff changeset
   672
		}
2f290fd103cd (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: 5683
diff changeset
   673
2f290fd103cd (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: 5683
diff changeset
   674
		/* Show news message if there are any changes */
2f290fd103cd (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: 5683
diff changeset
   675
		if (num_acc > 0) ShowRejectOrAcceptNews(st, num_acc, accepts, accept_msg[num_acc - 1]);
2f290fd103cd (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: 5683
diff changeset
   676
		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
   677
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   679
	/* redraw the station view since acceptance changed */
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8015
diff changeset
   680
	InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ACCEPTLIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
5098
7de23befaee4 (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
   683
static void UpdateStationSignCoord(Station *st)
7de23befaee4 (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
   684
{
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   685
	const StationRect *r = &st->rect;
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
   686
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   687
	if (r->IsEmpty()) return; /* no tiles belong to this station */
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   688
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   689
	/* clamp sign coord to be inside the station rect */
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7891
diff changeset
   690
	st->xy = TileXY(ClampU(TileX(st->xy), r->left, r->right), ClampU(TileY(st->xy), r->top, r->bottom));
5098
7de23befaee4 (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
   691
	UpdateStationVirtCoordDirty(st);
7de23befaee4 (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
   692
}
7de23befaee4 (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
   693
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   694
/** This is called right after a station was deleted.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   695
 * It checks if the whole station is free of substations, and if so, the station will be
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   696
 * deleted after a little while.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   697
 * @param st Station
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   698
 */
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   699
static void DeleteStationIfEmpty(Station *st)
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   700
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
	if (st->facilities == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
		st->delete_ctr = 0;
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
   703
		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
   704
	}
5098
7de23befaee4 (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
	/* station remains but it probably lost some parts - station sign should stay in the station boundaries */
7de23befaee4 (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
   706
	UpdateStationSignCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
   709
static CommandCost ClearTile_Station(TileIndex tile, byte flags);
977
ab88e042b39d (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
   710
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   711
/** Tries to clear the given area.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   712
 * @param tile TileIndex to start check
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   713
 * @param w width of search area
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   714
 * @param h height of search area
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   715
 * @param flags operation to perform
8429
ec2a1005006e (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8424
diff changeset
   716
 * @param invalid_dirs prohibited directions (set of DiagDirections)
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   717
 * @param station StationID to be queried and returned if available
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   718
 * @param check_clear if clearing tile should be performed (in wich case, cost will be added)
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   719
 * @return the cost in case of success, or an error code if it failed.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   720
 */
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   721
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID *station, bool check_clear = true)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
{
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
   723
	CommandCost cost(EXPENSES_CONSTRUCTION);
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1328
diff changeset
   724
	int allowed_z = -1;
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   725
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   726
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   727
		if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   728
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   729
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   730
6915
67a982c01f44 (svn r10168) -Fix [FS#879]: cannot build airport when an aircraft is flying over it.
rubidium
parents: 6857
diff changeset
   731
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   733
		uint z;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   734
		Slope tileh = GetTileSlope(tile_cur, &z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
2085
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   736
		/* Prohibit building if
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   737
		 *   1) The tile is "steep" (i.e. stretches two height levels)
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   738
		 * -OR-
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   739
		 *   2) The tile is non-flat if
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   740
		 *     a) the company building is an "old-school" AI
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   741
		 *   -OR-
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   742
		 *     b) the build_on_slopes switch is disabled
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   743
		 */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   744
		if (IsSteepSlope(tileh) ||
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   745
				((_is_old_ai_company || !_settings_game.construction.build_on_slopes) && tileh != SLOPE_FLAT)) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   746
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   749
		int flat_z = z;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   750
		if (tileh != SLOPE_FLAT) {
8429
ec2a1005006e (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8424
diff changeset
   751
			/* need to check so the entrance to the station is not pointing at a slope.
ec2a1005006e (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8424
diff changeset
   752
			 * This must be valid for all station tiles, as the user can remove single station tiles. */
ec2a1005006e (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8424
diff changeset
   753
			if ((HasBit(invalid_dirs, DIAGDIR_NE) && !(tileh & SLOPE_NE)) ||
ec2a1005006e (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8424
diff changeset
   754
			    (HasBit(invalid_dirs, DIAGDIR_SE) && !(tileh & SLOPE_SE)) ||
ec2a1005006e (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8424
diff changeset
   755
			    (HasBit(invalid_dirs, DIAGDIR_SW) && !(tileh & SLOPE_SW)) ||
ec2a1005006e (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8424
diff changeset
   756
			    (HasBit(invalid_dirs, DIAGDIR_NW) && !(tileh & SLOPE_NW))) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   757
				return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
			}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   759
			cost.AddCost(_price.terraform);
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   760
			flat_z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   762
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   763
		/* 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
   764
		if (allowed_z == -1) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   765
			/* first tile */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
			allowed_z = flat_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
		} else if (allowed_z != flat_z) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   768
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   771
		/* if station is set, then we have special handling to allow building on top of already existing stations.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   772
		 * so station points to INVALID_STATION if we can build on any station.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   773
		 * Or it points to a station if we're only allowed to build on exactly that station. */
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   774
		if (station != NULL && IsTileType(tile_cur, MP_STATION)) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
   775
			if (!IsRailwayStation(tile_cur)) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   776
				return ClearTile_Station(tile_cur, DC_AUTO); // get error message
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
			} else {
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
   778
				StationID st = GetStationIndex(tile_cur);
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   779
				if (*station == INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
					*station = st;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   781
				} else if (*station != st) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   782
					return_cmd_error(STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
			}
6720
34eab44fd841 (svn r9952) -Fix r9951: it was not possible to build a drive-through station over a road/tram
glx
parents: 6719
diff changeset
   785
		} else if (check_clear) {
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
   786
			CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   787
			if (CmdFailed(ret)) return ret;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
   788
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
		}
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   790
	} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   795
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
   796
{
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   797
	uint curw = st->trainst_w;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   798
	uint curh = st->trainst_h;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   799
	TileIndex tile = fin[0];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	uint w = fin[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
	uint h = fin[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
   803
	if (_settings_game.station.nonuniform_stations) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   804
		/* determine new size of train station region.. */
926
a6d140a6a4de (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
   805
		int x = min(TileX(st->train_tile), TileX(tile));
a6d140a6a4de (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
   806
		int y = min(TileY(st->train_tile), TileY(tile));
a6d140a6a4de (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
   807
		curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x;
a6d140a6a4de (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
   808
		curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   809
		tile = TileXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
	} else {
8098
e42d1a10cda9 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8096
diff changeset
   811
		/* do not allow modifying non-uniform stations,
e42d1a10cda9 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8096
diff changeset
   812
		 * the uniform-stations code wouldn't handle it well */
e42d1a10cda9 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8096
diff changeset
   813
		BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
e42d1a10cda9 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8096
diff changeset
   814
			if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station
8424
c3477565c975 (svn r11994) -Codechange: Remove numbers from string names where the strings aren't present in TTD, since they don't correspond to either TTD's TextIDs or OpenTTD's StringIDs.
maedhros
parents: 8413
diff changeset
   815
				_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
8098
e42d1a10cda9 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8096
diff changeset
   816
				return false;
e42d1a10cda9 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8096
diff changeset
   817
			}
e42d1a10cda9 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8096
diff changeset
   818
		END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
e42d1a10cda9 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8096
diff changeset
   819
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   820
		/* check so the orientation is the same */
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
   821
		if (GetRailStationAxis(st->train_tile) != axis) {
8424
c3477565c975 (svn r11994) -Codechange: Remove numbers from string names where the strings aren't present in TTD, since they don't correspond to either TTD's TextIDs or OpenTTD's StringIDs.
maedhros
parents: 8413
diff changeset
   822
			_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   823
			return false;
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   824
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   826
		/* check if the new station adjoins the old station in either direction */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   827
		if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   828
			/* above */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
			curh += h;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   830
		} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   831
			/* below */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   832
			tile -= TileDiffXY(0, curh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
			curh += h;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   834
		} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   835
			/* to the left */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
			curw += w;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   837
		} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   838
			/* to the right */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   839
			tile -= TileDiffXY(curw, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
			curw += w;
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   841
		} else {
8424
c3477565c975 (svn r11994) -Codechange: Remove numbers from string names where the strings aren't present in TTD, since they don't correspond to either TTD's TextIDs or OpenTTD's StringIDs.
maedhros
parents: 8413
diff changeset
   842
			_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
			return false;
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   844
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	}
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   846
	/* make sure the final size is not too big. */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
   847
	if (curw > _settings_game.station.station_spread || curh > _settings_game.station.station_spread) {
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   848
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   849
		return false;
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   850
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   852
	/* now tile contains the new value for st->train_tile
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   853
	 * 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
   854
	fin[0] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
	fin[1] = curw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
	fin[2] = curh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
536
03d80fecb999 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   860
static inline byte *CreateSingle(byte *layout, int n)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	do *layout++ = 0; while (--i);
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6488
diff changeset
   864
	layout[((n - 1) >> 1) - n] = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
536
03d80fecb999 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   868
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
   869
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
	do *layout++ = b; while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
	if (n > 4) {
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6488
diff changeset
   873
		layout[0 - n] = 0;
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6488
diff changeset
   874
		layout[n - 1 - n] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   879
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
   880
{
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   881
	if (statspec != NULL && statspec->lengths >= plat_len &&
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   882
			statspec->platforms[plat_len - 1] >= numtracks &&
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   883
			statspec->layouts[plat_len - 1][numtracks - 1]) {
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   884
		/* Custom layout defined, follow it. */
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   885
		memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1],
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   886
			plat_len * numtracks);
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   887
		return;
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   888
	}
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   889
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
	if (plat_len == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
		CreateSingle(layout, numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
	} else {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   893
		if (numtracks & 1) layout = CreateSingle(layout, plat_len);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   894
		numtracks >>= 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
		while (--numtracks >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
			layout = CreateMulti(layout, plat_len, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
			layout = CreateMulti(layout, plat_len, 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
1775
548dc04d50e2 (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
   903
/** Build railroad station
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
   904
 * @param tile_org starting position of station dragging/placement
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6463
diff changeset
   905
 * @param flags operation to perform
1775
548dc04d50e2 (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
   906
 * @param p1 various bitstuffed elements
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   907
 * - p1 = (bit  0)    - orientation (Axis)
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   908
 * - p1 = (bit  8-15) - number of tracks
a04d0142ad65 (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
   909
 * - p1 = (bit 16-23) - platform length
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   910
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
1775
548dc04d50e2 (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
   911
 * @param p2 various bitstuffed elements
548dc04d50e2 (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
   912
 * - p2 = (bit  0- 3) - railtype (p2 & 0xF)
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   913
 * - p2 = (bit  8-15) - custom station class
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   914
 * - p2 = (bit 16-23) - custom station id
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
   916
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
   917
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
	/* Does the authority allow this? */
1775
548dc04d50e2 (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
   919
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
8236
8a5dd0b42e47 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8230
diff changeset
   920
	if (!ValParamRailtype((RailType)(p2 & 0xF))) return CMD_ERROR;
1775
548dc04d50e2 (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
   921
548dc04d50e2 (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
   922
	/* unpack parameters */
6134
871305fd9ab7 (svn r8876) -Fix
tron
parents: 6133
diff changeset
   923
	Axis axis = Extract<Axis, 0>(p1);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   924
	uint numtracks = GB(p1,  8, 8);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   925
	uint plat_len  = GB(p1, 16, 8);
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   926
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
   927
	int w_org, h_org;
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   928
	if (axis == AXIS_X) {
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   929
		w_org = plat_len;
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   930
		h_org = numtracks;
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   931
	} else {
1775
548dc04d50e2 (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
   932
		h_org = plat_len;
548dc04d50e2 (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
   933
		w_org = numtracks;
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
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
   936
	if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR;
1781
5e2fef482637 (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
   937
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   938
	/* these values are those that will be stored in train_tile and station_platforms */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   939
	uint finalvalues[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
	finalvalues[0] = tile_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
	finalvalues[1] = w_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	finalvalues[2] = h_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   944
	/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
   945
	StationID est = INVALID_STATION;
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   946
	/* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   947
	 * for detail info, see:
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   948
	 * https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
   949
	CommandCost ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   950
	if (CmdFailed(ret)) return ret;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
   951
	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
   952
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   953
	Station *st = NULL;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   954
	bool check_surrounding = true;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   955
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
   956
	if (_settings_game.station.adjacent_stations) {
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   957
		if (est != INVALID_STATION) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   958
			if (HasBit(p1, 24)) {
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   959
				/* You can't build an adjacent station over the top of one that
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   960
				 * already exists. */
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   961
				return_cmd_error(STR_MUST_REMOVE_RAILWAY_STATION_FIRST);
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   962
			} else {
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   963
				/* Extend the current station, and don't check whether it will
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   964
				 * be near any other stations. */
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   965
				st = GetStation(est);
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   966
				check_surrounding = false;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   967
			}
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   968
		} else {
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   969
			/* There's no station here. Don't check the tiles surrounding this
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   970
			 * one if the company wanted to build an adjacent station. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   971
			if (HasBit(p1, 24)) check_surrounding = false;
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   972
		}
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   973
	}
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   974
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   975
	if (check_surrounding) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   976
		/* Make sure there are no similar stations around us. */
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   977
		st = GetStationAround(tile_org, w_org, h_org, est);
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   978
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
   979
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   981
	/* See if there is a deleted station close to us. */
6052
ed3d260a32bc (svn r8782) -Fix
tron
parents: 6051
diff changeset
   982
	if (st == NULL) st = GetClosestStationFromTile(tile_org);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
	if (st != NULL) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   985
		/* Reuse an existing station. */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   986
		if (st->owner != _current_company)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
			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
   988
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
		if (st->train_tile != 0) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   990
			/* check if we want to expanding an already existing station? */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   991
			if (_is_old_ai_company || !_settings_game.station.join_stations)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
				return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD);
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   993
			if (!CanExpandRailroadStation(st, finalvalues, axis))
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   994
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
   997
		/* XXX can't we pack this in the "else" part of the if above? */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
   998
		if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR;
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4399
diff changeset
   999
	} else {
5665
d6b5c720ad67 (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: 5660
diff changeset
  1000
		/* allocate and initialize new station */
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1001
		if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1002
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1003
		if (flags & DC_EXEC) {
9063
005b0643381c (svn r12915) -Fix [FS#1960](r12857): don't initialize Station struct with tile=0, buoys will never change that value
smatz
parents: 9055
diff changeset
  1004
			st = new Station(tile_org);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1005
9049
21f20d9bc849 (svn r12875) -Codechange: Use defined const instead of cast magic
belugas
parents: 9048
diff changeset
  1006
			st->town = ClosestTownFromTile(tile_org, UINT_MAX);
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
  1007
			st->string_id = GenerateStationName(st, tile_org, STATIONNAMING_RAIL);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1008
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1009
			if (IsValidCompanyID(_current_company)) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1010
				SetBit(st->town->have_ratings, _current_company);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1011
			}
5665
d6b5c720ad67 (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: 5660
diff changeset
  1012
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1015
	/* Check if the given station class is valid */
8296
59fa0940aefe (svn r11860) -Fix: Test station class validity against number of classes, not abosolute limit.
peter1138
parents: 8264
diff changeset
  1016
	if (GB(p2, 8, 8) >= GetNumStationClasses()) return CMD_ERROR;
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1017
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1018
	/* Check if we can allocate a custom stationspec to this station */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1019
	const StationSpec *statspec = GetCustomStationSpec((StationClassID)GB(p2, 8, 8), GB(p2, 16, 8));
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1020
	int specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC);
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1021
	if (specindex == -1) return CMD_ERROR;
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1022
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1023
	if (statspec != NULL) {
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1024
		/* Perform NewStation checks */
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1025
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1026
		/* Check if the station size is permitted */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1027
		if (HasBit(statspec->disallowed_platforms, numtracks - 1) || HasBit(statspec->disallowed_lengths, plat_len - 1)) {
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1028
			return CMD_ERROR;
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1029
		}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1030
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1031
		/* Check if the station is buildable */
9020
8174bbda9abe (svn r12819) -Codechange: handle more NewGRFs in the same way as TTDP does it, i.e. testing the low bits for 0xFF or 0 instead of all bits.
rubidium
parents: 9005
diff changeset
  1032
		if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1033
			return CMD_ERROR;
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1034
		}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1035
	}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1036
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
	if (flags & DC_EXEC) {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1038
		TileIndexDiff tile_delta;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
		byte *layout_ptr;
3769
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1040
		byte numtracks_orig;
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1041
		Track track;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1043
		/* Now really clear the land below the station
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1044
		 * It should never return CMD_ERROR.. but you never know ;)
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1045
		 * (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1046
		ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1047
		if (CmdFailed(ret)) return ret;
313
0c7cac001d1a (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
  1048
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
		st->train_tile = finalvalues[0];
5721
fa4e587f59f5 (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: 5718
diff changeset
  1050
		st->AddFacility(FACIL_TRAIN, finalvalues[0]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
		st->trainst_w = finalvalues[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
		st->trainst_h = finalvalues[2];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1054
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1055
		st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
5395
7727da322d66 (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: 5385
diff changeset
  1056
9003
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1057
		if (statspec != NULL) {
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1058
			/* Include this station spec's animation trigger bitmask
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1059
			 * in the station's cached copy. */
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1060
			st->cached_anim_triggers |= statspec->anim_triggers;
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1061
		}
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1062
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
  1063
		tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
  1064
		track = AxisToTrack(axis);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1065
9488
963e9e278125 (svn r13456) -Codechange: use AllocaM() macro instead of alloca() at most places
smatz
parents: 9413
diff changeset
  1066
		layout_ptr = AllocaM(byte, numtracks * plat_len);
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1067
		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
  1068
3769
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1069
		numtracks_orig = numtracks;
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1070
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1071
		SmallVector<Vehicle*, 4> affected_vehicles;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
		do {
1775
548dc04d50e2 (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
  1073
			TileIndex tile = tile_org;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
			int w = plat_len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
			do {
3769
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1076
				byte layout = *layout_ptr++;
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1077
				if (IsRailwayStationTile(tile) && GetRailwayStationReservation(tile)) {
9875
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1078
					/* Check for trains having a reservation for this tile. */
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1079
					Vehicle *v = GetTrainForReservation(tile, AxisToTrack(GetRailStationAxis(tile)));
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1080
					if (v != NULL) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1081
						FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1082
						*affected_vehicles.Append() = v;
9874
6d3b42eab489 (svn r14021) -Fix (r13957) [YAPP]: Overbuilding station tiles with non-track tiles could produce stale reservations. (michi_cc)
smatz
parents: 9852
diff changeset
  1083
						if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(GetVehicleTrackdir(v)), false);
6d3b42eab489 (svn r14021) -Fix (r13957) [YAPP]: Overbuilding station tiles with non-track tiles could produce stale reservations. (michi_cc)
smatz
parents: 9852
diff changeset
  1084
						for (; v->Next() != NULL; v = v->Next()) ;
6d3b42eab489 (svn r14021) -Fix (r13957) [YAPP]: Overbuilding station tiles with non-track tiles could produce stale reservations. (michi_cc)
smatz
parents: 9852
diff changeset
  1085
						if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(GetVehicleTrackdir(v))), false);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1086
					}
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1087
				}
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1088
6556
404da976ca9a (svn r9758) -Fix (FS#756): Ignore bit 1 (axis) of station tile layouts
peter1138
parents: 6500
diff changeset
  1089
				MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p2, 0, 4));
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1090
				SetCustomStationSpecIndex(tile, specindex);
3742
c5ef7a92daa5 (svn r4724) - Newstations: Add per-tile random data for station tiles.
peter1138
parents: 3741
diff changeset
  1091
				SetStationTileRandomBits(tile, GB(Random(), 0, 4));
9003
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1092
				SetStationAnimationFrame(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1094
				if (statspec != NULL) {
3784
213a1a3f8697 (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
  1095
					/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
213a1a3f8697 (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
  1096
					uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false);
7864
1380a814e4e0 (svn r11414) -Fix [FS#1387]: when building a station, even though we already 'know' it in memory, it should still be unknown in the realm of callbacks.
rubidium
parents: 7857
diff changeset
  1097
1380a814e4e0 (svn r11414) -Fix [FS#1387]: when building a station, even though we already 'know' it in memory, it should still be unknown in the realm of callbacks.
rubidium
parents: 7857
diff changeset
  1098
					/* As the station is not yet completely finished, the station does not yet exist. */
1380a814e4e0 (svn r11414) -Fix [FS#1387]: when building a station, even though we already 'know' it in memory, it should still be unknown in the realm of callbacks.
rubidium
parents: 7857
diff changeset
  1099
					uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, NULL, tile);
6556
404da976ca9a (svn r9758) -Fix (FS#756): Ignore bit 1 (axis) of station tile layouts
peter1138
parents: 6500
diff changeset
  1100
					if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis);
9003
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1101
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1102
					/* Trigger station animation -- after building? */
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1103
					StationAnimationTrigger(st, tile, STAT_ANIM_BUILT);
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1104
				}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1105
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
				tile += tile_delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
			} while (--w);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1108
			AddTrackToSignalBuffer(tile_org, track, _current_company);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1109
			YapfNotifyTrackLayoutChange(tile_org, track);
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1110
			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
  1111
		} while (--numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1113
		for (uint i = 0; i < affected_vehicles.Length(); ++i) {
9875
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1114
			/* Restore reservations of trains. */
9874
6d3b42eab489 (svn r14021) -Fix (r13957) [YAPP]: Overbuilding station tiles with non-track tiles could produce stale reservations. (michi_cc)
smatz
parents: 9852
diff changeset
  1115
			Vehicle *v = affected_vehicles[i];
6d3b42eab489 (svn r14021) -Fix (r13957) [YAPP]: Overbuilding station tiles with non-track tiles could produce stale reservations. (michi_cc)
smatz
parents: 9852
diff changeset
  1116
			if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(GetVehicleTrackdir(v)), true);
9875
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1117
			TryPathReserve(v, true, true);
9874
6d3b42eab489 (svn r14021) -Fix (r13957) [YAPP]: Overbuilding station tiles with non-track tiles could produce stale reservations. (michi_cc)
smatz
parents: 9852
diff changeset
  1118
			for (; v->Next() != NULL; v = v->Next()) ;
6d3b42eab489 (svn r14021) -Fix (r13957) [YAPP]: Overbuilding station tiles with non-track tiles could produce stale reservations. (michi_cc)
smatz
parents: 9852
diff changeset
  1119
			if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(GetVehicleTrackdir(v))), true);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1120
		}
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1121
6823
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6761
diff changeset
  1122
		st->MarkTilesDirty(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
		UpdateStationAcceptance(st, false);
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
  1125
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  1126
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
static void MakeRailwayStationAreaSmaller(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
	uint w = st->trainst_w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
	uint h = st->trainst_h;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1136
	TileIndex tile = st->train_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
restart:
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1139
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1140
	/* too small? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	if (w != 0 && h != 0) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1142
		/* check the left side, x = constant, y changes */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1143
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1144
			/* the left side is unused? */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1145
			if (++i == h) {
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1146
				tile += TileDiffXY(1, 0);
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1147
				w--;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1148
				goto restart;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1149
			}
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1150
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1152
		/* check the right side, x = constant, y changes */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1153
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1154
			/* the right side is unused? */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1155
			if (++i == h) {
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1156
				w--;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1157
				goto restart;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1158
			}
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1159
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1161
		/* check the upper side, y = constant, x changes */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1162
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1163
			/* the left side is unused? */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1164
			if (++i == w) {
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1165
				tile += TileDiffXY(0, 1);
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1166
				h--;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1167
				goto restart;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1168
			}
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1169
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1171
		/* check the lower side, y = constant, x changes */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1172
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1173
			/* the left side is unused? */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1174
			if (++i == w) {
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1175
				h--;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1176
				goto restart;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1177
			}
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1178
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
		tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
	st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
	st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
	st->train_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1188
/** Remove a single tile from a railroad station.
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1189
 * This allows for custom-built station with holes and weird layouts
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1190
 * @param tile tile of station piece to remove
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6463
diff changeset
  1191
 * @param flags operation to perform
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1192
 * @param p1 start_tile
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1193
 * @param p2 unused
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1194
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  1195
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
  1196
{
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1197
	TileIndex start = p1 == 0 ? tile : p1;
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1198
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1199
	/* Count of the number of tiles removed */
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1200
	int quantity = 0;
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1201
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1202
	if (tile >= MapSize() || start >= MapSize()) return CMD_ERROR;
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1203
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1204
	/* make sure sx,sy are smaller than ex,ey */
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1205
	int ex = TileX(tile);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1206
	int ey = TileY(tile);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1207
	int sx = TileX(start);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1208
	int sy = TileY(start);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1209
	if (ex < sx) Swap(ex, sx);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1210
	if (ey < sy) Swap(ey, sy);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1211
	tile = TileXY(sx, sy);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1212
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1213
	int size_x = ex - sx + 1;
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1214
	int size_y = ey - sy + 1;
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1215
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1216
	/* Do the action for every tile into the area */
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1217
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
8010
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1218
		/* Make sure the specified tile is a railroad station */
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1219
		if (!IsTileType(tile2, MP_STATION) || !IsRailwayStation(tile2)) {
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1220
			continue;
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1221
		}
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1222
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1223
		/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1224
		if (!EnsureNoVehicleOnGround(tile2)) {
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1225
			continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
		}
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1227
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1228
		/* Check ownership of station */
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1229
		Station *st = GetStationByTile(tile2);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1230
		if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1231
			continue;
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1232
		}
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1233
8010
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1234
		/* Do not allow removing from stations if non-uniform stations are not enabled
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1235
		 * The check must be here to give correct error message
8970
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
  1236
		 */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1237
		if (!_settings_game.station.nonuniform_stations) return_cmd_error(STR_NONUNIFORM_STATIONS_DISALLOWED);
8010
362ba0e81391 (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 7954
diff changeset
  1238
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1239
		/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1240
		quantity++;
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1241
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1242
		if (flags & DC_EXEC) {
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8296
diff changeset
  1243
			/* read variables before the station tile is removed */
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1244
			uint specindex = GetCustomStationSpecIndex(tile2);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1245
			Track track = GetRailStationTrack(tile2);
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8296
diff changeset
  1246
			Owner owner = GetTileOwner(tile2);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1247
			Vehicle *v = NULL;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1248
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1249
			if (GetRailwayStationReservation(tile2)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1250
				v = GetTrainForReservation(tile2, track);
9875
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1251
				if (v != NULL) {
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1252
					/* Free train reservation. */
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1253
					FreeTrainTrackReservation(v);
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1254
					if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(GetVehicleTrackdir(v)), false);
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1255
					Vehicle *temp = v;
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1256
					for (; temp->Next() != NULL; temp = temp->Next()) ;
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1257
					if (IsRailwayStationTile(temp->tile)) SetRailwayStationPlatformReservation(temp->tile, TrackdirToExitdir(ReverseTrackdir(GetVehicleTrackdir(temp))), false);
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1258
				}
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1259
			}
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8296
diff changeset
  1260
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1261
			DoClearSquare(tile2);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1262
			st->rect.AfterRemoveTile(st, tile2);
8306
22e1344c5457 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8302
diff changeset
  1263
			AddTrackToSignalBuffer(tile2, track, owner);
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1264
			YapfNotifyTrackLayoutChange(tile2, track);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1265
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1266
			DeallocateSpecFromStation(st, specindex);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1267
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1268
			/* now we need to make the "spanned" area of the railway station smaller
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1269
			 * if we deleted something at the edges.
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1270
			 * we also need to adjust train_tile. */
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1271
			MakeRailwayStationAreaSmaller(st);
6823
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6761
diff changeset
  1272
			st->MarkTilesDirty(false);
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1273
			UpdateStationSignCoord(st);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1274
9875
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1275
			if (v != NULL) {
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1276
				/* Restore station reservation. */
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1277
				if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(GetVehicleTrackdir(v)), true);
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1278
				TryPathReserve(v, true, true);
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1279
				for (; v->Next() != NULL; v = v->Next()) ;
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1280
				if (IsRailwayStationTile(v->tile)) SetRailwayStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(GetVehicleTrackdir(v))), true);
1de23b426e64 (svn r14022) -Fix (r13957) [YAPP]: Removing station tiles could produce stale reservations, too. (michi_cc)
smatz
parents: 9874
diff changeset
  1281
			}
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1282
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1283
			/* if we deleted the whole station, delete the train facility. */
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1284
			if (st->train_tile == 0) {
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1285
				st->facilities &= ~FACIL_TRAIN;
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  1286
				InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
6596
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1287
				UpdateStationVirtCoordDirty(st);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1288
				DeleteStationIfEmpty(st);
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1289
			}
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1290
		}
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1291
	} END_TILE_LOOP(tile2, size_x, size_y, tile)
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1292
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1293
	/* If we've not removed any tiles, give an error */
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1294
	if (quantity == 0) return CMD_ERROR;
f200c4895149 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 6556
diff changeset
  1295
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  1296
	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
  1297
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
3928
53fe96558353 (svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents: 3900
diff changeset
  1299
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  1300
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
  1301
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1302
	/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1303
	if (_current_company == OWNER_WATER && _settings_game.station.nonuniform_stations) {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1304
		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1305
	}
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1306
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1307
	/* Current company owns the station? */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1308
	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
	/* determine width and height of platforms */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
	tile = st->train_tile;
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1312
	int w = st->trainst_w;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1313
	int h = st->trainst_h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1314
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
	assert(w != 0 && h != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  1317
	CommandCost cost(EXPENSES_CONSTRUCTION);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
	/* clear all areas of the station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
		int w_bak = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
		do {
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8296
diff changeset
  1322
			/* for nonuniform stations, only remove tiles that are actually train station tiles */
5665
d6b5c720ad67 (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: 5660
diff changeset
  1323
			if (st->TileBelongsToRailStation(tile)) {
7758
17ad53748c7b (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 7739
diff changeset
  1324
				if (!EnsureNoVehicleOnGround(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
					return CMD_ERROR;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1326
				cost.AddCost(_price.remove_rail_station);
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1327
				if (flags & DC_EXEC) {
8300
dfd530665621 (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8296
diff changeset
  1328
					/* read variables before the station tile is removed */
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1329
					Track track = GetRailStationTrack(tile);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1330
					Owner owner = GetTileOwner(tile); // _current_company can be OWNER_WATER
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1331
					Vehicle *v = NULL;
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1332
					if (GetRailwayStationReservation(tile)) {
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1333
						v = GetTrainForReservation(tile, track);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1334
						if (v != NULL) FreeTrainTrackReservation(v);
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1335
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
					DoClearSquare(tile);
8306
22e1344c5457 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8302
diff changeset
  1337
					AddTrackToSignalBuffer(tile, track, owner);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1338
					YapfNotifyTrackLayoutChange(tile, track);
9815
69440bf2a2e0 (svn r13957) -Codechange [YAPP]: Free the old path reservation on removing some tracks and reroute trains afterwards. (michi_cc)
rubidium
parents: 9785
diff changeset
  1339
					if (v != NULL) TryPathReserve(v, true);
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1340
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
			}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1342
			tile += TileDiffXY(1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
		} while (--w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
		w = w_bak;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1345
		tile += TileDiffXY(-w, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
	} while (--h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
	if (flags & DC_EXEC) {
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1349
		st->rect.AfterRemoveRect(st, st->train_tile, st->trainst_w, st->trainst_h);
5395
7727da322d66 (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: 5385
diff changeset
  1350
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
		st->train_tile = 0;
5395
7727da322d66 (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: 5385
diff changeset
  1352
		st->trainst_w = st->trainst_h = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
		st->facilities &= ~FACIL_TRAIN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1355
		free(st->speclist);
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1356
		st->num_specs = 0;
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1357
		st->speclist  = NULL;
9003
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  1358
		st->cached_anim_triggers = 0;
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1359
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  1360
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1364
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
6368
c58210a58402 (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: 6357
diff changeset
  1368
/**
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
  1369
 * @param truck_station Determines whether a stop is ROADSTOP_BUS or ROADSTOP_TRUCK
6488
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6484
diff changeset
  1370
 * @param st The Station to do the whole procedure for
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1371
 * @return a pointer to where to link a new RoadStop*
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
  1372
 */
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1373
static RoadStop **FindRoadStopSpot(bool truck_station, Station *st)
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1374
{
3691
56dfcf599c3f (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1375
	RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1376
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1377
	if (*primary_stop == NULL) {
6488
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6484
diff changeset
  1378
		/* we have no roadstop of the type yet, so write a "primary stop" */
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1379
		return primary_stop;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1380
	} else {
6488
b6c42e91bb35 (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6484
diff changeset
  1381
		/* there are stops already, so append to the end of the list */
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1382
		RoadStop *stop = *primary_stop;
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1383
		while (stop->next != NULL) stop = stop->next;
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1384
		return &stop->next;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1385
	}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1386
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1387
3691
56dfcf599c3f (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1388
/** Build a bus or truck stop
56dfcf599c3f (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1389
 * @param tile tile to build the stop at
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6463
diff changeset
  1390
 * @param flags operation to perform
3333
5feb21487332 (svn r4111) Fix/Remove some stale comments
tron
parents: 3315
diff changeset
  1391
 * @param p1 entrance direction (DiagDirection)
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1392
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1393
 *           bit 1: 0 for normal, 1 for drive-through
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6596
diff changeset
  1394
 *           bit 2..4: the roadtypes
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1395
 *           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
  1396
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  1397
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
  1398
{
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1399
	bool type = HasBit(p2, 0);
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1400
	bool is_drive_through = HasBit(p2, 1);
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8520
diff changeset
  1401
	bool build_over_road  = is_drive_through && IsNormalRoadTile(tile);
9341
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9334
diff changeset
  1402
	bool town_owned_road  = false;
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6596
diff changeset
  1403
	RoadTypes rts = (RoadTypes)GB(p2, 2, 3);
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6596
diff changeset
  1404
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1405
	if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1406
6677
8120427efe01 (svn r9908) -Codechange: prepare the station picker for more road types.
rubidium
parents: 6674
diff changeset
  1407
	/* Trams only have drive through stops */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1408
	if (!is_drive_through && HasBit(rts, ROADTYPE_TRAM)) return CMD_ERROR;
6677
8120427efe01 (svn r9908) -Codechange: prepare the station picker for more road types.
rubidium
parents: 6674
diff changeset
  1409
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1410
	/* Saveguard the parameters */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1411
	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1412
	/* If it is a drive-through stop check for valid axis */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1413
	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
6018
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1414
	/* Road bits in the wrong direction */
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6596
diff changeset
  1415
	if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION);
6703
fdb8d05ce28f (svn r9935) -Fix: could not build a drive through station when there when you own the tram bits and the town owns the road.
rubidium
parents: 6691
diff changeset
  1416
fdb8d05ce28f (svn r9935) -Fix: could not build a drive through station when there when you own the tram bits and the town owns the road.
rubidium
parents: 6691
diff changeset
  1417
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
fdb8d05ce28f (svn r9935) -Fix: could not build a drive through station when there when you own the tram bits and the town owns the road.
rubidium
parents: 6691
diff changeset
  1418
10124
089100e22a6a (svn r14308) -Fix [FS#2268]: pay extra when tram/road bits need to be build for a roadstop.
rubidium
parents: 10123
diff changeset
  1419
	RoadTypes cur_rts = IsNormalRoadTile(tile) ? GetRoadTypes(tile) : ROADTYPES_NONE;
089100e22a6a (svn r14308) -Fix [FS#2268]: pay extra when tram/road bits need to be build for a roadstop.
rubidium
parents: 10123
diff changeset
  1420
	uint num_roadbits = 0;
6018
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1421
	/* Not allowed to build over this road */
6402
f15c50d74932 (svn r9532) -Fix (r8741) [FS#708]: Make errors when building drive through road stops more descriptive.
maedhros
parents: 6394
diff changeset
  1422
	if (build_over_road) {
8377
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1423
		/* there is a road, check if we can build road+tram stop over it */
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1424
		if (HasBit(cur_rts, ROADTYPE_ROAD)) {
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1425
			Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
9341
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9334
diff changeset
  1426
			if (road_owner == OWNER_TOWN) {
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9334
diff changeset
  1427
				town_owned_road = true;
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1428
				if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
9341
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9334
diff changeset
  1429
			} else {
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9334
diff changeset
  1430
				if (road_owner != OWNER_NONE && !CheckOwnership(road_owner)) return CMD_ERROR;
bd60c3b2d1e0 (svn r13233) -Fix: Replace some (incorrect) evaluations of TileOwner by RoadOwner.
frosch
parents: 9334
diff changeset
  1431
			}
10124
089100e22a6a (svn r14308) -Fix [FS#2268]: pay extra when tram/road bits need to be build for a roadstop.
rubidium
parents: 10123
diff changeset
  1432
			num_roadbits += CountBits(GetRoadBits(tile, ROADTYPE_ROAD));
8377
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1433
		}
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1434
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1435
		/* there is a tram, check if we can build road+tram stop over it */
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1436
		if (HasBit(cur_rts, ROADTYPE_TRAM)) {
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1437
			Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1438
			if (tram_owner != OWNER_NONE && !CheckOwnership(tram_owner)) return CMD_ERROR;
10124
089100e22a6a (svn r14308) -Fix [FS#2268]: pay extra when tram/road bits need to be build for a roadstop.
rubidium
parents: 10123
diff changeset
  1439
			num_roadbits += CountBits(GetRoadBits(tile, ROADTYPE_TRAM));
8377
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1440
		}
23835ad7ab64 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8306
diff changeset
  1441
6761
43c0425f9290 (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 6733
diff changeset
  1442
		/* Don't allow building the roadstop when vehicles are already driving on it */
43c0425f9290 (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 6733
diff changeset
  1443
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
43c0425f9290 (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 6733
diff changeset
  1444
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6596
diff changeset
  1445
		/* Do not remove roadtypes! */
6703
fdb8d05ce28f (svn r9935) -Fix: could not build a drive through station when there when you own the tram bits and the town owns the road.
rubidium
parents: 6691
diff changeset
  1446
		rts |= cur_rts;
6402
f15c50d74932 (svn r9532) -Fix (r8741) [FS#708]: Make errors when building drive through road stops more descriptive.
maedhros
parents: 6394
diff changeset
  1447
	}
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1448
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1449
	CommandCost cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road);
6719
70e750141e56 (svn r9951) -Fix: slope check was incomplete when building road over tram track (and vice-versa)
glx
parents: 6703
diff changeset
  1450
	if (CmdFailed(cost)) return cost;
10124
089100e22a6a (svn r14308) -Fix [FS#2268]: pay extra when tram/road bits need to be build for a roadstop.
rubidium
parents: 10123
diff changeset
  1451
	uint roadbits_to_build = CountBits(rts) * 2 - num_roadbits;
089100e22a6a (svn r14308) -Fix [FS#2268]: pay extra when tram/road bits need to be build for a roadstop.
rubidium
parents: 10123
diff changeset
  1452
	cost.AddCost(_price.build_road * roadbits_to_build);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1454
	Station *st = NULL;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1455
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1456
	if (!_settings_game.station.adjacent_stations || !HasBit(p2, 5)) {
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1457
		st = GetStationAround(tile, 1, 1, INVALID_STATION);
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1458
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1459
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
	/* Find a station close to us */
6052
ed3d260a32bc (svn r8782) -Fix
tron
parents: 6051
diff changeset
  1462
	if (st == NULL) st = GetClosestStationFromTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1464
	/* give us a road stop in the list, and check if something went wrong */
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1465
	if (!RoadStop::CanAllocateItem()) return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
5833
a0abc408c0bb (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: 5721
diff changeset
  1466
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  1467
	if (st != NULL &&
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
  1468
			GetNumRoadStopsInStation(st, ROADSTOP_BUS) + GetNumRoadStopsInStation(st, ROADSTOP_TRUCK) >= RoadStop::LIMIT) {
8424
c3477565c975 (svn r11994) -Codechange: Remove numbers from string names where the strings aren't present in TTD, since they don't correspond to either TTD's TextIDs or OpenTTD's StringIDs.
maedhros
parents: 8413
diff changeset
  1469
		return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1470
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1471
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
	if (st != NULL) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1473
		if (st->owner != _current_company) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1475
		}
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1476
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1477
		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
  1478
	} else {
5665
d6b5c720ad67 (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: 5660
diff changeset
  1479
		/* allocate and initialize new station */
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1480
		if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1481
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1482
		if (flags & DC_EXEC) {
9063
005b0643381c (svn r12915) -Fix [FS#1960](r12857): don't initialize Station struct with tile=0, buoys will never change that value
smatz
parents: 9055
diff changeset
  1483
			st = new Station(tile);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1484
9049
21f20d9bc849 (svn r12875) -Codechange: Use defined const instead of cast magic
belugas
parents: 9048
diff changeset
  1485
			st->town = ClosestTownFromTile(tile, UINT_MAX);
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
  1486
			st->string_id = GenerateStationName(st, tile, STATIONNAMING_ROAD);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1487
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1488
			if (IsValidCompanyID(_current_company)) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1489
				SetBit(st->town->have_ratings, _current_company);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1490
			}
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1491
			st->sign.width_1 = 0;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1492
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1495
	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
  1496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
	if (flags & DC_EXEC) {
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1498
		RoadStop *road_stop = new RoadStop(tile);
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1499
		/* Insert into linked list of RoadStops */
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1500
		RoadStop **currstop = FindRoadStopSpot(type, st);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1501
		*currstop = road_stop;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1502
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1503
		/*initialize an empty station */
5721
fa4e587f59f5 (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: 5718
diff changeset
  1504
		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
  1505
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1506
		st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
5395
7727da322d66 (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: 5385
diff changeset
  1507
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
  1508
		RoadStopType rs_type = type ? ROADSTOP_TRUCK : ROADSTOP_BUS;
6098
07544f189e9d (svn r8833) -Fix
tron
parents: 6093
diff changeset
  1509
		if (is_drive_through) {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6596
diff changeset
  1510
			MakeDriveThroughRoadStop(tile, st->owner, st->index, rs_type, rts, (Axis)p1, town_owned_road);
6098
07544f189e9d (svn r8833) -Fix
tron
parents: 6093
diff changeset
  1511
		} else {
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6596
diff changeset
  1512
			MakeRoadStop(tile, st->owner, st->index, rs_type, rts, (DiagDirection)p1);
6098
07544f189e9d (svn r8833) -Fix
tron
parents: 6093
diff changeset
  1513
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
		UpdateStationAcceptance(st, false);
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
  1517
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  1518
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1523
9775
22e256c3bf46 (svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium
parents: 9721
diff changeset
  1524
static Vehicle *ClearRoadStopStatusEnum(Vehicle *v, void *)
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1525
{
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1526
	if (v->type == VEH_ROAD) ClrBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1527
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1528
	return NULL;
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1529
}
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1530
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1531
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1532
/** Remove a bus station
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1533
 * @param st Station to remove
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1534
 * @param flags operation to perform
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1535
 * @param tile TileIndex been queried
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1536
 * @return cost or failure of operation
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1537
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  1538
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
  1539
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1540
	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
		return CMD_ERROR;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1542
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1544
	bool is_truck = IsTruckStop(tile);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1545
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1546
	RoadStop **primary_stop;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1547
	RoadStop *cur_stop;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1548
	if (is_truck) { // truck stop
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1549
		primary_stop = &st->truck_stops;
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
  1550
		cur_stop = GetRoadStopByTile(tile, ROADSTOP_TRUCK);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1551
	} else {
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1552
		primary_stop = &st->bus_stops;
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
  1553
		cur_stop = GetRoadStopByTile(tile, ROADSTOP_BUS);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1554
	}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1555
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1556
	assert(cur_stop != NULL);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1557
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1558
	/* don't do the check for drive-through road stops when company bankrupts */
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1559
	if (IsDriveThroughStopTile(tile) && (flags & DC_BANKRUPT)) {
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1560
		/* remove the 'going through road stop' status from all vehicles on that tile */
10083
eee4e42aa15b (svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium
parents: 9914
diff changeset
  1561
		if (flags & DC_EXEC) FindVehicleOnPos(tile, NULL, &ClearRoadStopStatusEnum);
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1562
	} else {
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1563
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  1564
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
	if (flags & DC_EXEC) {
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1567
		if (*primary_stop == cur_stop) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1568
			/* removed the first stop in the list */
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1569
			*primary_stop = cur_stop->next;
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1570
			/* removed the only stop? */
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1571
			if (*primary_stop == NULL) {
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1572
				st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP);
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1573
			}
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1574
		} else {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1575
			/* tell the predecessor in the list to skip this stop */
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1576
			RoadStop *pred = *primary_stop;
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1577
			while (pred->next != cur_stop) pred = pred->next;
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1578
			pred->next = cur_stop->next;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1579
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  1581
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
5708
4c4c5ec2bed6 (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: 5697
diff changeset
  1582
		delete cur_stop;
10223
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1583
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1584
		/* Make sure no vehicle is going to the old roadstop */
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1585
		Vehicle *v;
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1586
		FOR_ALL_VEHICLES(v) {
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1587
			if (v->type == VEH_ROAD &&
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1588
					v->First() == v &&
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1589
					v->current_order.IsType(OT_GOTO_STATION) &&
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1590
					v->dest_tile == tile) {
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1591
				v->dest_tile = v->GetOrderStationLocation(st->index);
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1592
			}
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1593
		}
8d2248c63c4d (svn r14446) -Fix [FS#2330]: when a road stop gets moved make sure to update the destination of RVs going to that road stop.
rubidium
parents: 10207
diff changeset
  1594
4398
9232bcc7422a (svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents: 4397
diff changeset
  1595
		DoClearSquare(tile);
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1596
		st->rect.AfterRemoveTile(st, tile);
4398
9232bcc7422a (svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents: 4397
diff changeset
  1597
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  1602
	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
  1603
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1605
/** Remove a bus or truck stop
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1606
 * @param tile tile to remove the stop from
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6463
diff changeset
  1607
 * @param flags operation to perform
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1608
 * @param p1 not used
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1609
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1610
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  1611
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1612
{
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1613
	/* Make sure the specified tile is a road stop of the correct type */
9494
dc3c14edbc62 (svn r13472) -Backport (r13467 from NoAI): make CmdRemoveRoadStop use p2 as documented (only look at bit 0, not at the complete value)
glx
parents: 9488
diff changeset
  1614
	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != GB(p2, 0, 1)) return CMD_ERROR;
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1615
	Station *st = GetStationByTile(tile);
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1616
	/* Save the stop info before it is removed */
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1617
	bool is_drive_through = IsDriveThroughStopTile(tile);
6661
1716fce5ad29 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 6596
diff changeset
  1618
	RoadTypes rts = GetRoadTypes(tile);
6664
aed6a5b1c992 (svn r9895) -Fix: assertion when removing roadstop.
rubidium
parents: 6662
diff changeset
  1619
	RoadBits road_bits = IsDriveThroughStopTile(tile) ?
aed6a5b1c992 (svn r9895) -Fix: assertion when removing roadstop.
rubidium
parents: 6662
diff changeset
  1620
			((GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) :
aed6a5b1c992 (svn r9895) -Fix: assertion when removing roadstop.
rubidium
parents: 6662
diff changeset
  1621
			DiagDirToRoadBits(GetRoadStopDir(tile));
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1622
	bool is_towns_road = is_drive_through && GetStopBuiltOnTownRoad(tile);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1623
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  1624
	CommandCost ret = RemoveRoadStop(st, flags, tile);
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1625
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1626
	/* If the stop was a drive-through stop replace the road */
6946
a48b23f1cc8a (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 6943
diff changeset
  1627
	if ((flags & DC_EXEC) && CmdSucceeded(ret) && is_drive_through) {
6733
733f7bbba1fb (svn r9965) -Fix: the ownership of drive through road stops on town owned roads wasn't properly reset when the road stop was removed.
rubidium
parents: 6720
diff changeset
  1628
		/* Rebuild the drive throuhg road stop. As a road stop can only be
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1629
		 * removed by the owner of the roadstop, _current_company is the
6733
733f7bbba1fb (svn r9965) -Fix: the ownership of drive through road stops on town owned roads wasn't properly reset when the road stop was removed.
rubidium
parents: 6720
diff changeset
  1630
		 * owner of the road stop. */
10289
801e5451f0ca (svn r14528) -Codechange: cache the closest town for all road tiles instead of only roads owned by tiles. This replaces a O(n) search over all towns from the road's tileloop with a O(1) lookup (PhilSophus)
rubidium
parents: 10287
diff changeset
  1631
		MakeRoadNormal(tile, road_bits, rts, ClosestTownFromTile(tile, UINT_MAX)->index,
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1632
				is_towns_road ? OWNER_TOWN : _current_company, _current_company, _current_company);
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1633
	}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1634
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1635
	return ret;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1636
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1638
/* FIXME -- need to move to its corresponding Airport variable*/
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1639
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1640
/* Country Airfield (small) */
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1641
static const byte _airport_sections_country[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
	54, 53, 52, 65,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
	58, 57, 56, 55,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
	64, 63, 63, 62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1647
/* City Airport (large) */
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1648
static const byte _airport_sections_town[] = {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1649
	31,  9, 33,  9,  9, 32,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1650
	27, 36, 29, 34,  8, 10,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	30, 11, 35, 13, 20, 21,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
	51, 12, 14, 17, 19, 28,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
	38, 13, 15, 16, 18, 39,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
	26, 22, 23, 24, 25, 26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1657
/* Metropolitain Airport (large) - 2 runways */
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1658
static const byte _airport_sections_metropolitan[] = {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1659
	 31,  9, 33,  9,  9, 32,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1660
	 27, 36, 29, 34,  8, 10,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1661
	 30, 11, 35, 13, 20, 21,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1662
	102,  8,  8,  8,  8, 28,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1663
	 83, 84, 84, 84, 84, 83,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1664
	 26, 23, 23, 23, 23, 26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1667
/* International Airport (large) - 2 runways */
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1668
static const byte _airport_sections_international[] = {
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  1669
	88, 89, 89, 89, 89, 89,  88,
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  1670
	51,  8,  8,  8,  8,  8,  32,
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1671
	30,  8, 11, 27, 11,  8,  10,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
	32,  8, 11, 27, 11,  8, 114,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
	87,  8, 11, 85, 11,  8, 114,
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1674
	87,  8,  8,  8,  8,  8,  90,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1675
	26, 23, 23, 23, 23, 23,  26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1678
/* Intercontinental Airport (vlarge) - 4 runways */
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1679
static const byte _airport_sections_intercontinental[] = {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1680
	102, 120,  89,  89,  89,  89,  89,  89, 118,
6267
9e015326c7fb (svn r9076) -Fix [FS#529]: the intercontinental airport used 'T-junction' runway sprites when there is no exit in the middle of the runway as in the city airport (skidd13).
rubidium
parents: 6261
diff changeset
  1681
	120,  23,  23,  23,  23,  23,  23, 119, 117,
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1682
	 87,  54,  87,   8,   8,   8,   8,  51, 117,
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1683
	 87, 162,  87,  85, 116, 116,   8,   9,  10,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1684
	 87,   8,   8,  11,  31,  11,   8, 160,  32,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1685
	 32, 160,   8,  11,  27,  11,   8,   8,  10,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1686
	 87,   8,   8,  11,  30,  11,   8,   8,  10,
4066
2d099b946f10 (svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents: 4059
diff changeset
  1687
	 87, 142,   8,  11,  29,  11,  10, 163,  10,
2d099b946f10 (svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents: 4059
diff changeset
  1688
	 87, 164,  87,   8,   8,   8,  10,  37, 117,
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1689
	 87, 120,  89,  89,  89,  89,  89,  89, 119,
6267
9e015326c7fb (svn r9076) -Fix [FS#529]: the intercontinental airport used 'T-junction' runway sprites when there is no exit in the middle of the runway as in the city airport (skidd13).
rubidium
parents: 6261
diff changeset
  1690
	121,  23,  23,  23,  23,  23,  23, 119,  37
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1691
};
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1692
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1693
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1694
/* Commuter Airfield (small) */
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1695
static const byte _airport_sections_commuter[] = {
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1696
	85, 30, 115, 115, 32,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1697
	87, 8,    8,   8, 10,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1698
	87, 11,  11,  11, 10,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1699
	26, 23,  23,  23, 26
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1700
};
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1701
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1702
/* Heliport */
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1703
static const byte _airport_sections_heliport[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
	66,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1707
/* Helidepot */
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1708
static const byte _airport_sections_helidepot[] = {
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1709
	124, 32,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1710
	122, 123
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1711
};
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1712
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  1713
/* Helistation */
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1714
static const byte _airport_sections_helistation[] = {
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1715
	 32, 134, 159, 158,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1716
	161, 142, 142, 157
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1717
};
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1718
3471
e454e2c0c23e (svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents: 3435
diff changeset
  1719
static const byte * const _airport_sections[] = {
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1720
	_airport_sections_country,           // Country Airfield (small)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1721
	_airport_sections_town,              // City Airport (large)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1722
	_airport_sections_heliport,          // Heliport
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1723
	_airport_sections_metropolitan,      // Metropolitain Airport (large)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1724
	_airport_sections_international,     // International Airport (xlarge)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1725
	_airport_sections_commuter,          // Commuter Airport (small)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1726
	_airport_sections_helidepot,         // Helidepot
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1727
	_airport_sections_intercontinental,  // Intercontinental Airport (xxlarge)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1728
	_airport_sections_helistation        // Helistation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1731
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1732
/** Get a possible noise reduction factor based on distance from town center.
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1733
 * The further you get, the less noise you generate.
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1734
 * So all those folks at city council can now happily slee...  work in their offices
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1735
 * @param afc AirportFTAClass pointer of the class being proposed
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1736
 * @param town_tile TileIndex of town's center, the one who will receive the airport's candidature
9669
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1737
 * @param tile TileIndex of northern tile of an airport (present or to-be-built), NOT the station tile
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1738
 * @return the noise that will be generated, according to distance
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1739
 */
9669
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1740
static uint8 GetAirportNoiseLevelForTown(const AirportFTAClass *afc, TileIndex town_tile, TileIndex tile)
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1741
{
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1742
	struct TileIndexDistance {
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1743
		TileIndex index;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1744
		uint distance;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1745
	};
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1746
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1747
	/* 0 cannot be accounted, and 1 is the lowest that can be reduced from town.
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1748
	 * So no need to go any further*/
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1749
	if (afc->noise_level < 2) return afc->noise_level;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1750
9669
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1751
	uint distance;
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1752
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1753
	/* Find the airport-to-be's closest corner to the town */
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1754
	if (afc->size_x == 1 && afc->size_y == 1) {
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1755
		distance = DistanceManhattan(town_tile, tile);  // ont tile, one corner, it's THE corner
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1756
	} else {
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1757
		/* calculate manhattan distance to town of each side of the airport */
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1758
		TileIndexDistance dist[4]; ///< Array that will contain all 4 corners in TileIndex and distance
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1759
		uint min_tile = UINT_MAX;  ///< Sentinel value
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1760
		uint min_indice = 4;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1761
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1762
		/* Based on the size of the airport, establish location of each corner*/
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1763
		dist[0].index = tile; // north tile
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1764
		dist[1].index = TileAddWrap(tile, afc->size_x - 1, afc->size_y - 1);  // south tile
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1765
		dist[2].index = TileAddWrap(tile, afc->size_x - 1, 0);  // west tile
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1766
		dist[3].index = TileAddWrap(tile, 0, afc->size_y - 1); //east tile
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1767
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1768
		/* now, go and find the smallest one, thus the closest to town */
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1769
		for (uint i = 0; i < 4; i++) {
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1770
			dist[i].distance = DistanceManhattan(town_tile, dist[i].index);
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1771
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1772
			if (dist[i].distance < min_tile) {
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1773
				min_tile = dist[i].distance;  // here's a new candidate
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1774
				min_indice = i;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1775
			}
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1776
		}
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1777
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1778
		distance = dist[min_indice].distance;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1779
	}
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1780
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1781
	/* The steps for measuring noise reduction are based on the "magical" (and arbitrary) 8 base distance
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1782
	 * adding the town_council_tolerance 4 times, as a way to graduate, depending of the tolerance.
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1783
	 * Basically, it says that the less tolerant a town is, the bigger the distance before
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1784
	 * an actual decrease can be granted */
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1785
	uint8 town_tolerance_distance = 8 + (_settings_game.difficulty.town_council_tolerance * 4);
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1786
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1787
	/* now, we want to have the distance segmented using the distance judged bareable by town
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1788
	 * This will give us the coefficient of reduction the distance provides. */
9383
33dc56cea391 (svn r13293) -Fix (r13226): airport far from a town generated too much noise
smatz
parents: 9360
diff changeset
  1789
	uint noise_reduction = distance / town_tolerance_distance;
33dc56cea391 (svn r13293) -Fix (r13226): airport far from a town generated too much noise
smatz
parents: 9360
diff changeset
  1790
33dc56cea391 (svn r13293) -Fix (r13226): airport far from a town generated too much noise
smatz
parents: 9360
diff changeset
  1791
	/* If the noise reduction equals the airport noise itself, don't give it for free.
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1792
	 * Otherwise, simply reduce the airport's level. */
9383
33dc56cea391 (svn r13293) -Fix (r13226): airport far from a town generated too much noise
smatz
parents: 9360
diff changeset
  1793
	return noise_reduction >= afc->noise_level ? 1 : afc->noise_level - noise_reduction;
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1794
}
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1795
9669
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1796
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1797
/** Recalculate the noise generated by the airports of each town */
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1798
void UpdateAirportsNoise()
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1799
{
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1800
	Town *t;
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1801
	const Station *st;
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1802
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1803
	FOR_ALL_TOWNS(t) t->noise_reached = 0;
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1804
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1805
	FOR_ALL_STATIONS(st) {
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1806
		if (st->airport_tile != 0) {
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1807
			st->town->noise_reached += GetAirportNoiseLevelForTown(GetAirport(st->airport_type), st->town->xy, st->airport_tile);
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1808
		}
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1809
	}
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1810
}
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1811
da2ecea5561e (svn r13758) -Fix (r13226): always use st->airport_tile, st->xy is different in many cases
smatz
parents: 9652
diff changeset
  1812
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1813
/** Place an Airport.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1814
 * @param tile tile where airport will be built
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6463
diff changeset
  1815
 * @param flags operation to perform
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1816
 * @param p1 airport type, @see airport.h
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1817
 * @param p2 (bit 0) - allow airports directly adjacent to other airports.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  1819
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
  1820
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1821
	bool airport_upgrade = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1823
	/* Check if a valid, buildable airport was chosen for construction */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1824
	if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1825
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1826
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
		return CMD_ERROR;
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1828
	}
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1829
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1830
	Town *t = ClosestTownFromTile(tile, UINT_MAX);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1831
	const AirportFTAClass *afc = GetAirport(p1);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1832
	int w = afc->size_x;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1833
	int h = afc->size_y;
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1834
	Station *st = NULL;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  1835
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1836
	if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
5513
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1837
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1838
		return CMD_ERROR;
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1839
	}
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1840
9075
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1841
	CommandCost cost = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1842
	if (CmdFailed(cost)) return cost;
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1843
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1844
	/* Go get the final noise level, that is base noise minus factor from distance to town center */
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1845
	uint newnoise_level = GetAirportNoiseLevelForTown(afc, t->xy, tile);
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1846
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1847
	/* Check if local auth would allow a new airport */
9360
51762cddd6f2 (svn r13257) -Fix(r13226): Typo has found its way on the code... Thanks cirdan
belugas
parents: 9358
diff changeset
  1848
	bool authority_refused;
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1849
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1850
	if (_settings_game.economy.station_noise_level) {
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1851
		/* do not allow to build a new airport if this raise the town noise over the maximum allowed by town */
9360
51762cddd6f2 (svn r13257) -Fix(r13226): Typo has found its way on the code... Thanks cirdan
belugas
parents: 9358
diff changeset
  1852
		authority_refused = (t->noise_reached + newnoise_level) > t->MaxTownNoise();
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1853
	} else {
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1854
		uint num = 0;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1855
		const Station *st;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1856
		FOR_ALL_STATIONS(st) {
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1857
			if (st->town == t && st->facilities & FACIL_AIRPORT && st->airport_type != AT_OILRIG) num++;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1858
		}
9360
51762cddd6f2 (svn r13257) -Fix(r13226): Typo has found its way on the code... Thanks cirdan
belugas
parents: 9358
diff changeset
  1859
		authority_refused = (num >= 2);
9075
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1860
	}
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1861
9360
51762cddd6f2 (svn r13257) -Fix(r13226): Typo has found its way on the code... Thanks cirdan
belugas
parents: 9358
diff changeset
  1862
	if (authority_refused) {
9075
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1863
		SetDParam(0, t->index);
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1864
		return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES);
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1865
	}
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1866
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1867
	if (!_settings_game.station.adjacent_stations || !HasBit(p2, 0)) {
9075
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1868
		st = GetStationAround(tile, w, h, INVALID_STATION);
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1869
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1870
	} else {
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1871
		st = NULL;
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1872
	}
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1873
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1874
	/* Find a station close to us */
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1875
	if (st == NULL) st = GetClosestStationFromTile(tile);
05ee343edc0d (svn r12934) -Codechange: Before verification of local authority, just make sure airport can physically be built there. Just moving tests
belugas
parents: 9063
diff changeset
  1876
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
	if (st != NULL) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1878
		if (st->owner != _current_company) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1880
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1881
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1882
		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
  1883
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1884
		if (st->airport_tile != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
			return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT);
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1886
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
		airport_upgrade = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
5665
d6b5c720ad67 (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: 5660
diff changeset
  1890
		/* allocate and initialize new station */
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1891
		if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1892
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1893
		if (flags & DC_EXEC) {
9063
005b0643381c (svn r12915) -Fix [FS#1960](r12857): don't initialize Station struct with tile=0, buoys will never change that value
smatz
parents: 9055
diff changeset
  1894
			st = new Station(tile);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1895
9048
d2d1c0b4181c (svn r12874) -Codechange: The closest town is already known. Do not search for it again.
belugas
parents: 9038
diff changeset
  1896
			st->town = t;
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
  1897
			st->string_id = GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1898
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1899
			if (IsValidCompanyID(_current_company)) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1900
				SetBit(st->town->have_ratings, _current_company);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1901
			}
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  1902
			st->sign.width_1 = 0;
6049
687015af5ef8 (svn r8779) -Fix
tron
parents: 6041
diff changeset
  1903
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  1906
	cost.AddCost(_price.build_airport * w * h);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
	if (flags & DC_EXEC) {
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1909
		/* Always add the noise, so there will be no need to recalculate when option toggles */
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1910
		st->town->noise_reached += newnoise_level;
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1911
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
		st->airport_tile = tile;
5721
fa4e587f59f5 (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: 5718
diff changeset
  1913
		st->AddFacility(FACIL_AIRPORT, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
		st->airport_type = (byte)p1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
		st->airport_flags = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1916
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1917
		st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
5395
7727da322d66 (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: 5385
diff changeset
  1918
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1919
		/* if airport was demolished while planes were en-route to it, the
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1920
		 * positions can no longer be the same (v->u.air.pos), since different
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1921
		 * airports have different indexes. So update all planes en-route to this
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1922
		 * airport. Only update if
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1923
		 * 1. airport is upgraded
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1924
		 * 2. airport is added to existing station (unfortunately unavoideable)
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1925
		 */
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1926
		if (airport_upgrade) UpdateAirplanesOnNewStation(st);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1927
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
		{
3471
e454e2c0c23e (svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents: 3435
diff changeset
  1929
			const byte *b = _airport_sections[p1];
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1930
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1931
			BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  1932
				MakeAirport(tile_cur, st->owner, st->index, *b - ((*b < 67) ? 8 : 24));
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  1933
				b++;
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1934
			} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
		UpdateStationAcceptance(st, false);
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
  1939
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  1940
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1941
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1942
		if (_settings_game.economy.station_noise_level) {
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1943
			InvalidateWindow(WC_TOWN_VIEW, st->town->index);
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1944
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  1950
static CommandCost RemoveAirport(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  1952
	if (_current_company != OWNER_WATER && !CheckOwnership(st->owner)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
		return CMD_ERROR;
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1954
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1955
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1956
	TileIndex tile = st->airport_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1957
6032
fe6a454ac1ba (svn r8755) -Fix
tron
parents: 6018
diff changeset
  1958
	const AirportFTAClass *afc = st->Airport();
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1959
	int w = afc->size_x;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1960
	int h = afc->size_y;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1961
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  1962
	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
  1963
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  1964
	const Vehicle *v;
6394
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6368
diff changeset
  1965
	FOR_ALL_VEHICLES(v) {
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6368
diff changeset
  1966
		if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6368
diff changeset
  1967
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6368
diff changeset
  1968
		if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR;
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6368
diff changeset
  1969
	}
dabe045f6f14 (svn r9524) -Fix(FS#640,r8755): Implemented a "dummy" State Machine for stations who got their airport removed while there were still aircraft within the State Machine (and thus caused asserts)
celestar
parents: 6368
diff changeset
  1970
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1971
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
7652
a2048af4a7f9 (svn r11183) -Fix [FS#1249]: airports do not need to care about overflying aircraf when removing them, because if they were not in the "flying" state it can't be removed anyway.
rubidium
parents: 7645
diff changeset
  1972
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
		if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
			DeleteAnimatedTile(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
			DoClearSquare(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1977
		}
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6488
diff changeset
  1978
	} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
	if (flags & DC_EXEC) {
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  1981
		for (uint i = 0; i < afc->nof_depots; ++i) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1982
			DeleteWindowById(
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1983
				WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1984
			);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1985
		}
755
80091de50044 (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
  1986
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1987
		/* Go get the final noise level, that is base noise minus factor from distance to town center.
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1988
		 * And as for construction, always remove it, even if the patch is not set, in order to avoid the
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1989
		 * need of recalculation */
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1990
		st->town->noise_reached -= GetAirportNoiseLevelForTown(afc, st->town->xy, tile);
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1991
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1992
		st->rect.AfterRemoveRect(st, tile, w, h);
5395
7727da322d66 (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: 5385
diff changeset
  1993
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
		st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1995
		st->facilities &= ~FACIL_AIRPORT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1996
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  1997
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  1998
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  1999
		if (_settings_game.economy.station_noise_level) {
9334
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  2000
			InvalidateWindow(WC_TOWN_VIEW, st->town->index);
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  2001
		}
28ac6c8e0795 (svn r13226) -Feature: Allow to have more than only two airports per town. The number of airports is now controlled by the noise each of them generates, the distance from town's center and how tolerant the town is.
belugas
parents: 9322
diff changeset
  2002
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2007
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2008
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2009
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2010
/** Build a buoy.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  2011
 * @param tile tile where to place the bouy
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6463
diff changeset
  2012
 * @param flags operation to perform
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2013
 * @param p1 unused
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2014
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  2016
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
  2017
{
7739
0b6f3da5c083 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 7730
diff changeset
  2018
	if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
6306
2ca4e362eb9b (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6304
diff changeset
  2019
	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
  2020
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2021
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_304B_SITE_UNSUITABLE);
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2022
5665
d6b5c720ad67 (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: 5660
diff changeset
  2023
	/* allocate and initialize new station */
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2024
	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
  2025
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2026
	if (flags & DC_EXEC) {
9063
005b0643381c (svn r12915) -Fix [FS#1960](r12857): don't initialize Station struct with tile=0, buoys will never change that value
smatz
parents: 9055
diff changeset
  2027
		Station *st = new Station(tile);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2028
9049
21f20d9bc849 (svn r12875) -Codechange: Use defined const instead of cast magic
belugas
parents: 9048
diff changeset
  2029
		st->town = ClosestTownFromTile(tile, UINT_MAX);
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
  2030
		st->string_id = GenerateStationName(st, tile, STATIONNAMING_BUOY);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2031
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2032
		if (IsValidCompanyID(_current_company)) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2033
			SetBit(st->town->have_ratings, _current_company);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2034
		}
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2035
		st->sign.width_1 = 0;
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  2036
		st->dock_tile = tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
		st->facilities |= FACIL_DOCK;
1751
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  2038
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  2039
		 * braindead.. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
		st->had_vehicle_of_type |= HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2041
		st->owner = OWNER_NONE;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2042
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  2043
		st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2045
		MakeBuoy(tile, st->index, GetWaterClass(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2046
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
		UpdateStationAcceptance(st, false);
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
  2049
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  2050
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  2053
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2055
8109
a501ce9046c4 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8108
diff changeset
  2056
/**
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2057
 * Tests whether the company's vehicles have this station in orders
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2058
 * When company == INVALID_COMPANY, then check all vehicles
8109
a501ce9046c4 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8108
diff changeset
  2059
 * @param station station ID
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2060
 * @param company company ID, INVALID_COMPANY to disable the check
8109
a501ce9046c4 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8108
diff changeset
  2061
 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2062
bool HasStationInUse(StationID station, CompanyID company)
1078
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2063
{
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2064
	const Vehicle *v;
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2065
	FOR_ALL_VEHICLES(v) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2066
		if (company == INVALID_COMPANY || v->owner == company) {
1078
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2067
			const Order *order;
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2068
			FOR_VEHICLE_ORDERS(v, order) {
8840
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8836
diff changeset
  2069
				if (order->IsType(OT_GOTO_STATION) && order->GetDestination() == station) {
1078
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2070
					return true;
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2071
				}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2072
			}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2073
		}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2074
	}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2075
	return false;
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2076
}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  2077
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  2078
static CommandCost RemoveBuoy(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
{
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  2080
	/* XXX: strange stuff */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2081
	if (!IsValidCompanyID(_current_company)) return_cmd_error(INVALID_STRING_ID);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2082
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2083
	TileIndex tile = st->dock_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2085
	if (HasStationInUse(st->index, INVALID_COMPANY)) return_cmd_error(STR_BUOY_IS_IN_USE);
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  2086
	/* remove the buoy if there is a ship on tile when company goes bankrupt... */
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  2087
	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
  2088
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
		st->dock_tile = 0;
1751
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  2091
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  2092
		 * braindead.. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
		st->had_vehicle_of_type &= ~HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  2096
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  2097
5953
b40dc8f4dc69 (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: 5914
diff changeset
  2098
		/* We have to set the water tile's state to the same state as before the
b40dc8f4dc69 (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: 5914
diff changeset
  2099
		 * buoy was placed. Otherwise one could plant a buoy on a canal edge,
b40dc8f4dc69 (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: 5914
diff changeset
  2100
		 * remove it and flood the land (if the canal edge is at level 0) */
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2101
		MakeWaterKeepingClass(tile, GetTileOwner(tile));
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  2102
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2105
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  2108
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_truck_station);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2111
static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2112
	{-1,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2113
	{ 0,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2114
	{ 0,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  2115
	{ 0, -1}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
};
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2117
static const byte _dock_w_chk[4] = { 2, 1, 2, 1 };
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2118
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
  2119
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2120
/** Build a dock/haven.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  2121
 * @param tile tile where dock will be built
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6463
diff changeset
  2122
 * @param flags operation to perform
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  2123
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2124
 * @param p2 unused
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2125
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  2126
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
  2127
{
8413
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
  2128
	DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
  2129
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE);
c7f3384330a3 (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8386
diff changeset
  2130
	direction = ReverseDiagDir(direction);
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  2131
8386
bed99ec71cb0 (svn r11956) -Fix [FS#1675]: Disallow building locks and docks on rapids.
peter1138
parents: 8377
diff changeset
  2132
	/* Docks cannot be placed on rapids */
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2133
	if (IsWaterTile(tile)) return_cmd_error(STR_304B_SITE_UNSUITABLE);
8386
bed99ec71cb0 (svn r11956) -Fix [FS#1675]: Disallow building locks and docks on rapids.
peter1138
parents: 8377
diff changeset
  2134
4619
aa9747946f8e (svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents: 4559
diff changeset
  2135
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
aa9747946f8e (svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents: 4559
diff changeset
  2136
6306
2ca4e362eb9b (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6304
diff changeset
  2137
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
2ca4e362eb9b (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6304
diff changeset
  2138
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2139
	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
  2140
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2141
	TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2142
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2143
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  2144
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  2145
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2146
6306
2ca4e362eb9b (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6304
diff changeset
  2147
	if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
2ca4e362eb9b (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6304
diff changeset
  2148
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2149
	/* Get the water class of the water tile before it is cleared.*/
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2150
	WaterClass wc = GetWaterClass(tile_cur);
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2151
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2152
	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
  2153
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  2154
	tile_cur += TileOffsByDiagDir(direction);
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2155
	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
  2156
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  2157
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2158
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
	/* middle */
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  2160
	Station *st = NULL;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  2161
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  2162
	if (!_settings_game.station.adjacent_stations || !HasBit(p1, 0)) {
6674
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  2163
		st = GetStationAround(
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  2164
				tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  2165
				_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION);
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  2166
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
5d77615aeaf2 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 6664
diff changeset
  2167
	}
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
	/* Find a station close to us */
6052
ed3d260a32bc (svn r8782) -Fix
tron
parents: 6051
diff changeset
  2170
	if (st == NULL) st = GetClosestStationFromTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2171
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2172
	if (st != NULL) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2173
		if (st->owner != _current_company) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2175
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2176
10228
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
  2177
		if (!st->rect.BeforeAddRect(
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
  2178
				tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
  2179
				_dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2180
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2181
		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
  2182
	} else {
5665
d6b5c720ad67 (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: 5660
diff changeset
  2183
		/* allocate and initialize new station */
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2184
		/* allocate and initialize new station */
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2185
		if (!Station::CanAllocateItem()) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2186
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2187
		if (flags & DC_EXEC) {
9063
005b0643381c (svn r12915) -Fix [FS#1960](r12857): don't initialize Station struct with tile=0, buoys will never change that value
smatz
parents: 9055
diff changeset
  2188
			st = new Station(tile);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2189
9049
21f20d9bc849 (svn r12875) -Codechange: Use defined const instead of cast magic
belugas
parents: 9048
diff changeset
  2190
			st->town = ClosestTownFromTile(tile, UINT_MAX);
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
  2191
			st->string_id = GenerateStationName(st, tile, STATIONNAMING_DOCK);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2192
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2193
			if (IsValidCompanyID(_current_company)) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2194
				SetBit(st->town->have_ratings, _current_company);
9038
38f0f10f8cca (svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
rubidium
parents: 9033
diff changeset
  2195
			}
5665
d6b5c720ad67 (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: 5660
diff changeset
  2196
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2197
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2199
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2200
		st->dock_tile = tile;
5721
fa4e587f59f5 (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: 5718
diff changeset
  2201
		st->AddFacility(FACIL_DOCK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2202
10228
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
  2203
		st->rect.BeforeAddRect(
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
  2204
				tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
2de09b30921a (svn r14456) -Fix: Obiwan in catchment-area and station-spread of docks.
frosch
parents: 10223
diff changeset
  2205
				_dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY);
5395
7727da322d66 (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: 5385
diff changeset
  2206
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2207
		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
  2208
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2209
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2210
		UpdateStationAcceptance(st, false);
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
  2211
		InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  2212
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2213
	}
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2214
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  2215
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2216
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2217
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  2218
static CommandCost RemoveDock(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2219
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2220
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2221
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2222
	TileIndex tile1 = st->dock_tile;
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2223
	TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2224
7758
17ad53748c7b (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 7739
diff changeset
  2225
	if (!EnsureNoVehicleOnGround(tile1)) return CMD_ERROR;
17ad53748c7b (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 7739
diff changeset
  2226
	if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2227
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2228
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2229
		DoClearSquare(tile1);
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8466
diff changeset
  2230
		MakeWaterKeepingClass(tile2, st->owner);
5395
7727da322d66 (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: 5385
diff changeset
  2231
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  2232
		st->rect.AfterRemoveTile(st, tile1);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  2233
		st->rect.AfterRemoveTile(st, tile2);
5395
7727da322d66 (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: 5385
diff changeset
  2234
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  2235
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2236
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2237
		st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2238
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2239
8017
2ecf318068bb (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8016
diff changeset
  2240
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2241
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2242
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2243
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2244
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  2245
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_dock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2246
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2247
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2248
#include "table/station_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2249
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2250
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx)
3763
7098c393c172 (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
  2251
{
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2252
	return &_station_display_datas[st][gfx];
3763
7098c393c172 (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
  2253
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2254
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2255
static void DrawTile_Station(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2256
{
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2257
	const DrawTileSprites *t = NULL;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2258
	RoadTypes roadtypes;
8166
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2259
	int32 total_offset;
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2260
	int32 custom_ground_offset;
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2261
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2262
	if (IsRailwayStation(ti->tile)) {
8166
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2263
		const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2264
		roadtypes = ROADTYPES_NONE;
8166
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2265
		total_offset = rti->total_offset;
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2266
		custom_ground_offset = rti->custom_ground_offset;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2267
	} else {
8466
4e3b01d2f1c5 (svn r12036) -Fix: For station tiles, only get road types for road stops.
peter1138
parents: 8429
diff changeset
  2268
		roadtypes = IsRoadStop(ti->tile) ? GetRoadTypes(ti->tile) : ROADTYPES_NONE;
8166
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2269
		total_offset = 0;
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2270
		custom_ground_offset = 0;
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2271
	}
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2272
	uint32 relocation = 0;
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2273
	const Station *st = NULL;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2274
	const StationSpec *statspec = NULL;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2275
	Owner owner = GetTileOwner(ti->tile);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2276
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2277
	SpriteID palette;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2278
	if (IsValidCompanyID(owner)) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2279
		palette = COMPANY_SPRITE_COLOR(owner);
4227
3ff996bf3f28 (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
  2280
	} else {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2281
		/* Some stations are not owner by a company, namely oil rigs */
4227
3ff996bf3f28 (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
  2282
		palette = PALETTE_TO_GREY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2283
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2284
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2285
	/* don't show foundation for docks */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2286
	if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile))
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
  2287
		DrawFoundation(ti, FOUNDATION_LEVELED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2288
3568
c60d7aceed1a (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
  2289
	if (IsCustomStationSpecIndex(ti->tile)) {
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2290
		/* look for customization */
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2291
		st = GetStationByTile(ti->tile);
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2292
		statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2293
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2294
		if (statspec != NULL) {
3576
18fb92480771 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2295
			uint tile = GetStationGfx(ti->tile);
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2296
3751
ce6408fdb788 (svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents: 3742
diff changeset
  2297
			relocation = GetCustomStationRelocation(statspec, st, ti->tile);
3576
18fb92480771 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2298
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2299
			if (HasBit(statspec->callbackmask, CBM_STATION_SPRITE_LAYOUT)) {
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2300
				uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
4886
19d09a4386ad (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
  2301
				if (callback != CALLBACK_FAILED) tile = (callback & ~1) + GetRailStationAxis(ti->tile);
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2302
			}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2303
3576
18fb92480771 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2304
			/* Ensure the chosen tile layout is valid for this custom station */
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2305
			if (statspec->renderdata != NULL) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2306
				t = &statspec->renderdata[tile < statspec->tiles ? tile : (uint)GetRailStationAxis(ti->tile)];
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2307
			}
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2308
		}
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2309
	}
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2310
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2311
	if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationType(ti->tile)][GetStationGfx(ti->tile)];
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2312
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2313
9852
a4ff032669c6 (svn r13996) -Fix (r13845): Oilrigs from pre r13838 save games can have unknown water class.
frosch
parents: 9815
diff changeset
  2314
	if (IsBuoy(ti->tile) || IsDock(ti->tile) || (IsOilRig(ti->tile) && GetWaterClass(ti->tile) != WATER_CLASS_INVALID)) {
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2315
		if (ti->tileh == SLOPE_FLAT) {
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2316
			DrawWaterClassGround(ti);
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2317
		} else {
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2318
			assert(IsDock(ti->tile));
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2319
			TileIndex water_tile = ti->tile + TileOffsByDiagDir(GetDockDirection(ti->tile));
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2320
			WaterClass wc = GetWaterClass(water_tile);
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2321
			if (wc == WATER_CLASS_SEA) {
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2322
				DrawShoreTile(ti->tileh);
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2323
			} else {
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2324
				DrawClearLandTile(ti, 3);
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2325
			}
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2326
		}
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2327
	} else {
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  2328
		SpriteID image = t->ground.sprite;
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10353
diff changeset
  2329
		SpriteID pal   = t->ground.pal;
8496
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2330
		if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2331
			image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2332
			image += custom_ground_offset;
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2333
		} else {
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2334
			image += total_offset;
30978fb53abd (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8471
diff changeset
  2335
		}
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10353
diff changeset
  2336
		DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  2337
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  2338
		/* PBS debugging, draw reserved tracks darker */
10109
882c4c0a5788 (svn r14293) -Change: do not show PBS track reservation in the intro game
smatz
parents: 10083
diff changeset
  2339
		if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && IsRailwayStation(ti->tile) && GetRailwayStationReservation(ti->tile)) {
9785
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  2340
			const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  2341
			DrawGroundSprite(GetRailStationAxis(ti->tile) == AXIS_X ? rti->base_sprites.single_y : rti->base_sprites.single_x, PALETTE_CRASH);
2005c34d0811 (svn r13927) -Add [YAPP]: Draw reserved tracks darker, toggeld by a patch setting. (michi_cc)
rubidium
parents: 9775
diff changeset
  2342
		}
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2343
	}
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2344
9154
2c042b567165 (svn r13016) -Codechange: unify the detection if rail catenary should be drawn
smatz
parents: 9111
diff changeset
  2345
	if (IsRailwayStation(ti->tile) && HasCatenaryDrawn(GetRailType(ti->tile)) && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
3355
e414a0b104a6 (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
  2346
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2347
	if (HasBit(roadtypes, ROADTYPE_TRAM)) {
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2348
		Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2349
		DrawGroundSprite((HasBit(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2350
		DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2351
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2352
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2353
	const DrawTileSeqStruct *dtss;
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2354
	foreach_draw_tile_seq(dtss, t->seq) {
8570
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8563
diff changeset
  2355
		SpriteID image = dtss->image.sprite;
9549
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9494
diff changeset
  2356
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9494
diff changeset
  2357
		/* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9494
diff changeset
  2358
		if (IsInvisibilitySet(TO_BUILDINGS) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
41ec95418e84 (svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents: 9494
diff changeset
  2359
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2360
		if (relocation == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
8166
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2361
			image += total_offset;
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2362
		} else {
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2363
			image += relocation;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2364
		}
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2365
10355
8a930759b457 (svn r14606) -Codechange: Unify usage of PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOR in spritelayout drawing.
frosch
parents: 10353
diff changeset
  2366
		SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, palette);
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2367
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2368
		if ((byte)dtss->delta_z != 0x80) {
4230
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2369
			AddSortableSpriteToDraw(
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2370
				image, pal,
4230
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2371
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2372
				dtss->size_x, dtss->size_y,
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7320
diff changeset
  2373
				dtss->size_z, ti->z + dtss->delta_z,
8158
2946a316540b (svn r11720) -Codechange: [NewGRF] Add support for bit 30 of station tile layouts; forcing a sprite to always be opaque.
peter1138
parents: 8144
diff changeset
  2374
				!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)
4230
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2375
			);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2376
		} else {
10257
2c37b72eec95 (svn r14488) -Fix: Synchronize drawing of spritelayouts in DrawTileLayout (Houses), IndustryDrawTileLayout, DrawStationTile, DrawTile_Station and DrawTile_Track (Waypoint).
frosch
parents: 10231
diff changeset
  2377
			/* For stations and original spritelayouts delta_x and delta_y are signed */
2c37b72eec95 (svn r14488) -Fix: Synchronize drawing of spritelayouts in DrawTileLayout (Houses), IndustryDrawTileLayout, DrawStationTile, DrawTile_Station and DrawTile_Track (Waypoint).
frosch
parents: 10231
diff changeset
  2378
			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2379
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2380
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2381
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2382
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2383
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
  2384
{
8166
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2385
	int32 total_offset = 0;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2386
	SpriteID pal = COMPANY_SPRITE_COLOR(_local_company);
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2387
	const DrawTileSprites *t = &_station_display_datas[st][image];
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2388
8166
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2389
	if (railtype != INVALID_RAILTYPE) {
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2390
		const RailtypeInfo *rti = GetRailTypeInfo(railtype);
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2391
		total_offset = rti->total_offset;
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2392
	}
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2393
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  2394
	SpriteID img = t->ground.sprite;
8166
85f2a6b30fd1 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8158
diff changeset
  2395
	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
  2396
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2397
	if (roadtype == ROADTYPE_TRAM) {
8571
53c94d717e99 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 8570
diff changeset
  2398
		DrawSprite(SPR_TRAMWAY_TRAM + (t->ground.sprite == SPR_ROAD_PAVED_STRAIGHT_X ? 1 : 0), PAL_NONE, x, y);
6691
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2399
	}
f9adbb0be102 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 6683
diff changeset
  2400
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2401
	const DrawTileSeqStruct *dtss;
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2402
	foreach_draw_tile_seq(dtss, t->seq) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2403
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
8570
f50de4804ff1 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8563
diff changeset
  2404
		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
  2405
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2406
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2407
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2408
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
  2409
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2410
	return GetTileMaxZ(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2411
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2412
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
  2413
static Foundation GetFoundation_Station(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2414
{
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
  2415
	return FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2416
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2417
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2418
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2419
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2420
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2421
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2422
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2423
static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2424
{
9322
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9297
diff changeset
  2425
	td->owner[0] = GetTileOwner(tile);
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9297
diff changeset
  2426
	if (IsDriveThroughStopTile(tile) && HasTileRoadType(tile, ROADTYPE_ROAD) && GetStopBuiltOnTownRoad(tile)) {
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9297
diff changeset
  2427
		/* Display a second owner */
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9297
diff changeset
  2428
		td->owner_type[1] = STR_ROAD_OWNER;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9297
diff changeset
  2429
		td->owner[1] = OWNER_TOWN;
cf7dc39f9576 (svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents: 9297
diff changeset
  2430
	}
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2431
	td->build_date = GetStationByTile(tile)->build_date;
2049
538e73c53f54 (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
  2432
9714
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2433
	const StationSpec *spec = GetStationSpec(tile);
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2434
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2435
	if (spec != NULL) {
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2436
		td->station_class = GetStationClassName(spec->sclass);
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2437
		td->station_name = spec->name;
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2438
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2439
		if (spec->grffile != NULL) {
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2440
			const GRFConfig *gc = GetGRFConfig(spec->grffile->grfid);
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2441
			td->grf = gc->name;
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2442
		}
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2443
	}
5d785e184f2d (svn r13830) -Feature: show additional NewGRF info in the Tile Info window for stations, houses and industries
smatz
parents: 9669
diff changeset
  2444
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2445
	StringID str;
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2446
	switch (GetStationType(tile)) {
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2447
		default: NOT_REACHED();
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2448
		case STATION_RAIL:    str = STR_305E_RAILROAD_STATION; break;
3882
c2e3e12e71d6 (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2449
		case STATION_AIRPORT:
c2e3e12e71d6 (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2450
			str = (IsHangar(tile) ? STR_305F_AIRCRAFT_HANGAR : STR_3060_AIRPORT);
c2e3e12e71d6 (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2451
			break;
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2452
		case STATION_TRUCK:   str = STR_3061_TRUCK_LOADING_AREA; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2453
		case STATION_BUS:     str = STR_3062_BUS_STATION; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2454
		case STATION_OILRIG:  str = STR_4807_OIL_RIG; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2455
		case STATION_DOCK:    str = STR_3063_SHIP_DOCK; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2456
		case STATION_BUOY:    str = STR_3069_BUOY; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2457
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2458
	td->str = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2459
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2460
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2461
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2462
static TrackStatus GetTileTrackStatus_Station(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2463
{
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2464
	TrackBits trackbits = TRACK_BIT_NONE;
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2465
1032
b8094fcab4bc (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
	switch (mode) {
b8094fcab4bc (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
		case TRANSPORT_RAIL:
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2468
			if (IsRailwayStation(tile) && !IsStationTileBlocked(tile)) {
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2469
				trackbits = TrackToTrackBits(GetRailStationTrack(tile));
1032
b8094fcab4bc (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
  2470
			}
b8094fcab4bc (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
  2471
			break;
b8094fcab4bc (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
  2472
b8094fcab4bc (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
  2473
		case TRANSPORT_WATER:
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2474
			/* buoy is coded as a station, it is always on open water */
5914
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2475
			if (IsBuoy(tile)) {
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2476
				trackbits = TRACK_BIT_ALL;
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2477
				/* remove tracks that connect NE map edge */
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2478
				if (TileX(tile) == 0) trackbits &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2479
				/* remove tracks that connect NW map edge */
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2480
				if (TileY(tile) == 0) trackbits &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
5914
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2481
			}
1032
b8094fcab4bc (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;
b8094fcab4bc (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
  2483
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2484
		case TRANSPORT_ROAD:
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8574
diff changeset
  2485
			if ((GetRoadTypes(tile) & sub_mode) != 0 && IsRoadStop(tile)) {
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8574
diff changeset
  2486
				DiagDirection dir = GetRoadStopDir(tile);
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8574
diff changeset
  2487
				Axis axis = DiagDirToAxis(dir);
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8574
diff changeset
  2488
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8574
diff changeset
  2489
				if (side != INVALID_DIAGDIR) {
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2490
					if (axis != DiagDirToAxis(side) || (IsStandardRoadStopTile(tile) && dir != side)) break;
8596
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8574
diff changeset
  2491
				}
c3404405f3f5 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8574
diff changeset
  2492
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2493
				trackbits = AxisToTrackBits(axis);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2494
			}
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2495
			break;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2496
1032
b8094fcab4bc (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
  2497
		default:
b8094fcab4bc (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
  2498
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2499
	}
1032
b8094fcab4bc (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
  2500
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
  2501
	return CombineTrackStatus(TrackBitsToTrackdirBits(trackbits), TRACKDIR_BIT_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2502
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2503
2660
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2504
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2505
static void TileLoop_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2506
{
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2507
	/* FIXME -- GetTileTrackStatus_Station -> animated stationtiles
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2508
	 * hardcoded.....not good */
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2509
	switch (GetStationType(tile)) {
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2510
		case STATION_AIRPORT:
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2511
			switch (GetStationGfx(tile)) {
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2512
				case GFX_RADAR_LARGE_FIRST:
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2513
				case GFX_WINDSACK_FIRST : // for small airport
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2514
				case GFX_RADAR_INTERNATIONAL_FIRST:
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2515
				case GFX_RADAR_METROPOLITAN_FIRST:
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2516
				case GFX_RADAR_DISTRICTWE_FIRST: // radar district W-E airport
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2517
				case GFX_WINDSACK_INTERCON_FIRST : // for intercontinental airport
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2518
					AddAnimatedTile(tile);
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2519
					break;
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2520
			}
2660
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2521
			break;
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2522
8497
b986e12ddabe (svn r12072) -Fix: Make docks at sea flood neighboured tiles.
frosch
parents: 8496
diff changeset
  2523
		case STATION_DOCK:
b986e12ddabe (svn r12072) -Fix: Make docks at sea flood neighboured tiles.
frosch
parents: 8496
diff changeset
  2524
			if (GetTileSlope(tile, NULL) != SLOPE_FLAT) break; // only handle water part
b986e12ddabe (svn r12072) -Fix: Make docks at sea flood neighboured tiles.
frosch
parents: 8496
diff changeset
  2525
		/* FALL THROUGH */
7272
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2526
		case STATION_OILRIG: //(station part)
d47fc9e22d1c (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7252
diff changeset
  2527
		case STATION_BUOY:
2660
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2528
			TileLoop_Water(tile);
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2529
			break;
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2530
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2531
		default: break;
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2532
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2533
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2534
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2535
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2536
static void AnimateTile_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2537
{
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  2538
	struct AnimData {
4467
156585f085d2 (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
  2539
		StationGfx from; // first sprite
156585f085d2 (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
  2540
		StationGfx to;   // last sprite
156585f085d2 (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
  2541
		byte delay;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
  2542
	};
4467
156585f085d2 (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
  2543
156585f085d2 (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
  2544
	static const AnimData data[] = {
156585f085d2 (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
  2545
		{ GFX_RADAR_LARGE_FIRST,         GFX_RADAR_LARGE_LAST,         3 },
156585f085d2 (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
		{ GFX_WINDSACK_FIRST,            GFX_WINDSACK_LAST,            1 },
156585f085d2 (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
		{ GFX_RADAR_INTERNATIONAL_FIRST, GFX_RADAR_INTERNATIONAL_LAST, 3 },
156585f085d2 (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
		{ GFX_RADAR_METROPOLITAN_FIRST,  GFX_RADAR_METROPOLITAN_LAST,  3 },
156585f085d2 (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
		{ GFX_RADAR_DISTRICTWE_FIRST,    GFX_RADAR_DISTRICTWE_LAST,    3 },
156585f085d2 (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
		{ GFX_WINDSACK_INTERCON_FIRST,   GFX_WINDSACK_INTERCON_LAST,   1 }
156585f085d2 (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
	};
156585f085d2 (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
  2552
9003
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2553
	if (IsRailwayStation(tile)) {
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2554
		AnimateStationTile(tile);
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2555
		return;
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2556
	}
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2557
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2558
	StationGfx gfx = GetStationGfx(tile);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2559
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2560
	for (const AnimData *i = data; i != endof(data); i++) {
4467
156585f085d2 (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
  2561
		if (i->from <= gfx && gfx <= i->to) {
156585f085d2 (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
  2562
			if ((_tick_counter & i->delay) == 0) {
156585f085d2 (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
  2563
				SetStationGfx(tile, gfx < i->to ? gfx + 1 : i->from);
156585f085d2 (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
  2564
				MarkTileDirtyByTile(tile);
156585f085d2 (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
  2565
			}
156585f085d2 (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
  2566
			break;
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2567
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2568
	}
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
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  2571
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2572
static void ClickTile_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2573
{
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2574
	if (IsHangar(tile)) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2575
		ShowDepotWindow(tile, VEH_AIRCRAFT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2576
	} else {
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2577
		ShowStationViewWindow(GetStationIndex(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2578
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2579
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2580
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
  2581
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
  2582
{
8832
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2583
	StationID station_id = GetStationIndex(tile);
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2584
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2585
	if (v->type == VEH_TRAIN) {
8919
403ddceeb879 (svn r12689) -Feature: non-stop(or rather no non-stop) and via orders for road vehicles.
rubidium
parents: 8906
diff changeset
  2586
		if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2587
		if (IsRailwayStation(tile) && IsFrontEngine(v) &&
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  2588
				!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) {
8832
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2589
			DiagDirection dir = DirToDiagDir(v->direction);
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2590
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2591
			x &= 0xF;
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2592
			y &= 0xF;
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2593
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2594
			if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2595
			if (y == TILE_SIZE / 2) {
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2596
				if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
10287
e84ee4b8ba7b (svn r14526) -Fix [FS#2379]: make sure trains stop at the end of a station; a 3/8th length train did stop 2/8th of it's length too early causing a 63/8th long train not to fit in a 4 tile station.
rubidium
parents: 10273
diff changeset
  2597
				int stop = TILE_SIZE - (v->u.rail.cached_veh_length + 1) / 2;
e84ee4b8ba7b (svn r14526) -Fix [FS#2379]: make sure trains stop at the end of a station; a 3/8th length train did stop 2/8th of it's length too early causing a 63/8th long train not to fit in a 4 tile station.
rubidium
parents: 10273
diff changeset
  2598
				if (x == stop) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); /* enter station */
e84ee4b8ba7b (svn r14526) -Fix [FS#2379]: make sure trains stop at the end of a station; a 3/8th length train did stop 2/8th of it's length too early causing a 63/8th long train not to fit in a 4 tile station.
rubidium
parents: 10273
diff changeset
  2599
				if (x < stop) {
8832
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2600
					uint16 spd;
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2601
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2602
					v->vehstatus |= VS_TRAIN_SLOWING;
10287
e84ee4b8ba7b (svn r14526) -Fix [FS#2379]: make sure trains stop at the end of a station; a 3/8th length train did stop 2/8th of it's length too early causing a 63/8th long train not to fit in a 4 tile station.
rubidium
parents: 10273
diff changeset
  2603
					spd = max(0, (stop - x) * 20 - 15);
8832
6d8cc04d39a4 (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium
parents: 8806
diff changeset
  2604
					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
  2605
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2606
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2607
		}
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  2608
	} else if (v->type == VEH_ROAD) {
6076
a052ed1779e4 (svn r8809) -Fix (r8715): accidentally removed a part of an expression.
rubidium
parents: 6070
diff changeset
  2609
		if (v->u.road.state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)v->u.road.state) && v->u.road.frame == 0) {
6857
60130753e595 (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 6823
diff changeset
  2610
			if (IsRoadStop(tile) && IsRoadVehFront(v)) {
2671
2c2edd17e9cc (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2611
				/* Attempt to allocate a parking bay in a road stop */
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2612
				RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
2671
2c2edd17e9cc (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2613
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2614
				if (IsDriveThroughStopTile(tile)) {
8919
403ddceeb879 (svn r12689) -Feature: non-stop(or rather no non-stop) and via orders for road vehicles.
rubidium
parents: 8906
diff changeset
  2615
					if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;
403ddceeb879 (svn r12689) -Feature: non-stop(or rather no non-stop) and via orders for road vehicles.
rubidium
parents: 8906
diff changeset
  2616
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2617
					/* Vehicles entering a drive-through stop from the 'normal' side use first bay (bay 0). */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2618
					byte side = ((DirToDiagDir(v->direction) == ReverseDiagDir(GetRoadStopDir(tile))) == (v->u.road.overtaking == 0)) ? 0 : 1;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2619
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2620
					if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2621
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2622
					/* Check if the vehicle is stopping at this road stop */
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
  2623
					if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
8840
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8836
diff changeset
  2624
							v->current_order.GetDestination() == GetStationIndex(tile)) {
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  2625
						SetBit(v->u.road.state, RVS_IS_STOPPING);
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2626
						rs->AllocateDriveThroughBay(side);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2627
					}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2628
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2629
					/* Indicate if vehicle is using second bay. */
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  2630
					if (side == 1) SetBit(v->u.road.state, RVS_USING_SECOND_BAY);
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2631
					/* Indicate a drive-through stop */
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  2632
					SetBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2633
					return VETSB_CONTINUE;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2634
				}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2635
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2636
				/* For normal (non drive-through) road stops */
7469
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7379
diff changeset
  2637
				/* Check if station is busy or if there are no free bays or whether it is a articulated vehicle. */
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7379
diff changeset
  2638
				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
  2639
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  2640
				SetBit(v->u.road.state, RVS_IN_ROAD_STOP);
2671
2c2edd17e9cc (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2641
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2642
				/* Allocate a bay and update the road state */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2643
				uint bay_nr = rs->AllocateBay();
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5998
diff changeset
  2644
				SB(v->u.road.state, RVS_USING_SECOND_BAY, 1, bay_nr);
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2645
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2646
				/* Mark the station entrace as busy */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2647
				rs->SetEntranceBusy(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2648
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2649
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2650
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2651
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5990
diff changeset
  2652
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2653
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2654
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2655
/* this function is called for one station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2656
static void StationHandleBigTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2657
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2658
	UpdateStationAcceptance(st, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2659
5665
d6b5c720ad67 (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: 5660
diff changeset
  2660
	if (st->facilities == 0 && ++st->delete_ctr >= 8) delete st;
1239
133586622b78 (svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents: 1231
diff changeset
  2661
0
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
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2664
static inline void byte_inc_sat(byte *p)
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2665
{
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2666
	byte b = *p + 1;
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2667
	if (b != 0) *p = b;
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2668
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2669
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2670
static void UpdateStationRating(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2671
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2672
	bool waiting_changed = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2673
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2674
	byte_inc_sat(&st->time_since_load);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2675
	byte_inc_sat(&st->time_since_unload);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2676
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2677
	GoodsEntry *ge = st->goods;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2678
	do {
6261
f294962efd0d (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: 6259
diff changeset
  2679
		/* Slowly increase the rating back to his original level in the case we
f294962efd0d (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: 6259
diff changeset
  2680
		 *  didn't deliver cargo yet to this station. This happens when a bribe
f294962efd0d (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: 6259
diff changeset
  2681
		 *  failed while you didn't moved that cargo yet to a station. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2682
		if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP) && ge->rating < INITIAL_STATION_RATING) {
6261
f294962efd0d (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: 6259
diff changeset
  2683
			ge->rating++;
7474
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7469
diff changeset
  2684
		}
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7469
diff changeset
  2685
6261
f294962efd0d (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: 6259
diff changeset
  2686
		/* Only change the rating if we are moving this cargo */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2687
		if (HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2688
			byte_inc_sat(&ge->days_since_pickup);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2689
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2690
			int rating = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2691
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2692
			{
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
  2693
				int b = ge->last_speed - 85;
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
  2694
				if (b >= 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2695
					rating += b >> 2;
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
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2699
				byte age = ge->last_age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2700
				(age >= 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2701
				(rating += 10, age >= 2) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2702
				(rating += 10, age >= 1) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2703
				(rating += 13, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2704
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2705
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2706
			if (IsValidCompanyID(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
  2707
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2708
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2709
				byte days = ge->days_since_pickup;
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2710
				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
  2711
				(days > 21) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2712
				(rating += 25, days > 12) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2713
				(rating += 25, days > 6) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2714
				(rating += 45, days > 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2715
				(rating += 35, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2716
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2717
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  2718
			uint waiting = ge->cargo.Count();
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2719
			(rating -= 90, waiting > 1500) ||
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2720
			(rating += 55, waiting > 1000) ||
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2721
			(rating += 35, waiting > 600) ||
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2722
			(rating += 10, waiting > 300) ||
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2723
			(rating += 20, waiting > 100) ||
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2724
			(rating += 10, true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2725
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2726
			{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2727
				int or_ = ge->rating; // old rating
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2728
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2729
				/* only modify rating in steps of -2, -1, 0, 1 or 2 */
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7891
diff changeset
  2730
				ge->rating = rating = or_ + Clamp(Clamp(rating, 0, 255) - or_, -2, 2);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2731
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2732
				/* if rating is <= 64 and more than 200 items waiting,
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2733
				 * 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
  2734
				if (rating <= 64 && waiting >= 200) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2735
					int dec = Random() & 0x1F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2736
					if (waiting < 400) dec &= 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2737
					waiting -= dec + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2738
					waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2739
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2740
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  2741
				/* 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
  2742
				if (rating <= 127 && waiting != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2743
					uint32 r = Random();
5660
1425b81374b8 (svn r8120) -Fix (r8055): Station cargo waiting value clamp should be signed not unsigned. This resulted in cargo magically appearing...
peter1138
parents: 5609
diff changeset
  2744
					if (rating <= (int)GB(r, 0, 7)) {
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  2745
						/* Need to have int, otherwise it will just overflow etc. */
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  2746
						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
  2747
						waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2748
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2749
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2750
7252
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2751
				/* At some point we really must cap the cargo. Previously this
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2752
				 * was a strict 4095, but now we'll have a less strict, but
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2753
				 * increasingly agressive truncation of the amount of cargo. */
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2754
				static const uint WAITING_CARGO_THRESHOLD  = 1 << 12;
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2755
				static const uint WAITING_CARGO_CUT_FACTOR = 1 <<  6;
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2756
				static const uint MAX_WAITING_CARGO        = 1 << 15;
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2757
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2758
				if (waiting > WAITING_CARGO_THRESHOLD) {
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2759
					uint difference = waiting - WAITING_CARGO_THRESHOLD;
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2760
					waiting -= (difference / WAITING_CARGO_CUT_FACTOR);
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2761
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2762
					waiting = min(waiting, MAX_WAITING_CARGO);
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2763
					waiting_changed = true;
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2764
				}
3440dde39b84 (svn r10555) -Codechange/Fix: add a soft limit of 4096 "entities" in a station's waiting queue and a hard limit of 32768 so (malicious) people cannot cause a "denial of service" attack by filling cargo lists.
rubidium
parents: 7097
diff changeset
  2765
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  2766
				if (waiting_changed) ge->cargo.Truncate(waiting);
0
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2769
	} while (++ge != endof(st->goods));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2770
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2771
	StationID index = st->index;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2772
	if (waiting_changed) {
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8015
diff changeset
  2773
		InvalidateWindow(WC_STATION_VIEW, index); // update whole window
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2774
	} else {
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8015
diff changeset
  2775
		InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_RATINGLIST); // update only ratings list
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2776
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2777
}
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
/* called for every station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2780
static void StationHandleSmallTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2781
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2782
	if (st->facilities == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2783
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2784
	byte b = st->delete_ctr + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2785
	if (b >= 185) b = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2786
	st->delete_ctr = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2787
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2788
	if (b == 0) UpdateStationRating(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2789
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2790
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  2791
void OnTick_Station()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2792
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2793
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2794
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2795
	uint i = _station_tick_ctr;
5247
1f982de55b88 (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
  2796
	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
  2797
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2798
	if (IsValidStationID(i)) StationHandleBigTick(GetStation(i));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2799
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2800
	Station *st;
9003
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2801
	FOR_ALL_STATIONS(st) {
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2802
		StationHandleSmallTick(st);
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2803
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2804
		/* Run 250 tick interval trigger for station animation.
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2805
		 * Station index is included so that triggers are not all done
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2806
		 * at the same time. */
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2807
		if ((_tick_counter + st->index) % 250 == 0) {
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2808
			StationAnimationTrigger(st, st->xy, STAT_ANIM_250_TICKS);
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2809
		}
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2810
	}
0
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
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  2813
void StationMonthlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2814
{
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2815
	/* not used */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2816
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2817
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2818
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  2819
void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint radius)
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
	Station *st;
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
	FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2824
		if (st->owner == owner &&
1245
3822f77cbc53 (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1239
diff changeset
  2825
				DistanceManhattan(tile, st->xy) <= radius) {
6350
04b19f551aec (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6329
diff changeset
  2826
			for (CargoID i = 0; i < NUM_CARGO; i++) {
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2827
				GoodsEntry *ge = &st->goods[i];
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2828
7474
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7469
diff changeset
  2829
				if (ge->acceptance_pickup != 0) {
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7891
diff changeset
  2830
					ge->rating = Clamp(ge->rating + amount, 0, 255);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2831
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2832
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2833
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2834
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2835
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2836
6350
04b19f551aec (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6329
diff changeset
  2837
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
  2838
{
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  2839
	st->goods[type].cargo.Append(new CargoPacket(st->index, amount));
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
  2840
	SetBit(st->goods[type].acceptance_pickup, GoodsEntry::PICKUP);
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  2841
9003
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2842
	StationAnimationTrigger(st, st->xy, STAT_ANIM_NEW_CARGO, type);
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  2843
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2844
	InvalidateWindow(WC_STATION_VIEW, st->index);
6823
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6761
diff changeset
  2845
	st->MarkTilesDirty(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2846
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2847
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2848
static bool IsUniqueStationName(const char *name)
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2849
{
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2850
	const Station *st;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2851
	char buf[512];
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2852
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2853
	FOR_ALL_STATIONS(st) {
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2854
		SetDParam(0, st->index);
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2855
		GetString(buf, STR_STATION, lastof(buf));
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2856
		if (strcmp(buf, name) == 0) return false;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2857
	}
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2858
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2859
	return true;
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2860
}
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2861
1786
7cfd46c3fcc4 (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
  2862
/** Rename a station
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  2863
 * @param tile unused
6483
ae78fc3c6b20 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6463
diff changeset
  2864
 * @param flags operation to perform
1786
7cfd46c3fcc4 (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
  2865
 * @param p1 station ID that is to be renamed
7cfd46c3fcc4 (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
  2866
 * @param p2 unused
7cfd46c3fcc4 (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
  2867
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  2868
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
  2869
{
10137
189e1e91fe82 (svn r14323) -Fix (r14064): forgot a return...
smatz
parents: 10124
diff changeset
  2870
	if (!IsValidStationID(p1)) return CMD_ERROR;
9914
c07d0352d8d5 (svn r14064) -Fix [FS#1752]: check for the length of strings (in bytes) in the command. Checking for the length in pixels is impossible because that differs per client.
rubidium
parents: 9875
diff changeset
  2871
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2872
	Station *st = GetStation(p1);
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2873
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
1774
907db1b7a445 (svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents: 1751
diff changeset
  2874
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10137
diff changeset
  2875
	bool reset = StrEmpty(_cmd_text);
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10137
diff changeset
  2876
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10137
diff changeset
  2877
	if (!reset) {
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10137
diff changeset
  2878
		if (strlen(_cmd_text) >= MAX_LENGTH_STATION_NAME_BYTES) return CMD_ERROR;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10137
diff changeset
  2879
		if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10137
diff changeset
  2880
	}
7097
bc497a49fb45 (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7067
diff changeset
  2881
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2882
	if (flags & DC_EXEC) {
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  2883
		free(st->name);
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10137
diff changeset
  2884
		st->name = reset ? NULL : strdup(_cmd_text);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  2885
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2886
		UpdateStationVirtCoord(st);
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
  2887
		InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2888
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2889
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2890
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6946
diff changeset
  2891
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2892
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2893
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2894
/**
10353
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2895
 * Find all (non-buoy) stations around a rectangular producer (industry, house, headquarter, ...)
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2896
 *
10353
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2897
 * @param tile North tile of producer
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2898
 * @param w_prod X extent of producer
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2899
 * @param h_prod Y extent of producer
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2900
 *
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2901
 * @return: Set of found stations
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  2902
 */
10353
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2903
StationSet FindStationsAroundTiles(TileIndex tile, int w_prod, int h_prod)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2904
{
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2905
	StationSet station_set;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2906
10353
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2907
	/* area to search = producer plus station catchment radius */
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2908
	int max_rad = (_settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED);
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2909
	int w = w_prod + 2 * max_rad;
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2910
	int h = h_prod + 2 * max_rad;
568
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2911
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  2912
	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
  2913
		cur_tile = TILE_MASK(cur_tile);
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2914
		if (!IsTileType(cur_tile, MP_STATION)) continue;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2915
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2916
		Station *st = GetStationByTile(cur_tile);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  2917
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2918
		if (st->IsBuoy()) continue; // bouys don't accept cargo
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2919
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2920
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  2921
		if (_settings_game.station.modified_catchment) {
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2922
			/* min and max coordinates of the producer relative */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2923
			const int x_min_prod = max_rad + 1;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2924
			const int x_max_prod = max_rad + w_prod;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2925
			const int y_min_prod = max_rad + 1;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2926
			const int y_max_prod = max_rad + h_prod;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2927
10290
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10289
diff changeset
  2928
			int rad = st->GetCatchmentRadius();
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2929
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2930
			int x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2931
			if (w_cur < x_min_prod) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2932
				x_dist = x_min_prod - w_cur;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2933
			} else if (w_cur > x_max_prod) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2934
				x_dist = w_cur - x_max_prod;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2935
			}
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2936
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2937
			if (x_dist > rad) continue;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2938
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2939
			int y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2940
			if (h_cur < y_min_prod) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2941
				y_dist = y_min_prod - h_cur;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2942
			} else if (h_cur > y_max_prod) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2943
				y_dist = h_cur - y_max_prod;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2944
			}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2945
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2946
			if (y_dist > rad) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2947
		}
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2948
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2949
		/* Insert the station in the set. This will fail if it has
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2950
		 * already been added.
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2951
		 */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2952
		station_set.insert(st);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2953
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  2954
	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
  2955
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2956
	return station_set;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2957
}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2958
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2959
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2960
{
8970
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
  2961
	Station *st1 = NULL;   // Station with best rating
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
  2962
	Station *st2 = NULL;   // Second best station
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
  2963
	uint best_rating1 = 0; // rating of st1
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8969
diff changeset
  2964
	uint best_rating2 = 0; // rating of st2
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2965
10353
452d21d281e6 (svn r14604) -Codechange: Simplify a function and rename it, and fix some comments.
frosch
parents: 10347
diff changeset
  2966
	StationSet all_stations = FindStationsAroundTiles(tile, w, h);
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2967
	for (StationSet::iterator st_iter = all_stations.begin(); st_iter != all_stations.end(); ++st_iter) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2968
		Station *st = *st_iter;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2969
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2970
		/* Is the station reserved exclusively for somebody else? */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2971
		if (st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2972
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2973
		if (st->goods[type].rating == 0) continue; // Lowest possible rating, better not to give cargo anymore
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2974
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  2975
		if (_settings_game.order.selectgoods && st->goods[type].last_speed == 0) continue; // Selectively servicing stations, and not this one
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2976
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2977
		if (IsCargoInClass(type, CC_PASSENGERS)) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2978
			if (st->facilities == FACIL_TRUCK_STOP) continue; // passengers are never served by just a truck stop
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2979
		} else {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2980
			if (st->facilities == FACIL_BUS_STOP) continue; // non-passengers are never served by just a bus stop
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2981
		}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2982
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2983
		/* This station can be used, add it to st1/st2 */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2984
		if (st1 == NULL || st->goods[type].rating >= best_rating1) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2985
			st2 = st1; best_rating2 = best_rating1; st1 = st; best_rating1 = st->goods[type].rating;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2986
		} else if (st2 == NULL || st->goods[type].rating >= best_rating2) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2987
			st2 = st; best_rating2 = st->goods[type].rating;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2988
		}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2989
	}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2990
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2991
	/* no stations around at all? */
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2992
	if (st1 == NULL) return 0;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2993
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2994
	if (st2 == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2995
		/* only one station around */
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2996
		uint moved = amount * best_rating1 / 256 + 1;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  2997
		UpdateStationWaiting(st1, type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2998
		return moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2999
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3000
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  3001
	/* 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
  3002
	assert(st1 != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3003
	assert(st2 != NULL);
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  3004
	assert(best_rating1 != 0 || best_rating2 != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3005
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3006
	/* the 2nd highest one gets a penalty */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3007
	best_rating2 >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3008
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3009
	/* amount given to station 1 */
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  3010
	uint t = (best_rating1 * (amount + 1)) / (best_rating1 + best_rating2);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  3011
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  3012
	uint moved = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3013
	if (t != 0) {
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7864
diff changeset
  3014
		moved = t * best_rating1 / 256 + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3015
		amount -= t;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  3016
		UpdateStationWaiting(st1, type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3017
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3018
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3019
	if (amount != 0) {
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  3020
		amount = amount * best_rating2 / 256 + 1;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  3021
		moved += amount;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3022
		UpdateStationWaiting(st2, type, amount);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3023
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3024
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3025
	return moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3026
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3027
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  3028
void BuildOilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3029
{
9063
005b0643381c (svn r12915) -Fix [FS#1960](r12857): don't initialize Station struct with tile=0, buoys will never change that value
smatz
parents: 9055
diff changeset
  3030
	Station *st = new Station(tile);
2427
5312305eecdd (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
  3031
5312305eecdd (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
	if (st == NULL) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5362
diff changeset
  3033
		DEBUG(misc, 0, "Can't allocate station for oilrig at 0x%X, reverting to oilrig only", tile);
2427
5312305eecdd (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
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3035
	}
2427
5312305eecdd (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
  3036
9049
21f20d9bc849 (svn r12875) -Codechange: Use defined const instead of cast magic
belugas
parents: 9048
diff changeset
  3037
	st->town = ClosestTownFromTile(tile, UINT_MAX);
2427
5312305eecdd (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
  3038
	st->sign.width_1 = 0;
5312305eecdd (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
9055
4dc6a0c0ef47 (svn r12897) -Codechange: some coding style in station_cmd.cpp.
rubidium
parents: 9049
diff changeset
  3040
	st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG);
7826
4283314d07a3 (svn r11376) -Fix: fill the town a oil rig is associated with before creating the name, otherwise every oil rig will become "<TOWN> Oilrig" which effectively means that there can be several oil rigs with exactly the same name.
rubidium
parents: 7814
diff changeset
  3041
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9714
diff changeset
  3042
	assert(IsTileType(tile, MP_INDUSTRY));
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9714
diff changeset
  3043
	MakeOilrig(tile, st->index, GetWaterClass(tile));
2427
5312305eecdd (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
  3044
5312305eecdd (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
  3045
	st->owner = OWNER_NONE;
5312305eecdd (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
  3046
	st->airport_flags = 0;
5312305eecdd (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->airport_type = AT_OILRIG;
5312305eecdd (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->xy = tile;
5312305eecdd (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->bus_stops = NULL;
5312305eecdd (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->truck_stops = NULL;
5312305eecdd (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->airport_tile = tile;
5312305eecdd (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->dock_tile = tile;
5312305eecdd (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->train_tile = 0;
5312305eecdd (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->had_vehicle_of_type = 0;
5312305eecdd (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_load = 255;
5312305eecdd (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->time_since_unload = 255;
5312305eecdd (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
  3057
	st->delete_ctr = 0;
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6248
diff changeset
  3058
	st->last_vehicle_type = VEH_INVALID;
2427
5312305eecdd (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->facilities = FACIL_AIRPORT | FACIL_DOCK;
5312305eecdd (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
	st->build_date = _date;
5312305eecdd (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
  3061
10231
f241d43cb22d (svn r14459) -Fix [FS#2343]: Update station-spread when building or removing oilrigs to make them consistent with station-spread-calculation on game-load and to make oilrig-stations behave like any other station type.
frosch
parents: 10228
diff changeset
  3062
	st->rect.BeforeAddTile(tile, StationRect::ADD_FORCE);
f241d43cb22d (svn r14459) -Fix [FS#2343]: Update station-spread when building or removing oilrigs to make them consistent with station-spread-calculation on game-load and to make oilrig-stations behave like any other station type.
frosch
parents: 10228
diff changeset
  3063
6350
04b19f551aec (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6329
diff changeset
  3064
	for (CargoID j = 0; j < NUM_CARGO; j++) {
7474
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7469
diff changeset
  3065
		st->goods[j].acceptance_pickup = 0;
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3066
		st->goods[j].days_since_pickup = 255;
6261
f294962efd0d (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: 6259
diff changeset
  3067
		st->goods[j].rating = INITIAL_STATION_RATING;
2427
5312305eecdd (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
		st->goods[j].last_speed = 0;
5312305eecdd (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
		st->goods[j].last_age = 255;
5312305eecdd (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
	}
5312305eecdd (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
  3071
5312305eecdd (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
  3072
	UpdateStationVirtCoordDirty(st);
5312305eecdd (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
  3073
	UpdateStationAcceptance(st, false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3074
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3075
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  3076
void DeleteOilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3077
{
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  3078
	Station *st = GetStationByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3079
9718
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9714
diff changeset
  3080
	MakeWaterKeepingClass(tile, OWNER_NONE);
4b7468076d31 (svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents: 9714
diff changeset
  3081
	MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3082
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3083
	st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3084
	st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3085
	st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3086
	st->airport_flags = 0;
10231
f241d43cb22d (svn r14459) -Fix [FS#2343]: Update station-spread when building or removing oilrigs to make them consistent with station-spread-calculation on game-load and to make oilrig-stations behave like any other station type.
frosch
parents: 10228
diff changeset
  3087
f241d43cb22d (svn r14459) -Fix [FS#2343]: Update station-spread when building or removing oilrigs to make them consistent with station-spread-calculation on game-load and to make oilrig-stations behave like any other station type.
frosch
parents: 10228
diff changeset
  3088
	st->rect.AfterRemoveTile(st, tile);
f241d43cb22d (svn r14459) -Fix [FS#2343]: Update station-spread when building or removing oilrigs to make them consistent with station-spread-calculation on game-load and to make oilrig-stations behave like any other station type.
frosch
parents: 10228
diff changeset
  3089
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3090
	UpdateStationVirtCoordDirty(st);
5665
d6b5c720ad67 (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: 5660
diff changeset
  3091
	if (st->facilities == 0) delete st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3092
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3093
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  3094
static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3095
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  3096
	if (!IsTileOwner(tile, old_owner)) return;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  3097
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  3098
	if (new_owner != INVALID_OWNER) {
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  3099
		Station *st = GetStationByTile(tile);
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  3100
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  3101
		SetTileOwner(tile, new_owner);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  3102
		if (!IsBuoy(tile)) st->owner = new_owner; // do not set st->owner for buoys
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9234
diff changeset
  3103
		InvalidateWindowClassesData(WC_STATION_LIST, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3104
	} else {
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  3105
		if (IsDriveThroughStopTile(tile)) {
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  3106
			/* Remove the drive-through road stop */
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
  3107
			DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? ROADSTOP_TRUCK : ROADSTOP_BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  3108
			assert(IsTileType(tile, MP_ROAD));
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  3109
			/* Change owner of tile and all roadtypes */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  3110
			ChangeTileOwner(tile, old_owner, new_owner);
6116
0a63874accb6 (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: 6115
diff changeset
  3111
		} else {
8519
fe61d7aa3053 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 8518
diff changeset
  3112
			DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
8520
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  3113
			/* Set tile owner of water under (now removed) buoy and dock to OWNER_NONE.
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  3114
			 * Update owner of buoy if it was not removed (was in orders).
ac36e31894cc (svn r12095) -Fix [FS#1703]: when a company bankrupts, remove drive-through road stops, ship depots and buoys too. Update owners of water and road.
smatz
parents: 8519
diff changeset
  3115
			 * Do not update when owned by OWNER_WATER (sea and rivers). */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
  3116
			if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && IsTileOwner(tile, old_owner)) SetTileOwner(tile, OWNER_NONE);
6116
0a63874accb6 (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: 6115
diff changeset
  3117
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3118
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3119
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3120
6116
0a63874accb6 (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: 6115
diff changeset
  3121
/**
0a63874accb6 (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: 6115
diff changeset
  3122
 * Check if a drive-through road stop tile can be cleared.
0a63874accb6 (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: 6115
diff changeset
  3123
 * Road stops built on town-owned roads check the conditions
0a63874accb6 (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: 6115
diff changeset
  3124
 * that would allow clearing of the original road.
0a63874accb6 (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: 6115
diff changeset
  3125
 * @param tile road stop tile to check
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
  3126
 * @param flags command flags
6116
0a63874accb6 (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: 6115
diff changeset
  3127
 * @return true if the road can be cleared
0a63874accb6 (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: 6115
diff changeset
  3128
 */
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
  3129
static bool CanRemoveRoadWithStop(TileIndex tile, uint32 flags)
6116
0a63874accb6 (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: 6115
diff changeset
  3130
{
0a63874accb6 (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: 6115
diff changeset
  3131
	/* The road can always be cleared if it was not a town-owned road */
0a63874accb6 (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: 6115
diff changeset
  3132
	if (!GetStopBuiltOnTownRoad(tile)) return true;
0a63874accb6 (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: 6115
diff changeset
  3133
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
  3134
	return CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, ROADTYPE_ROAD, flags);
6116
0a63874accb6 (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: 6115
diff changeset
  3135
}
0a63874accb6 (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: 6115
diff changeset
  3136
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6915
diff changeset
  3137
static CommandCost ClearTile_Station(TileIndex tile, byte flags)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  3138
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3139
	if (flags & DC_AUTO) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3140
		switch (GetStationType(tile)) {
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3141
			case STATION_RAIL:    return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3142
			case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST);
8563
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8520
diff changeset
  3143
			case STATION_TRUCK:   return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_CARGO_TRAM_STATION : STR_3047_MUST_DEMOLISH_TRUCK_STATION);
13b1a41e46f1 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 8520
diff changeset
  3144
			case STATION_BUS:     return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_PASSENGER_TRAM_STATION : STR_3046_MUST_DEMOLISH_BUS_STATION);
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3145
			case STATION_BUOY:    return_cmd_error(STR_306A_BUOY_IN_THE_WAY);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3146
			case STATION_DOCK:    return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3147
			case STATION_OILRIG:
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3148
				SetDParam(0, STR_4807_OIL_RIG);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3149
				return_cmd_error(STR_4800_IN_THE_WAY);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3150
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3151
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3152
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  3153
	Station *st = GetStationByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3154
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3155
	switch (GetStationType(tile)) {
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3156
		case STATION_RAIL:    return RemoveRailroadStation(st, tile, flags);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3157
		case STATION_AIRPORT: return RemoveAirport(st, flags);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3158
		case STATION_TRUCK:
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
  3159
			if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags))
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  3160
				return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  3161
			return RemoveRoadStop(st, flags, tile);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  3162
		case STATION_BUS:
9342
6daf441eee26 (svn r13234) -Fix: Check/affect town rating when removing/bulldozing town-owned road under drivethrough stops.
frosch
parents: 9341
diff changeset
  3163
			if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile, flags))
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  3164
				return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  3165
			return RemoveRoadStop(st, flags, tile);
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3166
		case STATION_BUOY:    return RemoveBuoy(st, flags);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3167
		case STATION_DOCK:    return RemoveDock(st, flags);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3168
		default: break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  3169
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3171
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3172
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3173
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  3174
void InitializeStations()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3175
{
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
  3176
	/* Clean the station pool and create 1 block in it */
7379
5afd3c499c4d (svn r10748) -Codechange: call the pool cleanup functions for stations directly instead of using the wrapper functions.
rubidium
parents: 7377
diff changeset
  3177
	_Station_pool.CleanPool();
5afd3c499c4d (svn r10748) -Codechange: call the pool cleanup functions for stations directly instead of using the wrapper functions.
rubidium
parents: 7377
diff changeset
  3178
	_Station_pool.AddBlockToPool();
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  3179
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3180
	/* Clean the roadstop pool and create 1 block in it */
7379
5afd3c499c4d (svn r10748) -Codechange: call the pool cleanup functions for stations directly instead of using the wrapper functions.
rubidium
parents: 7377
diff changeset
  3181
	_RoadStop_pool.CleanPool();
5afd3c499c4d (svn r10748) -Codechange: call the pool cleanup functions for stations directly instead of using the wrapper functions.
rubidium
parents: 7377
diff changeset
  3182
	_RoadStop_pool.AddBlockToPool();
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  3183
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3184
	_station_tick_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3185
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3187
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  3188
void AfterLoadStations()
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3189
{
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  3190
	/* Update the speclists of all stations to point to the currently loaded custom stations. */
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3191
	Station *st;
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3192
	FOR_ALL_STATIONS(st) {
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  3193
		for (uint i = 0; i < st->num_specs; i++) {
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3194
			if (st->speclist[i].grfid == 0) continue;
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3195
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3196
			st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx);
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3197
		}
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3198
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3199
		for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
9003
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  3200
7972fa66d9c9 (svn r12798) -Feature: Add some support for NewGRF station animation. (Thanks to mart3p for samples and fixes)
peter1138
parents: 8970
diff changeset
  3201
		StationUpdateAnimTriggers(st);
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3202
	}
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3203
}
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3204
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7491
diff changeset
  3205
static CommandCost TerraformTile_Station(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7491
diff changeset
  3206
{
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9385
diff changeset
  3207
	if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3208
		/* TODO: If you implement newgrf callback 149 'land slope check', you have to decide what to do with it here.
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3209
		 *       TTDP does not call it.
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3210
		 */
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3211
		if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3212
			switch (GetStationType(tile)) {
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3213
				case STATION_RAIL: {
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3214
					DiagDirection direction = AxisToDiagDir(GetRailStationAxis(tile));
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3215
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3216
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  3217
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3218
				}
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3219
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3220
				case STATION_AIRPORT:
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  3221
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3222
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3223
				case STATION_TRUCK:
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3224
				case STATION_BUS: {
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3225
					DiagDirection direction = GetRoadStopDir(tile);
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3226
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3227
					if (IsDriveThroughStopTile(tile)) {
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3228
						if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3229
					}
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  3230
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3231
				}
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3232
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3233
				default: break;
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3234
			}
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3235
		}
80c8517b08d1 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 7545
diff changeset
  3236
	}
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7491
diff changeset
  3237
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7491
diff changeset
  3238
}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7491
diff changeset
  3239
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3240
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  3241
extern const TileTypeProcs _tile_type_station_procs = {
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3242
	DrawTile_Station,           /* draw_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3243
	GetSlopeZ_Station,          /* get_slope_z_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3244
	ClearTile_Station,          /* clear_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3245
	GetAcceptedCargo_Station,   /* get_accepted_cargo_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3246
	GetTileDesc_Station,        /* get_tile_desc_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3247
	GetTileTrackStatus_Station, /* get_tile_track_status_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3248
	ClickTile_Station,          /* click_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3249
	AnimateTile_Station,        /* animate_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3250
	TileLoop_Station,           /* tile_loop_clear */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3251
	ChangeTileOwner_Station,    /* change_tile_owner_clear */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3252
	NULL,                       /* get_produced_cargo_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3253
	VehicleEnter_Station,       /* vehicle_enter_tile_proc */
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7333
diff changeset
  3254
	GetFoundation_Station,      /* get_foundation_proc */
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7491
diff changeset
  3255
	TerraformTile_Station,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3256
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3257
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1876
diff changeset
  3258
static const SaveLoad _roadstop_desc[] = {
8969
6d1c74e0e2cd (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 8964
diff changeset
  3259
	SLE_VAR(RoadStop, xy,           SLE_UINT32),
5718
ce37296bb03c (svn r8212) -Fix
tron
parents: 5716
diff changeset
  3260
	SLE_CONDNULL(1, 0, 44),
8969
6d1c74e0e2cd (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 8964
diff changeset
  3261
	SLE_VAR(RoadStop, status,       SLE_UINT8),
1285
4bda5c927b45 (svn r1789) -Fix: there is no need to save the index, it is done for us
truelight
parents: 1284
diff changeset
  3262
	/* Index was saved in some versions, but this is not needed */
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  3263
	SLE_CONDNULL(4, 0, 8),
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5709
diff changeset
  3264
	SLE_CONDNULL(2, 0, 44),
3479
3655a074a380 (svn r4324) Remove the unused road stop type attribute from struct RoadStop
tron
parents: 3478
diff changeset
  3265
	SLE_CONDNULL(1, 0, 25),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3266
8969
6d1c74e0e2cd (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 8964
diff changeset
  3267
	SLE_REF(RoadStop, next,         REF_ROADSTOPS),
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  3268
	SLE_CONDNULL(2, 0, 44),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3269
3431
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3429
diff changeset
  3270
	SLE_CONDNULL(4, 0, 24),
3475
150d89779e96 (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
  3271
	SLE_CONDNULL(1, 25, 25),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3272
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3273
	SLE_END()
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3274
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3275
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1876
diff changeset
  3276
static const SaveLoad _station_desc[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3277
	SLE_CONDVAR(Station, xy,                         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3278
	SLE_CONDVAR(Station, xy,                         SLE_UINT32,                  6, SL_MAX_VERSION),
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  3279
	SLE_CONDNULL(4, 0, 5),  ///< bus/lorry tile
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3280
	SLE_CONDVAR(Station, train_tile,                 SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3281
	SLE_CONDVAR(Station, train_tile,                 SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3282
	SLE_CONDVAR(Station, airport_tile,               SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3283
	SLE_CONDVAR(Station, airport_tile,               SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3284
	SLE_CONDVAR(Station, dock_tile,                  SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3285
	SLE_CONDVAR(Station, dock_tile,                  SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3286
	    SLE_REF(Station, town,                       REF_TOWN),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3287
	    SLE_VAR(Station, trainst_w,                  SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3288
	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
  3289
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  3290
	SLE_CONDNULL(1, 0, 3),  ///< alpha_order
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3291
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3292
	    SLE_VAR(Station, string_id,                  SLE_STRINGID),
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  3293
	SLE_CONDSTR(Station, name,                       SLE_STR, 0,                 84, SL_MAX_VERSION),
10347
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
  3294
	SLE_CONDVAR(Station, indtype,                    SLE_UINT8,                 103, SL_MAX_VERSION),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3295
	    SLE_VAR(Station, had_vehicle_of_type,        SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3296
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3297
	    SLE_VAR(Station, time_since_load,            SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3298
	    SLE_VAR(Station, time_since_unload,          SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3299
	    SLE_VAR(Station, delete_ctr,                 SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3300
	    SLE_VAR(Station, owner,                      SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3301
	    SLE_VAR(Station, facilities,                 SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3302
	    SLE_VAR(Station, airport_type,               SLE_UINT8),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3303
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  3304
	SLE_CONDNULL(2, 0, 5),  ///< Truck/bus stop status
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  3305
	SLE_CONDNULL(1, 0, 4),  ///< Blocked months
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3306
5995
4e57aeeeafcd (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: 5991
diff changeset
  3307
	SLE_CONDVAR(Station, airport_flags,              SLE_VAR_U64 | SLE_FILE_U16,  0,  2),
4e57aeeeafcd (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: 5991
diff changeset
  3308
	SLE_CONDVAR(Station, airport_flags,              SLE_VAR_U64 | SLE_FILE_U32,  3, 45),
4e57aeeeafcd (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: 5991
diff changeset
  3309
	SLE_CONDVAR(Station, airport_flags,              SLE_UINT64,                 46, SL_MAX_VERSION),
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3310
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  3311
	SLE_CONDNULL(2, 0, 25), ///< last-vehicle
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3312
	SLE_CONDVAR(Station, last_vehicle_type,          SLE_UINT8,                  26, SL_MAX_VERSION),
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3313
8964
84f2e443b7be (svn r12756) -Cleanup: variable scope and coding style in station*
smatz
parents: 8962
diff changeset
  3314
	SLE_CONDNULL(2, 3, 25), ///< custom station class and id
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3315
	SLE_CONDVAR(Station, build_date,                 SLE_FILE_U16 | SLE_VAR_I32,  3, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3316
	SLE_CONDVAR(Station, build_date,                 SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3317
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3318
	SLE_CONDREF(Station, bus_stops,                  REF_ROADSTOPS,               6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3319
	SLE_CONDREF(Station, truck_stops,                REF_ROADSTOPS,               6, SL_MAX_VERSION),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3320
3687
f421ffcfeb00 (svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents: 3682
diff changeset
  3321
	/* Used by newstations for graphic variations */
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3322
	SLE_CONDVAR(Station, random_bits,                SLE_UINT16,                 27, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3323
	SLE_CONDVAR(Station, waiting_triggers,           SLE_UINT8,                  27, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3324
	SLE_CONDVAR(Station, num_specs,                  SLE_UINT8,                  27, SL_MAX_VERSION),
3687
f421ffcfeb00 (svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents: 3682
diff changeset
  3325
6500
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  3326
	SLE_CONDLST(Station, loading_vehicles,           REF_VEHICLE,                57, SL_MAX_VERSION),
f12678890222 (svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium
parents: 6491
diff changeset
  3327
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  3328
	/* reserve extra space in savegame here. (currently 32 bytes) */
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  3329
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3330
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3331
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3332
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3333
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3334
static uint16 _waiting_acceptance;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3335
static uint16 _cargo_source;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3336
static uint32 _cargo_source_xy;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3337
static uint16 _cargo_days;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3338
static Money  _cargo_feeder_share;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3339
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3340
static const SaveLoad _station_speclist_desc[] = {
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3341
	SLE_CONDVAR(StationSpecList, grfid,    SLE_UINT32, 27, SL_MAX_VERSION),
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3342
	SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8,  27, SL_MAX_VERSION),
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3343
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3344
	SLE_END()
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3345
};
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3346
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3347
7491
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3348
void SaveLoad_STNS(Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3349
{
7491
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3350
	static const SaveLoad _goods_desc[] = {
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3351
		SLEG_CONDVAR(            _waiting_acceptance, SLE_UINT16,                  0, 67),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3352
		 SLE_CONDVAR(GoodsEntry, acceptance_pickup,   SLE_UINT8,                  68, SL_MAX_VERSION),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3353
		SLE_CONDNULL(2,                                                           51, 67),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3354
		     SLE_VAR(GoodsEntry, days_since_pickup,   SLE_UINT8),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3355
		     SLE_VAR(GoodsEntry, rating,              SLE_UINT8),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3356
		SLEG_CONDVAR(            _cargo_source,       SLE_FILE_U8 | SLE_VAR_U16,   0, 6),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3357
		SLEG_CONDVAR(            _cargo_source,       SLE_UINT16,                  7, 67),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3358
		SLEG_CONDVAR(            _cargo_source_xy,    SLE_UINT32,                 44, 67),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3359
		SLEG_CONDVAR(            _cargo_days,         SLE_UINT8,                   0, 67),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3360
		     SLE_VAR(GoodsEntry, last_speed,          SLE_UINT8),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3361
		     SLE_VAR(GoodsEntry, last_age,            SLE_UINT8),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3362
		SLEG_CONDVAR(            _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3363
		SLEG_CONDVAR(            _cargo_feeder_share, SLE_INT64,                  65, 67),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3364
		 SLE_CONDLST(GoodsEntry, cargo.packets,       REF_CARGO_PACKET,           68, SL_MAX_VERSION),
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3365
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3366
		SLE_END()
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3367
};
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3368
595b714c8719 (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7474
diff changeset
  3369
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3370
	SlObject(st, _station_desc);
6463
e986fe39dfe7 (svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138
parents: 6453
diff changeset
  3371
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3372
	_waiting_acceptance = 0;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3373
6463
e986fe39dfe7 (svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138
parents: 6453
diff changeset
  3374
	uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
e986fe39dfe7 (svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138
parents: 6453
diff changeset
  3375
	for (CargoID i = 0; i < num_cargo; i++) {
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3376
		GoodsEntry *ge = &st->goods[i];
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3377
		SlObject(ge, _goods_desc);
7013
b9643e4f798b (svn r10269) -Fix [FS#912]: station ratings were shown for all cargos instead of only the cargos that have been transported.
rubidium
parents: 7010
diff changeset
  3378
		if (CheckSavegameVersion(68)) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  3379
			SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3380
			if (GB(_waiting_acceptance, 0, 12) != 0) {
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3381
				/* Don't construct the packet with station here, because that'll fail with old savegames */
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3382
				CargoPacket *cp = new CargoPacket();
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3383
				/* In old versions, enroute_from used 0xFF as INVALID_STATION */
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3384
				cp->source          = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3385
				cp->count           = GB(_waiting_acceptance, 0, 12);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3386
				cp->days_in_transit = _cargo_days;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3387
				cp->feeder_share    = _cargo_feeder_share;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3388
				cp->source_xy       = _cargo_source_xy;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3389
				cp->days_in_transit = _cargo_days;
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3390
				cp->feeder_share    = _cargo_feeder_share;
7474
1daa825ba893 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7469
diff changeset
  3391
				SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, 1);
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3392
				ge->cargo.Append(cp);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3393
			}
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6955
diff changeset
  3394
		}
1266
eccd576e322f (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  3395
	}
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3396
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3397
	if (st->num_specs != 0) {
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3398
		/* Allocate speclist memory when loading a game */
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5601
diff changeset
  3399
		if (st->speclist == NULL) st->speclist = CallocT<StationSpecList>(st->num_specs);
6069
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  3400
		for (uint i = 0; i < st->num_specs; i++) {
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  3401
			SlObject(&st->speclist[i], _station_speclist_desc);
51c67843788d (svn r8799) -Fix
tron
parents: 6067
diff changeset
  3402
		}
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3403
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3404
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3405
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  3406
static void Save_STNS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3407
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3408
	Station *st;
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  3409
	/* Write the stations */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3410
	FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3411
		SlSetArrayIndex(st->index);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3412
		SlAutolength((AutolengthProc*)SaveLoad_STNS, st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3413
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3414
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3415
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  3416
static void Load_STNS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3417
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3418
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3419
	while ((index = SlIterateArray()) != -1) {
5665
d6b5c720ad67 (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: 5660
diff changeset
  3420
		Station *st = new (index) Station();
d6b5c720ad67 (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: 5660
diff changeset
  3421
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3422
		SaveLoad_STNS(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3423
7795
8ce3c983c7a3 (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 7758
diff changeset
  3424
		/* this means it's an oldstyle savegame without support for nonuniform stations */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  3425
		if (st->train_tile != 0 && st->trainst_h == 0) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3426
			uint w = GB(st->trainst_w, 4, 4);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3427
			uint h = GB(st->trainst_w, 0, 4);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3428
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 6098
diff changeset
  3429
			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
  3430
			st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3431
			st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3432
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3433
	}
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  3434
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
  3435
	/* This is to ensure all pointers are within the limits of _stations_size */
5247
1f982de55b88 (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
  3436
	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
  3437
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3438
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  3439
static void Save_ROADSTOP()
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3440
{
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3441
	RoadStop *rs;
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3442
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3443
	FOR_ALL_ROADSTOPS(rs) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3444
		SlSetArrayIndex(rs->index);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3445
		SlObject(rs, _roadstop_desc);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3446
	}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3447
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3448
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  3449
static void Load_ROADSTOP()
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3450
{
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3451
	int index;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3452
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3453
	while ((index = SlIterateArray()) != -1) {
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5709
diff changeset
  3454
		RoadStop *rs = new (index) RoadStop(INVALID_TILE);
5708
4c4c5ec2bed6 (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: 5697
diff changeset
  3455
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3456
		SlObject(rs, _roadstop_desc);
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3457
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3458
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3459
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  3460
extern const ChunkHandler _station_chunk_handlers[] = {
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3461
	{ 'STNS', Save_STNS,      Load_STNS,      CH_ARRAY },
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3462
	{ '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
  3463
};