src/station_cmd.cpp
author glx
Sat, 16 Feb 2008 00:10:03 +0000
changeset 9070 e83a2f017f3d
parent 9069 7b9573ccc411
child 9092 383a632de666
permissions -rw-r--r--
(svn r12155) -Fix (r12154): some warnings (always compile before commit)
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6443
b8f06d8eb7be (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 6442
diff changeset
     3
/** @file station_cmd.cpp */
2213
cb78ae22fe58 (svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents: 2187
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
6413
3d660a812fbd (svn r8822) -Fix
tron
parents: 6402
diff changeset
     7
#include "aircraft.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
     8
#include "bridge_map.h"
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
     9
#include "cmd_helper.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1295
diff changeset
    10
#include "debug.h"
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
    11
#include "tile_cmd.h"
6949
72d11a1e1e60 (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: 6923
diff changeset
    12
#include "landscape.h"
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
    13
#include "station_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "station.h"
8721
b7971ad9bdd9 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8710
diff changeset
    15
#include "viewport_func.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    16
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "airport.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    21
#include "sprite.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    22
#include "depot.h"
2676
2ba71e034d97 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2671
diff changeset
    23
#include "train.h"
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7319
diff changeset
    24
#include "roadveh.h"
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
    25
#include "water_map.h"
3515
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
    26
#include "industry_map.h"
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
    27
#include "newgrf_callbacks.h"
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
    28
#include "newgrf_station.h"
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
    29
#include "yapf/yapf.h"
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
    30
#include "misc/autoptr.hpp"
8598
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8594
diff changeset
    31
#include "road_type.h"
14ae80fe4c8f (svn r11663) -Codechange: moving of the road related types and functions.
rubidium
parents: 8594
diff changeset
    32
#include "road_internal.h" /* For drawing catenary/checking road removal */
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6413
diff changeset
    33
#include "cargotype.h"
8707
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8662
diff changeset
    34
#include "variables.h"
8078
bdf94bf88568 (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: 8041
diff changeset
    35
#include "autoslope.h"
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8322
diff changeset
    36
#include "transparency.h"
8444
9317090e9c8c (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 8427
diff changeset
    37
#include "water.h"
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8511
diff changeset
    38
#include "station_gui.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8605
diff changeset
    39
#include "strings_func.h"
8627
448ebf3a8291 (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: 8626
diff changeset
    40
#include "functions.h"
448ebf3a8291 (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: 8626
diff changeset
    41
#include "window_func.h"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8635
diff changeset
    42
#include "date_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8636
diff changeset
    43
#include "vehicle_func.h"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8707
diff changeset
    44
#include "string_func.h"
8734
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8732
diff changeset
    45
#include "signal_func.h"
b7fc8c6fd379 (svn r11802) -Fix [FS#716]: do not crash trains when leaving depot to a very long track
smatz
parents: 8732
diff changeset
    46
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    47
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8754
diff changeset
    48
#include "table/strings.h"
5917
e0d30aba24a3 (svn r8126) -Fix (r8125): missing #include fixes compilation error on g++ (still some warnings, working on it)
KUDr
parents: 5916
diff changeset
    49
7872
a0646ade9d4a (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: 7866
diff changeset
    50
DEFINE_OLD_POOL_GENERIC(Station, Station)
a0646ade9d4a (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: 7866
diff changeset
    51
DEFINE_OLD_POOL_GENERIC(RoadStop, RoadStop)
1272
d3e09adb7736 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    52
d3e09adb7736 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    53
7816
207d11ff7fda (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: 7815
diff changeset
    54
/**
207d11ff7fda (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: 7815
diff changeset
    55
 * Check whether the given tile is a hangar.
207d11ff7fda (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: 7815
diff changeset
    56
 * @param t the tile to of whether it is a hangar.
207d11ff7fda (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: 7815
diff changeset
    57
 * @pre IsTileType(t, MP_STATION)
207d11ff7fda (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: 7815
diff changeset
    58
 * @return true if and only if the tile is a hangar.
207d11ff7fda (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: 7815
diff changeset
    59
 */
207d11ff7fda (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: 7815
diff changeset
    60
bool IsHangar(TileIndex t)
207d11ff7fda (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: 7815
diff changeset
    61
{
207d11ff7fda (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: 7815
diff changeset
    62
	assert(IsTileType(t, MP_STATION));
207d11ff7fda (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: 7815
diff changeset
    63
207d11ff7fda (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: 7815
diff changeset
    64
	const Station *st = GetStationByTile(t);
207d11ff7fda (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: 7815
diff changeset
    65
	const AirportFTAClass *apc = st->Airport();
207d11ff7fda (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: 7815
diff changeset
    66
207d11ff7fda (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: 7815
diff changeset
    67
	for (uint i = 0; i < apc->nof_depots; i++) {
207d11ff7fda (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: 7815
diff changeset
    68
		if (st->airport_tile + ToTileIndexDiff(apc->airport_depots[i]) == t) return true;
207d11ff7fda (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: 7815
diff changeset
    69
	}
207d11ff7fda (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: 7815
diff changeset
    70
207d11ff7fda (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: 7815
diff changeset
    71
	return false;
207d11ff7fda (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: 7815
diff changeset
    72
}
207d11ff7fda (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: 7815
diff changeset
    73
6087
b56c54f79335 (svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop
celestar
parents: 6085
diff changeset
    74
RoadStop* GetRoadStopByTile(TileIndex tile, RoadStop::Type type)
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    75
{
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
    76
	const Station* st = GetStationByTile(tile);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
    77
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
    78
	for (RoadStop *rs = st->GetPrimaryRoadStop(type);; rs = rs->next) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
    79
		if (rs->xy == tile) return rs;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    80
		assert(rs->next != NULL);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    81
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    82
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    83
6164
a4458b13cca9 (svn r8539) -Fix
tron
parents: 6157
diff changeset
    84
a4458b13cca9 (svn r8539) -Fix
tron
parents: 6157
diff changeset
    85
static uint GetNumRoadStopsInStation(const Station* st, RoadStop::Type type)
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    86
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
    87
	uint num = 0;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    88
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    89
	assert(st != NULL);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
    90
	for (const RoadStop *rs = st->GetPrimaryRoadStop(type); rs != NULL; rs = rs->next) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
    91
		num++;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
    92
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    93
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    94
	return num;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    95
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    96
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    97
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
    98
/** Calculate the radius of the station. Basicly it is the biggest
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
    99
 *  radius that is available within the station
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   100
 * @param st Station to query
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   101
 * @return the so calculated radius
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   102
 */
2643
735ef1e7884b (svn r3185) const
tron
parents: 2642
diff changeset
   103
static uint FindCatchmentRadius(const Station* st)
703
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   104
{
6367
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   105
	uint ret = CA_NONE;
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   106
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   107
	if (st->bus_stops   != NULL) ret = max<uint>(ret, CA_BUS);
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   108
	if (st->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK);
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   109
	if (st->train_tile  != 0)    ret = max<uint>(ret, CA_TRAIN);
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   110
	if (st->dock_tile   != 0)    ret = max<uint>(ret, CA_DOCK);
2f569d554980 (svn r8767) -Fix
tron
parents: 6365
diff changeset
   111
	if (st->airport_tile)        ret = max<uint>(ret, st->Airport()->catchment);
703
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   112
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   113
	return ret;
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   114
}
c917d7d9aced (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   115
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
#define CHECK_STATIONS_ERR ((Station*)-1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   118
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
   119
{
6916
e87d54a598ea (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6898
diff changeset
   120
	/* check around to see if there's any stations there */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   121
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   122
		if (IsTileType(tile_cur, MP_STATION)) {
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
   123
			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
   124
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   125
			if (closest_station == INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
				closest_station = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
			} else if (closest_station != t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
				_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
				return CHECK_STATIONS_ERR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
		}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   132
	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   133
	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
   134
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   136
/**
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   137
 * Function to check whether the given tile matches some criterion.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   138
 * @param tile the tile to check
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   139
 * @return true if it matches, false otherwise
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   140
 */
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   141
typedef bool (*CMSAMatcher)(TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
3515
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   143
/**
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   144
 * Counts the numbers of tiles matching a specific type in the area around
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   145
 * @param tile the center tile of the 'count area'
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   146
 * @param type the type of tile searched for
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   147
 * @param industry when type == MP_INDUSTRY, the type of the industry,
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   148
 *                 in all other cases this parameter is ignored
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6524
diff changeset
   149
 * @return the result the noumber of matching tiles around
3515
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   150
 */
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   151
static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   152
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   155
	for (int dx = -3; dx <= 3; dx++) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   156
		for (int dy = -3; dy <= 3; dy++) {
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   157
			if (cmp(TILE_MASK(tile + TileDiffXY(dx, dy)))) num++;
3515
b14c49efef1e (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   158
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	return num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   164
/**
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   165
 * Check whether the tile is a mine.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   166
 * @param tile the tile to investigate.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   167
 * @return true if and only if the tile is a mine
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   168
 */
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   169
static bool CMSAMine(TileIndex tile)
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   170
{
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   171
	/* No industry */
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   172
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   173
8141
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   174
	const Industry *ind = GetIndustryByTile(tile);
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   175
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   176
	/* No extractive industry */
8141
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   177
	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   178
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   179
	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   180
		/* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine */
8141
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   181
		if (ind->produced_cargo[i] != CT_INVALID && (GetCargo(ind->produced_cargo[i])->classes & CC_LIQUID) == 0) return true;
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   182
	}
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   183
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   184
	return false;
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   185
}
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   186
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   187
/**
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   188
 * Check whether the tile is water.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   189
 * @param tile the tile to investigate.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   190
 * @return true if and only if the tile is a mine
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   191
 */
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   192
static bool CMSAWater(TileIndex tile)
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   193
{
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   194
	return IsTileType(tile, MP_WATER) && IsWater(tile);
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   195
}
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   196
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   197
/**
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   198
 * Check whether the tile is a tree.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   199
 * @param tile the tile to investigate.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   200
 * @return true if and only if the tile is a mine
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   201
 */
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   202
static bool CMSATree(TileIndex tile)
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   203
{
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   204
	return IsTileType(tile, MP_TREES);
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   205
}
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   206
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   207
/**
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   208
 * Check whether the tile is a forest.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   209
 * @param tile the tile to investigate.
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   210
 * @return true if and only if the tile is a mine
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   211
 */
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   212
static bool CMSAForest(TileIndex tile)
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   213
{
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   214
	/* No industry */
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   215
	if (!IsTileType(tile, MP_INDUSTRY)) return false;
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   216
8141
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   217
	const Industry *ind = GetIndustryByTile(tile);
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   218
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   219
	/* No extractive industry */
8141
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   220
	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   221
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   222
	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   223
		/* The industry produces wood. */
8141
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8138
diff changeset
   224
		if (ind->produced_cargo[i] != CT_INVALID && GetCargo(ind->produced_cargo[i])->label == 'WOOD') return true;
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   225
	}
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   226
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   227
	return false;
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   228
}
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   229
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
#define M(x) ((x) - STR_SV_STNAME)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
8310
2bb5c255f4ff (svn r11364) -Fix (r11363): compilation broken
glx
parents: 8309
diff changeset
   232
enum StationNaming {
8309
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
   233
	STATIONNAMING_RAIL = 0,
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
   234
	STATIONNAMING_ROAD = 0,
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
   235
	STATIONNAMING_AIRPORT,
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
   236
	STATIONNAMING_OILRIG,
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
   237
	STATIONNAMING_DOCK,
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
   238
	STATIONNAMING_BUOY,
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
   239
	STATIONNAMING_HELIPORT,
8310
2bb5c255f4ff (svn r11364) -Fix (r11363): compilation broken
glx
parents: 8309
diff changeset
   240
};
8309
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
   241
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   242
static bool GenerateStationName(Station *st, TileIndex tile, int flag)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
	static const uint32 _gen_station_name_bits[] = {
1454
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   245
		0,                                      /* 0 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   246
		1 << M(STR_SV_STNAME_AIRPORT),          /* 1 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   247
		1 << M(STR_SV_STNAME_OILFIELD),         /* 2 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   248
		1 << M(STR_SV_STNAME_DOCKS),            /* 3 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   249
		0x1FF << M(STR_SV_STNAME_BUOY_1),       /* 4 */
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   250
		1 << M(STR_SV_STNAME_HELIPORT),         /* 5 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
	Town *t = st->town;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	uint32 free_names = (uint32)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	int found;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	unsigned long tmp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
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
		Station *s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		FOR_ALL_STATIONS(s) {
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   262
			if (s != st && s->town == t) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
				uint str = M(s->string_id);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
				if (str <= 0x20) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
					if (str == M(STR_SV_STNAME_FOREST))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
						str = M(STR_SV_STNAME_WOODS);
8425
72a71d480c5f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   267
					ClrBit(free_names, str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   270
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   272
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	/* check default names */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	tmp = free_names & _gen_station_name_bits[flag];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	if (tmp != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
		found = FindFirstBit(tmp);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
		goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	/* check mine? */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   281
	if (HasBit(free_names, M(STR_SV_STNAME_MINES))) {
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   282
		if (CountMapSquareAround(tile, CMSAMine) >= 2) {
1454
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   283
			found = M(STR_SV_STNAME_MINES);
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   284
			goto done;
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   285
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	/* check close enough to town to get central as name? */
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   289
	if (DistanceMax(tile, t->xy) < 8) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
		found = M(STR_SV_STNAME);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   291
		if (HasBit(free_names, M(STR_SV_STNAME))) goto done;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
		found = M(STR_SV_STNAME_CENTRAL);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   294
		if (HasBit(free_names, M(STR_SV_STNAME_CENTRAL))) goto done;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	/* Check lakeside */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   298
	if (HasBit(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   299
			DistanceFromEdge(tile) < 20 &&
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   300
			CountMapSquareAround(tile, CMSAWater) >= 5) {
1454
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   301
		found = M(STR_SV_STNAME_LAKESIDE);
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   302
		goto done;
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   303
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	/* Check woods */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   306
	if (HasBit(free_names, M(STR_SV_STNAME_WOODS)) && (
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   307
				CountMapSquareAround(tile, CMSATree) >= 8 ||
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7794
diff changeset
   308
				CountMapSquareAround(tile, CMSAForest) >= 2)
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   309
			) {
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6676
diff changeset
   310
		found = _opt.landscape == LT_TROPIC ?
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   311
			M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
1454
03c4de053282 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   312
		goto done;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	/* check elevation compared to town */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   316
	{
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   317
		uint z = GetTileZ(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   318
		uint z2 = GetTileZ(t->xy);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   319
		if (z < z2) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   320
			found = M(STR_SV_STNAME_VALLEY);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   321
			if (HasBit(free_names, M(STR_SV_STNAME_VALLEY))) goto done;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   322
		} else if (z > z2) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   323
			found = M(STR_SV_STNAME_HEIGHTS);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   324
			if (HasBit(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   325
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	/* check direction compared to town */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
		static const int8 _direction_and_table[] = {
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   331
			~( (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   332
			~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   333
			~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_EAST)) | (1 << M(STR_SV_STNAME_NORTH)) ),
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   334
			~( (1 << M(STR_SV_STNAME_SOUTH)) | (1 << M(STR_SV_STNAME_WEST)) | (1 << M(STR_SV_STNAME_EAST)) ),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
		};
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   336
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   337
		free_names &= _direction_and_table[
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   338
			(TileX(tile) < TileX(t->xy)) +
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   339
			(TileY(tile) < TileY(t->xy)) * 2];
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
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   342
	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));
7551
9ae828d83ff2 (svn r10320) -Fix [FS#278]: one could only build a limited number of stations before one had to rename them.
rubidium
parents: 7509
diff changeset
   343
	found = (tmp == 0) ? M(STR_SV_STNAME_FALLBACK) : FindFirstBit(tmp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
done:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
	st->string_id = found + STR_SV_STNAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
#undef M
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
   351
static Station* GetClosestStationFromTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
{
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
   353
	uint threshold = 8;
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   354
	Station* best_station = NULL;
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   355
	Station* st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	FOR_ALL_STATIONS(st) {
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
   358
		if (st->facilities == 0 && st->owner == _current_player) {
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   359
			uint cur_dist = DistanceManhattan(tile, st->xy);
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   360
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   361
			if (cur_dist < threshold) {
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   362
				threshold = cur_dist;
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   363
				best_station = st;
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   364
			}
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	return best_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   371
/** Update the virtual coords needed to draw the station sign.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   372
 * @param st Station to update for.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   373
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
static void UpdateStationVirtCoord(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
{
3422
12cdb13ddb56 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 3418
diff changeset
   376
	Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   377
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	pt.y -= 32;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   379
	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
   380
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   381
	SetDParam(0, st->index);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   382
	SetDParam(1, st->facilities);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
	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
   384
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   386
/** Update the virtual coords needed to draw the station sign for all stations. */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   387
void UpdateAllStationVirtCoord()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   389
	Station* st;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   390
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
	FOR_ALL_STATIONS(st) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   392
		UpdateStationVirtCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8035
diff changeset
   396
/**
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8035
diff changeset
   397
 * Update the station virt coords while making the modified parts dirty.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8035
diff changeset
   398
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8035
diff changeset
   399
 * This function updates the virt coords and mark the modified parts as dirty
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8035
diff changeset
   400
 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8035
diff changeset
   401
 * @param st The station to update the virt coords
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8035
diff changeset
   402
 * @ingroup dirty
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8035
diff changeset
   403
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
static void UpdateStationVirtCoordDirty(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
{
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   406
	st->MarkDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
	UpdateStationVirtCoord(st);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   408
	st->MarkDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   411
/** Get a mask of the cargo types that the station accepts.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   412
 * @param st Station to query
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   413
 * @return the expected mask
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   414
 */
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   415
static uint GetAcceptanceMask(const Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	uint mask = 0;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   418
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
   419
	for (CargoID i = 0; i < NUM_CARGO; i++) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   420
		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
   421
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	return mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   425
/** Items contains the two cargo names that are to be accepted or rejected.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   426
 * msg is the string id of the message to display.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   427
 */
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   428
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
   429
{
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   430
	for (uint i = 0; i < num_items; i++) {
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6413
diff changeset
   431
		SetDParam(i + 1, GetCargo(cargo[i])->name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	}
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   433
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   434
	SetDParam(0, st->index);
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   435
	AddNewsItem(msg, NEWS_FLAGS(NM_SMALL, NF_VIEWPORT | NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
8387
30f519812d62 (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: 8360
diff changeset
   438
/**
30f519812d62 (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: 8360
diff changeset
   439
* Get a list of the cargo types being produced around the tile (in a rectangle).
30f519812d62 (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: 8360
diff changeset
   440
* @param produced: Destination array of produced cargo
30f519812d62 (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: 8360
diff changeset
   441
* @param tile: Center of the search area
30f519812d62 (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: 8360
diff changeset
   442
* @param w: Width of the center
30f519812d62 (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: 8360
diff changeset
   443
* @param h: Height of the center
30f519812d62 (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: 8360
diff changeset
   444
* @param rad: Radius of the search area
30f519812d62 (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: 8360
diff changeset
   445
*/
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   446
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile,
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   447
	int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
{
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   449
	memset(produced, 0, sizeof(AcceptedCargo));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   451
	int x = TileX(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   452
	int y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   454
	/* expand the region by rad tiles on each side
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   455
	 * while making sure that we remain inside the board. */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   456
	int x2 = min(x + w + rad, MapSizeX());
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   457
	int x1 = max(x - rad, 0);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   458
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   459
	int y2 = min(y + h + rad, MapSizeY());
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   460
	int y1 = max(y - rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   467
	for (int yc = y1; yc != y2; yc++) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   468
		for (int xc = x1; xc != x2; xc++) {
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8444
diff changeset
   469
			if (!(IsInsideBS(xc, x, w) && IsInsideBS(yc, y, h))) {
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   470
				TileIndex tile = TileXY(xc, yc);
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   471
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   472
				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
   473
				if (gpc != NULL) {
3344
d86c852715fa (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3334
diff changeset
   474
					CargoID cargos[2] = { CT_INVALID, CT_INVALID };
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   475
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
					gpc(tile, cargos);
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   477
					if (cargos[0] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
						produced[cargos[0]]++;
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   479
						if (cargos[1] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
							produced[cargos[1]]++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
			}
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   485
		}
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   486
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
8387
30f519812d62 (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: 8360
diff changeset
   489
/**
30f519812d62 (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: 8360
diff changeset
   490
* Get a list of the cargo types that are accepted around the tile.
30f519812d62 (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: 8360
diff changeset
   491
* @param accepts: Destination array of accepted cargo
30f519812d62 (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: 8360
diff changeset
   492
* @param tile: Center of the search area
30f519812d62 (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: 8360
diff changeset
   493
* @param w: Width of the center
30f519812d62 (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: 8360
diff changeset
   494
* @param h: Height of the center
30f519812d62 (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: 8360
diff changeset
   495
* @param rad: Radius of the rectangular search area
30f519812d62 (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: 8360
diff changeset
   496
*/
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   497
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile,
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   498
	int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
{
473
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   500
	memset(accepts, 0, sizeof(AcceptedCargo));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   502
	int x = TileX(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   503
	int y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   505
	/* expand the region by rad tiles on each side
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   506
	 * while making sure that we remain inside the board. */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   507
	int x2 = min(x + w + rad, MapSizeX());
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   508
	int y2 = min(y + h + rad, MapSizeY());
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   509
	int x1 = max(x - rad, 0);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   510
	int y1 = max(y - rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   517
	for (int yc = y1; yc != y2; yc++) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   518
		for (int xc = x1; xc != x2; xc++) {
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   519
			TileIndex tile = TileXY(xc, yc);
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   520
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   521
			if (!IsTileType(tile, MP_STATION)) {
473
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   522
				AcceptedCargo ac;
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   523
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   524
				GetAcceptedCargo(tile, ac);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   525
				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
   526
			}
1424
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   527
		}
c6d120592e98 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   528
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   531
struct ottd_Rectangle {
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   532
	uint min_x;
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   533
	uint min_y;
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   534
	uint max_x;
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   535
	uint max_y;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   536
};
2793
d613eb566917 (svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents: 2767
diff changeset
   537
5103
db210d789741 (svn r7174) -CodeChange: CheckStationSpreadOut() now uses MergePoint() for bounding rectangle calculation.
KUDr
parents: 5098
diff changeset
   538
static inline void MergePoint(ottd_Rectangle* rect, TileIndex tile)
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   539
{
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   540
	uint x = TileX(tile);
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   541
	uint y = TileY(tile);
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   542
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   543
	if (rect->min_x > x) rect->min_x = x;
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   544
	if (rect->min_y > y) rect->min_y = y;
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   545
	if (rect->max_x < x) rect->max_x = x;
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   546
	if (rect->max_y < y) rect->max_y = y;
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   547
}
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   548
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   549
/** Update the acceptance for a station.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   550
 * @param st Station to update
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   551
 * @param show_msg controls whether to display a message that acceptance was changed.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   552
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
static void UpdateStationAcceptance(Station *st, bool show_msg)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
{
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   555
	/* Don't update acceptance for a buoy */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   556
	if (st->IsBuoy()) return;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   557
2793
d613eb566917 (svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents: 2767
diff changeset
   558
	ottd_Rectangle rect;
1507
2d09b13f049f (svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents: 1477
diff changeset
   559
	rect.min_x = MapSizeX();
2d09b13f049f (svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents: 1477
diff changeset
   560
	rect.min_y = MapSizeY();
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   561
	rect.max_x = 0;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   562
	rect.max_y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
	/* old accepted goods types */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   565
	uint old_acc = GetAcceptanceMask(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   567
	/* 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
   568
	if (st->train_tile != 0) {
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   569
		MergePoint(&rect, st->train_tile);
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   570
		MergePoint(&rect,
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   571
			st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1)
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   572
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   574
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
	if (st->airport_tile != 0) {
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6344
diff changeset
   576
		const AirportFTAClass* afc = st->Airport();
3876
c0d426e78b56 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
   577
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   578
		MergePoint(&rect, st->airport_tile);
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   579
		MergePoint(&rect,
3876
c0d426e78b56 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
   580
			st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1)
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   581
		);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   582
	}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   583
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   584
	if (st->dock_tile != 0) MergePoint(&rect, st->dock_tile);
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   585
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   586
	for (const RoadStop *rs = st->bus_stops; rs != NULL; rs = rs->next) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   587
		MergePoint(&rect, rs->xy);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   588
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   590
	for (const RoadStop *rs = st->truck_stops; rs != NULL; rs = rs->next) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   591
		MergePoint(&rect, rs->xy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   593
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   594
	/* And retrieve the acceptance. */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   595
	AcceptedCargo accepts;
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   596
	if (rect.max_x >= rect.min_x) {
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   597
		GetAcceptanceAroundTiles(
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   598
			accepts,
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   599
			TileXY(rect.min_x, rect.min_y),
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   600
			rect.max_x - rect.min_x + 1,
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   601
			rect.max_y - rect.min_y + 1,
9070
e83a2f017f3d (svn r12155) -Fix (r12154): some warnings (always compile before commit)
glx
parents: 9069
diff changeset
   602
			_patches.modified_catchment ? FindCatchmentRadius(st) : (uint)CA_UNMODIFIED
1423
50abec7ebe37 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   603
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
		memset(accepts, 0, sizeof(accepts));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   608
	/* Adjust in case our station only accepts fewer kinds of goods */
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
   609
	for (CargoID i = 0; i < NUM_CARGO; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
		uint amt = min(accepts[i], 15);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   612
		/* Make sure the station can accept the goods type. */
6655
951b0ba32eb1 (svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents: 6632
diff changeset
   613
		bool is_passengers = IsCargoInClass(i, CC_PASSENGERS);
951b0ba32eb1 (svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents: 6632
diff changeset
   614
		if ((!is_passengers && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
951b0ba32eb1 (svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents: 6632
diff changeset
   615
				(is_passengers && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
			amt = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
7970
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7965
diff changeset
   618
		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
   619
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   621
	/* Only show a message in case the acceptance was actually changed. */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   622
	uint new_acc = GetAcceptanceMask(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
	if (old_acc == new_acc)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   625
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   626
	/* show a message to report that the acceptance was changed? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	if (show_msg && st->owner == _local_player && st->facilities) {
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   628
		/* List of accept and reject strings for different number of
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   629
		 * cargo types */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   630
		static const StringID accept_msg[] = {
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   631
			STR_3040_NOW_ACCEPTS,
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   632
			STR_3041_NOW_ACCEPTS_AND,
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   633
		};
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   634
		static const StringID reject_msg[] = {
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   635
			STR_303E_NO_LONGER_ACCEPTS,
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   636
			STR_303F_NO_LONGER_ACCEPTS_OR,
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   637
		};
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   638
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   639
		/* Array of accepted and rejected cargo types */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   640
		CargoID accepts[2] = { CT_INVALID, CT_INVALID };
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   641
		CargoID rejects[2] = { CT_INVALID, CT_INVALID };
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   642
		uint num_acc = 0;
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   643
		uint num_rej = 0;
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   644
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   645
		/* Test each cargo type to see if its acceptange has changed */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   646
		for (CargoID i = 0; i < NUM_CARGO; i++) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   647
			if (HasBit(new_acc, i)) {
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   648
				if (!HasBit(old_acc, i) && num_acc < lengthof(accepts)) {
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   649
					/* New cargo is accepted */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   650
					accepts[num_acc++] = i;
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   651
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
			} else {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   653
				if (HasBit(old_acc, i) && num_rej < lengthof(rejects)) {
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   654
					/* Old cargo is no longer accepted */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   655
					rejects[num_rej++] = i;
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   656
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
			}
5941
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   658
		}
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   659
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   660
		/* Show news message if there are any changes */
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   661
		if (num_acc > 0) ShowRejectOrAcceptNews(st, num_acc, accepts, accept_msg[num_acc - 1]);
3eadff67530f (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5934
diff changeset
   662
		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
   663
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   665
	/* redraw the station view since acceptance changed */
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8511
diff changeset
   666
	InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ACCEPTLIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
5098
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   669
static void UpdateStationSignCoord(Station *st)
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   670
{
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   671
	const StationRect *r = &st->rect;
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
   672
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   673
	if (r->IsEmpty()) return; /* no tiles belong to this station */
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   674
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   675
	/* clamp sign coord to be inside the station rect */
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8387
diff changeset
   676
	st->xy = TileXY(ClampU(TileX(st->xy), r->left, r->right), ClampU(TileY(st->xy), r->top, r->bottom));
5098
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   677
	UpdateStationVirtCoordDirty(st);
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   678
}
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   679
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   680
/** This is called right after a station was deleted.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   681
 * It checks if the whole station is free of substations, and if so, the station will be
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   682
 * deleted after a little while.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   683
 * @param st Station
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   684
 */
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   685
static void DeleteStationIfEmpty(Station *st)
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   686
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
	if (st->facilities == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
		st->delete_ctr = 0;
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
   689
		RebuildStationLists();
28
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   690
		InvalidateWindow(WC_STATION_LIST, st->owner);
27
87c8058a69b5 (svn r28) -Fix removing station merged with oilrig, will reset oilrigs ownership
darkvater
parents: 22
diff changeset
   691
	}
5098
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   692
	/* station remains but it probably lost some parts - station sign should stay in the station boundaries */
bd3e82d14997 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   693
	UpdateStationSignCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
   696
static CommandCost ClearTile_Station(TileIndex tile, byte flags);
977
bcafa4f6550a (svn r1472) -Fix: correct error message for when trying to build a railroad station over a bus/truck/etc-station.
darkvater
parents: 972
diff changeset
   697
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   698
/** Tries to clear the given area.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   699
 * @param tile TileIndex to start check
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   700
 * @param w width of search area
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   701
 * @param h height of search area
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   702
 * @param flags operation to perform
8925
0a0032d000ed (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8920
diff changeset
   703
 * @param invalid_dirs prohibited directions (set of DiagDirections)
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   704
 * @param station StationID to be queried and returned if available
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   705
 * @param check_clear if clearing tile should be performed (in wich case, cost will be added)
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   706
 * @return the cost in case of success, or an error code if it failed.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   707
 */
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   708
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
   709
{
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
   710
	CommandCost cost(EXPENSES_CONSTRUCTION);
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1328
diff changeset
   711
	int allowed_z = -1;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   712
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   713
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   714
		if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) {
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   715
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   716
		}
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5568
diff changeset
   717
7411
d29245c5ca69 (svn r10168) -Fix [FS#879]: cannot build airport when an aircraft is flying over it.
rubidium
parents: 7353
diff changeset
   718
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   720
		uint z;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   721
		Slope tileh = GetTileSlope(tile_cur, &z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   723
		/* Prohibit building if
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   724
		 *   1) The tile is "steep" (i.e. stretches two height levels)
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   725
		 * -OR-
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   726
		 *   2) The tile is non-flat if
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   727
		 *     a) the player building is an "old-school" AI
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   728
		 *   -OR-
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   729
		 *     b) the build_on_slopes switch is disabled
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   730
		 */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   731
		if (IsSteepSlope(tileh) ||
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   732
				((_is_old_ai_player || !_patches.build_on_slopes) && tileh != SLOPE_FLAT)) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   733
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   736
		int flat_z = z;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   737
		if (tileh != SLOPE_FLAT) {
8925
0a0032d000ed (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8920
diff changeset
   738
			/* need to check so the entrance to the station is not pointing at a slope.
0a0032d000ed (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8920
diff changeset
   739
			 * This must be valid for all station tiles, as the user can remove single station tiles. */
0a0032d000ed (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8920
diff changeset
   740
			if ((HasBit(invalid_dirs, DIAGDIR_NE) && !(tileh & SLOPE_NE)) ||
0a0032d000ed (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8920
diff changeset
   741
			    (HasBit(invalid_dirs, DIAGDIR_SE) && !(tileh & SLOPE_SE)) ||
0a0032d000ed (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8920
diff changeset
   742
			    (HasBit(invalid_dirs, DIAGDIR_SW) && !(tileh & SLOPE_SW)) ||
0a0032d000ed (svn r11999) -Fix: Do entrance-slope-check for every tile of railstations.
frosch
parents: 8920
diff changeset
   743
			    (HasBit(invalid_dirs, DIAGDIR_NW) && !(tileh & SLOPE_NW))) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   744
				return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
			}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   746
			cost.AddCost(_price.terraform);
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   747
			flat_z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   749
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   750
		/* 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
   751
		if (allowed_z == -1) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   752
			/* first tile */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
			allowed_z = flat_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		} else if (allowed_z != flat_z) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   755
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   758
		/* if station is set, then we have special handling to allow building on top of already existing stations.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   759
		 * so station points to INVALID_STATION if we can build on any station.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   760
		 * Or it points to a station if we're only allowed to build on exactly that station. */
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   761
		if (station != NULL && IsTileType(tile_cur, MP_STATION)) {
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
   762
			if (!IsRailwayStation(tile_cur)) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   763
				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
   764
			} else {
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
   765
				StationID st = GetStationIndex(tile_cur);
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   766
				if (*station == INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
					*station = st;
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   768
				} else if (*station != st) {
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   769
					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
   770
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
			}
7216
637511194fec (svn r9952) -Fix r9951: it was not possible to build a drive-through station over a road/tram
glx
parents: 7215
diff changeset
   772
		} else if (check_clear) {
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
   773
			CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   774
			if (CmdFailed(ret)) return ret;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
   775
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
		}
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   777
	} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   782
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
   783
{
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   784
	uint curw = st->trainst_w;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   785
	uint curh = st->trainst_h;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   786
	TileIndex tile = fin[0];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
	uint w = fin[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
	uint h = fin[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
	if (_patches.nonuniform_stations) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   791
		/* determine new size of train station region.. */
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   792
		int x = min(TileX(st->train_tile), TileX(tile));
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   793
		int y = min(TileY(st->train_tile), TileY(tile));
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   794
		curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x;
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   795
		curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   796
		tile = TileXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
	} else {
8594
dfd42ca57d74 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8592
diff changeset
   798
		/* do not allow modifying non-uniform stations,
dfd42ca57d74 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8592
diff changeset
   799
		 * the uniform-stations code wouldn't handle it well */
dfd42ca57d74 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8592
diff changeset
   800
		BEGIN_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
dfd42ca57d74 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8592
diff changeset
   801
			if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station
8920
04df97185061 (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: 8909
diff changeset
   802
				_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
8594
dfd42ca57d74 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8592
diff changeset
   803
				return false;
dfd42ca57d74 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8592
diff changeset
   804
			}
dfd42ca57d74 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8592
diff changeset
   805
		END_TILE_LOOP(t, st->trainst_w, st->trainst_h, st->train_tile)
dfd42ca57d74 (svn r11659) -Fix [FS#1563]: do not allow modifying non-uniform stations when non-uniform stations are disabled
smatz
parents: 8592
diff changeset
   806
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   807
		/* check so the orientation is the same */
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
   808
		if (GetRailStationAxis(st->train_tile) != axis) {
8920
04df97185061 (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: 8909
diff changeset
   809
			_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   810
			return false;
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   811
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   813
		/* check if the new station adjoins the old station in either direction */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   814
		if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   815
			/* above */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
			curh += h;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   817
		} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   818
			/* below */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   819
			tile -= TileDiffXY(0, curh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
			curh += h;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   821
		} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   822
			/* to the left */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
			curw += w;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   824
		} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   825
			/* to the right */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   826
			tile -= TileDiffXY(curw, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
			curw += w;
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   828
		} else {
8920
04df97185061 (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: 8909
diff changeset
   829
			_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
			return false;
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   831
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
	}
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   833
	/* make sure the final size is not too big. */
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   834
	if (curw > _patches.station_spread || curh > _patches.station_spread) {
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   835
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   836
		return false;
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   837
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   839
	/* now tile contains the new value for st->train_tile
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   840
	 * 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
   841
	fin[0] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
	fin[1] = curw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
	fin[2] = curh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   847
static inline byte *CreateSingle(byte *layout, int n)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
	do *layout++ = 0; while (--i);
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   851
	layout[((n - 1) >> 1) - n] = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   855
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
   856
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
	do *layout++ = b; while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
	if (n > 4) {
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   860
		layout[0 - n] = 0;
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
   861
		layout[n - 1 - n] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   866
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
   867
{
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   868
	if (statspec != NULL && statspec->lengths >= plat_len &&
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   869
			statspec->platforms[plat_len - 1] >= numtracks &&
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   870
			statspec->layouts[plat_len - 1][numtracks - 1]) {
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   871
		/* Custom layout defined, follow it. */
3676
48444d881fbe (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   872
		memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1],
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   873
			plat_len * numtracks);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   874
		return;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   875
	}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   876
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	if (plat_len == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
		CreateSingle(layout, numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	} else {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   880
		if (numtracks & 1) layout = CreateSingle(layout, plat_len);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   881
		numtracks >>= 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
		while (--numtracks >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
			layout = CreateMulti(layout, plat_len, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
			layout = CreateMulti(layout, plat_len, 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   890
/** Build railroad station
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
   891
 * @param tile_org starting position of station dragging/placement
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6959
diff changeset
   892
 * @param flags operation to perform
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   893
 * @param p1 various bitstuffed elements
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   894
 * - p1 = (bit  0)    - orientation (Axis)
2140
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   895
 * - p1 = (bit  8-15) - number of tracks
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   896
 * - p1 = (bit 16-23) - platform length
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   897
 * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   898
 * @param p2 various bitstuffed elements
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   899
 * - p2 = (bit  0- 3) - railtype (p2 & 0xF)
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   900
 * - p2 = (bit  8-15) - custom station class
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   901
 * - p2 = (bit 16-23) - custom station id
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
   903
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
   904
{
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   905
	int w_org, h_org;
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
   906
	CommandCost ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	/* Does the authority allow this? */
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   909
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
8732
b18f578f7c16 (svn r11800) -Codechange: move some functions to a more logical location + some type safety.
rubidium
parents: 8726
diff changeset
   910
	if (!ValParamRailtype((RailType)(p2 & 0xF))) return CMD_ERROR;
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   911
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   912
	/* unpack parameters */
6460
b3017e083031 (svn r8876) -Fix
tron
parents: 6459
diff changeset
   913
	Axis axis = Extract<Axis, 0>(p1);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   914
	uint numtracks = GB(p1,  8, 8);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   915
	uint plat_len  = GB(p1, 16, 8);
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   916
	if (axis == AXIS_X) {
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   917
		w_org = plat_len;
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   918
		h_org = numtracks;
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   919
	} else {
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   920
		h_org = plat_len;
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   921
		w_org = numtracks;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
1781
92e08797c84b (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   924
	if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR;
92e08797c84b (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   925
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   926
	/* these values are those that will be stored in train_tile and station_platforms */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   927
	uint finalvalues[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	finalvalues[0] = tile_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	finalvalues[1] = w_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
	finalvalues[2] = h_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   932
	/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
   933
	StationID est = INVALID_STATION;
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   934
	/* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   935
	 * for detail info, see:
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   936
	 * https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   937
	ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   938
	if (CmdFailed(ret)) return ret;
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
   939
	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
   940
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   941
	Station *st = NULL;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   942
	bool check_surrounding = true;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   943
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   944
	if (_patches.adjacent_stations) {
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   945
		if (est != INVALID_STATION) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   946
			if (HasBit(p1, 24)) {
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   947
				/* You can't build an adjacent station over the top of one that
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   948
				 * already exists. */
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   949
				return_cmd_error(STR_MUST_REMOVE_RAILWAY_STATION_FIRST);
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   950
			} else {
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   951
				/* Extend the current station, and don't check whether it will
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   952
				 * be near any other stations. */
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   953
				st = GetStation(est);
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   954
				check_surrounding = false;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   955
			}
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   956
		} else {
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   957
			/* There's no station here. Don't check the tiles surrounding this
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   958
			 * one if the player wanted to build an adjacent station. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   959
			if (HasBit(p1, 24)) check_surrounding = false;
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   960
		}
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   961
	}
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   962
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   963
	if (check_surrounding) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   964
		/* Make sure there are no similar stations around us. */
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   965
		st = GetStationAround(tile_org, w_org, h_org, est);
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   966
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
   967
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   969
	/* See if there is a deleted station close to us. */
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
   970
	if (st == NULL) st = GetClosestStationFromTile(tile_org);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   972
	/* In case of new station if DC_EXEC is NOT set we still need to create the station
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   973
	 * to test if everything is OK. In this case we need to delete it before return. */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
   974
	AutoPtrT<Station> st_auto_delete;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   975
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	if (st != NULL) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   977
		/* Reuse an existing station. */
6390
542cf60254b2 (svn r8794) -Fix
tron
parents: 6378
diff changeset
   978
		if (st->owner != _current_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
			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
   980
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
		if (st->train_tile != 0) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   982
			/* check if we want to expanding an already existing station? */
2422
914a12dee832 (svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents: 2395
diff changeset
   983
			if (_is_old_ai_player || !_patches.join_stations)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
				return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD);
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   985
			if (!CanExpandRailroadStation(st, finalvalues, axis))
1189
5ff98d7485b3 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   986
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
   989
		/* XXX can't we pack this in the "else" part of the if above? */
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
   990
		if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR;
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4399
diff changeset
   991
	} else {
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   992
		/* allocate and initialize new station */
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   993
		st = new Station(tile_org);
7873
b3bccdcf85ef (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7872
diff changeset
   994
		if (st == NULL) return_cmd_error(STR_3008_TOO_MANY_STATIONS_LOADING);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   995
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   996
		/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
   997
		st_auto_delete = st;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
   998
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
		st->town = ClosestTownFromTile(tile_org, (uint)-1);
8309
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
  1000
		if (!GenerateStationName(st, tile_org, STATIONNAMING_RAIL)) return CMD_ERROR;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1001
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1002
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  1003
			SetBit(st->town->have_ratings, _current_player);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1004
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1007
	/* Check if the given station class is valid */
8792
1f062b9f10f6 (svn r11860) -Fix: Test station class validity against number of classes, not abosolute limit.
peter1138
parents: 8760
diff changeset
  1008
	if (GB(p2, 8, 8) >= GetNumStationClasses()) return CMD_ERROR;
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1009
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1010
	/* Check if we can allocate a custom stationspec to this station */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1011
	const StationSpec *statspec = GetCustomStationSpec((StationClassID)GB(p2, 8, 8), GB(p2, 16, 8));
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1012
	int specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC);
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1013
	if (specindex == -1) return CMD_ERROR;
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1014
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1015
	if (statspec != NULL) {
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1016
		/* Perform NewStation checks */
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1017
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1018
		/* Check if the station size is permitted */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  1019
		if (HasBit(statspec->disallowed_platforms, numtracks - 1) || HasBit(statspec->disallowed_lengths, plat_len - 1)) {
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1020
			return CMD_ERROR;
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1021
		}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1022
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1023
		/* Check if the station is buildable */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  1024
		if (HasBit(statspec->callbackmask, CBM_STATION_AVAIL) && GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) {
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1025
			return CMD_ERROR;
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1026
		}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1027
	}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1028
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
	if (flags & DC_EXEC) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1030
		TileIndexDiff tile_delta;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
		byte *layout_ptr;
3769
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1032
		byte numtracks_orig;
2824
a7a9d3239884 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1033
		Track track;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1035
		/* Now really clear the land below the station
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1036
		 * It should never return CMD_ERROR.. but you never know ;)
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1037
		 * (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) */
3183
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1038
		ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
cf71bd234ebd (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1039
		if (CmdFailed(ret)) return ret;
313
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
  1040
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
		st->train_tile = finalvalues[0];
5972
564f98b055d1 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5969
diff changeset
  1042
		st->AddFacility(FACIL_TRAIN, finalvalues[0]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
		st->trainst_w = finalvalues[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
		st->trainst_h = finalvalues[2];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1046
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1047
		st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1048
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
  1049
		tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
  1050
		track = AxisToTrack(axis);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1051
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1052
		layout_ptr = (byte*)alloca(numtracks * plat_len);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1053
		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
  1054
3769
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1055
		numtracks_orig = numtracks;
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1056
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
		do {
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
  1058
			TileIndex tile = tile_org;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
			int w = plat_len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
			do {
3769
2fd087fd336f (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1061
				byte layout = *layout_ptr++;
7052
580522971dfa (svn r9758) -Fix (FS#756): Ignore bit 1 (axis) of station tile layouts
peter1138
parents: 6996
diff changeset
  1062
				MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p2, 0, 4));
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1063
				SetCustomStationSpecIndex(tile, specindex);
3742
8528d7737361 (svn r4724) - Newstations: Add per-tile random data for station tiles.
peter1138
parents: 3741
diff changeset
  1064
				SetStationTileRandomBits(tile, GB(Random(), 0, 4));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1066
				if (statspec != NULL) {
3784
41d43d1191a5 (svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents: 3775
diff changeset
  1067
					/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
41d43d1191a5 (svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents: 3775
diff changeset
  1068
					uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false);
8360
ba65cb849f4a (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: 8353
diff changeset
  1069
ba65cb849f4a (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: 8353
diff changeset
  1070
					/* As the station is not yet completely finished, the station does not yet exist. */
ba65cb849f4a (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: 8353
diff changeset
  1071
					uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, NULL, tile);
7052
580522971dfa (svn r9758) -Fix (FS#756): Ignore bit 1 (axis) of station tile layouts
peter1138
parents: 6996
diff changeset
  1072
					if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis);
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1073
				}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1074
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
				tile += tile_delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
			} while (--w);
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8798
diff changeset
  1077
			AddTrackToSignalBuffer(tile_org, track, _current_player);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1078
			YapfNotifyTrackLayoutChange(tile_org, track);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1079
			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
  1080
		} while (--numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
7319
f884be171f04 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 7257
diff changeset
  1082
		st->MarkTilesDirty(false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
		UpdateStationAcceptance(st, false);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1085
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
		InvalidateWindow(WC_STATION_LIST, st->owner);
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1087
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1088
		/* success, so don't delete the new station */
7794
ccc691b566eb (svn r10646) -Cleanup: AutoPtrT<>::Release() renamed to Detach()
KUDr
parents: 7768
diff changeset
  1089
		st_auto_delete.Detach();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
static void MakeRailwayStationAreaSmaller(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
	uint w = st->trainst_w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
	uint h = st->trainst_h;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1099
	TileIndex tile = st->train_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
restart:
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1102
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1103
	/* too small? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
	if (w != 0 && h != 0) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1105
		/* check the left side, x = constant, y changes */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1106
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1107
			/* the left side is unused? */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1108
			if (++i == h) {
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1109
				tile += TileDiffXY(1, 0);
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1110
				w--;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1111
				goto restart;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1112
			}
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1113
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1115
		/* check the right side, x = constant, y changes */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1116
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1117
			/* the right side is unused? */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1118
			if (++i == h) {
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1119
				w--;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1120
				goto restart;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1121
			}
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1122
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1124
		/* check the upper side, y = constant, x changes */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1125
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1126
			/* the left side is unused? */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1127
			if (++i == w) {
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1128
				tile += TileDiffXY(0, 1);
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1129
				h--;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1130
				goto restart;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1131
			}
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1132
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1134
		/* check the lower side, y = constant, x changes */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1135
		for (uint i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1136
			/* the left side is unused? */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1137
			if (++i == w) {
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1138
				h--;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1139
				goto restart;
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1140
			}
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1141
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
		tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
	st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	st->train_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1151
/** Remove a single tile from a railroad station.
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1152
 * This allows for custom-built station with holes and weird layouts
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1153
 * @param tile tile of station piece to remove
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6959
diff changeset
  1154
 * @param flags operation to perform
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1155
 * @param p1 start_tile
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1156
 * @param p2 unused
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1157
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1158
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
  1159
{
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1160
	TileIndex start = p1 == 0 ? tile : p1;
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1161
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1162
	/* Count of the number of tiles removed */
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1163
	int quantity = 0;
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1164
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1165
	if (tile >= MapSize() || start >= MapSize()) return CMD_ERROR;
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1166
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1167
	/* make sure sx,sy are smaller than ex,ey */
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1168
	int ex = TileX(tile);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1169
	int ey = TileY(tile);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1170
	int sx = TileX(start);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1171
	int sy = TileY(start);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1172
	if (ex < sx) Swap(ex, sx);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1173
	if (ey < sy) Swap(ey, sy);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1174
	tile = TileXY(sx, sy);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1175
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1176
	int size_x = ex - sx + 1;
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1177
	int size_y = ey - sy + 1;
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1178
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1179
	/* Do the action for every tile into the area */
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1180
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
8506
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1181
		/* Make sure the specified tile is a railroad station */
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1182
		if (!IsTileType(tile2, MP_STATION) || !IsRailwayStation(tile2)) {
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1183
			continue;
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1184
		}
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1185
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1186
		/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1187
		if (!EnsureNoVehicleOnGround(tile2)) {
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1188
			continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
		}
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1190
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1191
		/* Check ownership of station */
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1192
		Station *st = GetStationByTile(tile2);
8506
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1193
		if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1194
			continue;
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1195
		}
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1196
8506
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1197
		/* Do not allow removing from stations if non-uniform stations are not enabled
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1198
		 * The check must be here to give correct error message
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1199
 		 */
8920
04df97185061 (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: 8909
diff changeset
  1200
		if (!_patches.nonuniform_stations) return_cmd_error(STR_NONUNIFORM_STATIONS_DISALLOWED);
8506
578228a9044b (svn r11570) -Fix: do not flood rail station tiles when there is a vehicle on it (when non-uniform stations are ON)
smatz
parents: 8450
diff changeset
  1201
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1202
		/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1203
		quantity++;
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1204
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1205
		if (flags & DC_EXEC) {
8796
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8792
diff changeset
  1206
			/* read variables before the station tile is removed */
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1207
			uint specindex = GetCustomStationSpecIndex(tile2);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1208
			Track track = GetRailStationTrack(tile2);
8796
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8792
diff changeset
  1209
			Owner owner = GetTileOwner(tile2);
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8792
diff changeset
  1210
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1211
			DoClearSquare(tile2);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1212
			st->rect.AfterRemoveTile(st, tile2);
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8798
diff changeset
  1213
			AddTrackToSignalBuffer(tile2, track, owner);
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1214
			YapfNotifyTrackLayoutChange(tile2, track);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1215
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1216
			DeallocateSpecFromStation(st, specindex);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1217
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1218
			/* now we need to make the "spanned" area of the railway station smaller
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1219
			 * if we deleted something at the edges.
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1220
			 * we also need to adjust train_tile. */
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1221
			MakeRailwayStationAreaSmaller(st);
7319
f884be171f04 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 7257
diff changeset
  1222
			st->MarkTilesDirty(false);
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1223
			UpdateStationSignCoord(st);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1224
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1225
			/* if we deleted the whole station, delete the train facility. */
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1226
			if (st->train_tile == 0) {
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1227
				st->facilities &= ~FACIL_TRAIN;
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1228
				InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
7092
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1229
				UpdateStationVirtCoordDirty(st);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1230
				DeleteStationIfEmpty(st);
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1231
			}
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1232
		}
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1233
	} END_TILE_LOOP(tile2, size_x, size_y, tile)
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1234
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1235
	/* If we've not removed any tiles, give an error */
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1236
	if (quantity == 0) return CMD_ERROR;
3fa66ad549c8 (svn r9810) -Feature: Add drag and drop removal of station tiles (Wolf01)
peter1138
parents: 7052
diff changeset
  1237
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  1238
	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
  1239
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
3928
791f04fb29ad (svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents: 3900
diff changeset
  1241
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1242
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
  1243
{
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1244
	/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1245
	if (_current_player == OWNER_WATER && _patches.nonuniform_stations)
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1246
		return DoCommand(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1247
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	/* Current player owns the station? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
	/* determine width and height of platforms */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
	tile = st->train_tile;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1254
	int w = st->trainst_w;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1255
	int h = st->trainst_h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1256
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
	assert(w != 0 && h != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  1259
	CommandCost cost(EXPENSES_CONSTRUCTION);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
	/* clear all areas of the station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
		int w_bak = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
		do {
8796
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8792
diff changeset
  1264
			/* for nonuniform stations, only remove tiles that are actually train station tiles */
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1265
			if (st->TileBelongsToRailStation(tile)) {
8254
5de2bbd26163 (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: 8235
diff changeset
  1266
				if (!EnsureNoVehicleOnGround(tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
					return CMD_ERROR;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
  1268
				cost.AddCost(_price.remove_rail_station);
2824
a7a9d3239884 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1269
				if (flags & DC_EXEC) {
8796
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8792
diff changeset
  1270
					/* read variables before the station tile is removed */
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1271
					Track track = GetRailStationTrack(tile);
8796
81b0d6b54a1f (svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz
parents: 8792
diff changeset
  1272
					Owner owner = GetTileOwner(tile); // _current_player can be OWNER_WATER
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
					DoClearSquare(tile);
8802
e08824cdab46 (svn r11871) -Fix [FS#1074]: do not update signals after each tile when building/removing a large block of track/signals/station
smatz
parents: 8798
diff changeset
  1274
					AddTrackToSignalBuffer(tile, track, owner);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1275
					YapfNotifyTrackLayoutChange(tile, track);
2824
a7a9d3239884 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1276
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
			}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1278
			tile += TileDiffXY(1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
		} while (--w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
		w = w_bak;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1281
		tile += TileDiffXY(-w, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	} while (--h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	if (flags & DC_EXEC) {
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1285
		st->rect.AfterRemoveRect(st, st->train_tile, st->trainst_w, st->trainst_h);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1286
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
		st->train_tile = 0;
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1288
		st->trainst_w = st->trainst_h = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
		st->facilities &= ~FACIL_TRAIN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
3587
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1291
		free(st->speclist);
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1292
		st->num_specs = 0;
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1293
		st->speclist  = NULL;
2eb52db0b872 (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1294
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1295
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1299
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
6694
a10a42eefd52 (svn r9425) -Codechange/Fix (FS#689): Housekeeping in the convert rail functions: Changed the order of error checks to generate more meaningful error messages, added some doxygen comments and replaced bitshifting by proper mathematical operations
celestar
parents: 6683
diff changeset
  1303
/**
6984
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6980
diff changeset
  1304
 * @param truck_station Determines whether a stop is RoadStop::BUS or RoadStop::TRUCK
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6980
diff changeset
  1305
 * @param st The Station to do the whole procedure for
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1306
 * @return a pointer to where to link a new RoadStop*
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
  1307
 */
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1308
static RoadStop **FindRoadStopSpot(bool truck_station, Station* st)
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1309
{
3691
7e1ad0718ed8 (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1310
	RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1311
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1312
	if (*primary_stop == NULL) {
6984
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6980
diff changeset
  1313
		/* we have no roadstop of the type yet, so write a "primary stop" */
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1314
		return primary_stop;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1315
	} else {
6984
045168d13eef (svn r9669) -Documentation: some more doxygen fixes
belugas
parents: 6980
diff changeset
  1316
		/* there are stops already, so append to the end of the list */
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1317
		RoadStop *stop = *primary_stop;
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1318
		while (stop->next != NULL) stop = stop->next;
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1319
		return &stop->next;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1320
	}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1321
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1322
3691
7e1ad0718ed8 (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1323
/** Build a bus or truck stop
7e1ad0718ed8 (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1324
 * @param tile tile to build the stop at
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6959
diff changeset
  1325
 * @param flags operation to perform
3333
41f8abe65d1e (svn r4111) Fix/Remove some stale comments
tron
parents: 3315
diff changeset
  1326
 * @param p1 entrance direction (DiagDirection)
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1327
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1328
 *           bit 1: 0 for normal, 1 for drive-through
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  1329
 *           bit 2..4: the roadtypes
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1330
 *           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
  1331
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1332
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
  1333
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  1334
	bool type = HasBit(p2, 0);
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  1335
	bool is_drive_through = HasBit(p2, 1);
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9016
diff changeset
  1336
	bool build_over_road  = is_drive_through && IsNormalRoadTile(tile);
6393
7c0211e6a6c8 (svn r8797) -Fix (8741): the 'drive through station built on town owned road' bit was not set.
rubidium
parents: 6392
diff changeset
  1337
	bool town_owned_road  = build_over_road && IsTileOwner(tile, OWNER_TOWN);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  1338
	RoadTypes rts = (RoadTypes)GB(p2, 2, 3);
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  1339
8353
49a1d9b9d937 (svn r11407) -Fix: do not allow building of tram-tracks when they are not available (SmatZ)
truelight
parents: 8345
diff changeset
  1340
	if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_player, rts)) return CMD_ERROR;
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1341
7173
0a9b13debedf (svn r9908) -Codechange: prepare the station picker for more road types.
rubidium
parents: 7170
diff changeset
  1342
	/* Trams only have drive through stops */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  1343
	if (!is_drive_through && HasBit(rts, ROADTYPE_TRAM)) return CMD_ERROR;
7173
0a9b13debedf (svn r9908) -Codechange: prepare the station picker for more road types.
rubidium
parents: 7170
diff changeset
  1344
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1345
	/* Saveguard the parameters */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1346
	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1347
	/* If it is a drive-through stop check for valid axis */
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1348
	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
6344
c5c1b17c8925 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6338
diff changeset
  1349
	/* Road bits in the wrong direction */
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  1350
	if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION);
7199
11f9a87e9ac5 (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: 7187
diff changeset
  1351
11f9a87e9ac5 (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: 7187
diff changeset
  1352
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
11f9a87e9ac5 (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: 7187
diff changeset
  1353
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
  1354
	CommandCost cost;
7199
11f9a87e9ac5 (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: 7187
diff changeset
  1355
6344
c5c1b17c8925 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6338
diff changeset
  1356
	/* Not allowed to build over this road */
6898
fa8a3e592990 (svn r9532) -Fix (r8741) [FS#708]: Make errors when building drive through road stops more descriptive.
maedhros
parents: 6890
diff changeset
  1357
	if (build_over_road) {
fa8a3e592990 (svn r9532) -Fix (r8741) [FS#708]: Make errors when building drive through road stops more descriptive.
maedhros
parents: 6890
diff changeset
  1358
		if (IsTileOwner(tile, OWNER_TOWN) && !_patches.road_stop_on_town_road) return_cmd_error(STR_DRIVE_THROUGH_ERROR_ON_TOWN_ROAD);
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  1359
8873
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1360
		RoadTypes cur_rts = GetRoadTypes(tile);
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1361
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1362
		/* there is a road, check if we can build road+tram stop over it */
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1363
		if (HasBit(cur_rts, ROADTYPE_ROAD)) {
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1364
			Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1365
			if (road_owner != OWNER_TOWN && road_owner != OWNER_NONE && !CheckOwnership(road_owner)) return CMD_ERROR;
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1366
		}
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1367
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1368
		/* there is a tram, check if we can build road+tram stop over it */
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1369
		if (HasBit(cur_rts, ROADTYPE_TRAM)) {
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1370
			Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1371
			if (tram_owner != OWNER_NONE && !CheckOwnership(tram_owner)) return CMD_ERROR;
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1372
		}
99dee7eb17e0 (svn r11944) -Fix: allow building drive-through road/tram stops at road/tram track that has no owner
smatz
parents: 8802
diff changeset
  1373
7257
18c8b085008d (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 7229
diff changeset
  1374
		/* Don't allow building the roadstop when vehicles are already driving on it */
18c8b085008d (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 7229
diff changeset
  1375
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
18c8b085008d (svn r9996) -Fix: be more strict when building/upgrading roads and/or road stops.
rubidium
parents: 7229
diff changeset
  1376
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  1377
		/* Do not remove roadtypes! */
7199
11f9a87e9ac5 (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: 7187
diff changeset
  1378
		rts |= cur_rts;
6898
fa8a3e592990 (svn r9532) -Fix (r8741) [FS#708]: Make errors when building drive through road stops more descriptive.
maedhros
parents: 6890
diff changeset
  1379
	}
7216
637511194fec (svn r9952) -Fix r9951: it was not possible to build a drive-through station over a road/tram
glx
parents: 7215
diff changeset
  1380
	cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road);
7215
ef3e4b2bc075 (svn r9951) -Fix: slope check was incomplete when building road over tram track (and vice-versa)
glx
parents: 7199
diff changeset
  1381
	if (CmdFailed(cost)) return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1383
	Station *st = NULL;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1384
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  1385
	if (!_patches.adjacent_stations || !HasBit(p2, 5)) {
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1386
		st = GetStationAround(tile, 1, 1, INVALID_STATION);
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1387
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1388
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
	/* Find a station close to us */
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
  1391
	if (st == NULL) st = GetClosestStationFromTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1393
	/* give us a road stop in the list, and check if something went wrong */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1394
	RoadStop *road_stop = new RoadStop(tile);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1395
	if (road_stop == NULL) {
8920
04df97185061 (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: 8909
diff changeset
  1396
		return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1397
	}
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1398
6084
75d052b142e5 (svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents: 5972
diff changeset
  1399
	/* ensure that in case of error (or no DC_EXEC) the new road stop gets deleted upon return */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
  1400
	AutoPtrT<RoadStop> rs_auto_delete(road_stop);
6084
75d052b142e5 (svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents: 5972
diff changeset
  1401
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  1402
	if (st != NULL &&
6088
c11f7acc18bd (svn r8403) -Fix (r8402): Forgot to remove an enum
celestar
parents: 6087
diff changeset
  1403
			GetNumRoadStopsInStation(st, RoadStop::BUS) + GetNumRoadStopsInStation(st, RoadStop::TRUCK) >= RoadStop::LIMIT) {
8920
04df97185061 (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: 8909
diff changeset
  1404
		return_cmd_error(type ? STR_TOO_MANY_TRUCK_STOPS : STR_TOO_MANY_BUS_STOPS);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1405
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1406
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1407
	/* In case of new station if DC_EXEC is NOT set we still need to create the station
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1408
	 * to test if everything is OK. In this case we need to delete it before return. */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
  1409
	AutoPtrT<Station> st_auto_delete;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1410
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
	if (st != NULL) {
6390
542cf60254b2 (svn r8794) -Fix
tron
parents: 6378
diff changeset
  1412
		if (st->owner != _current_player) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1414
		}
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1415
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1416
		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
  1417
	} else {
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1418
		/* allocate and initialize new station */
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1419
		st = new Station(tile);
7873
b3bccdcf85ef (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7872
diff changeset
  1420
		if (st == NULL) 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
  1421
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1422
		/* ensure that in case of error (or no DC_EXEC) the new station gets deleted upon return */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
  1423
		st_auto_delete = st;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1424
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1425
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1426
		Town *t = st->town = ClosestTownFromTile(tile, (uint)-1);
8309
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
  1427
		if (!GenerateStationName(st, tile, STATIONNAMING_ROAD)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1429
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  1430
			SetBit(t->have_ratings, _current_player);
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1431
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
  1436
	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
  1437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
	if (flags & DC_EXEC) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1439
		/* Insert into linked list of RoadStops */
6157
c64e66c3804e (svn r8531) -Fix
tron
parents: 6156
diff changeset
  1440
		RoadStop **currstop = FindRoadStopSpot(type, st);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1441
		*currstop = road_stop;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1442
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1443
		/*initialize an empty station */
5972
564f98b055d1 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5969
diff changeset
  1444
		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
  1445
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1446
		st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1447
6424
65bf2bbe789d (svn r8833) -Fix
tron
parents: 6419
diff changeset
  1448
		RoadStop::Type rs_type = type ? RoadStop::TRUCK : RoadStop::BUS;
65bf2bbe789d (svn r8833) -Fix
tron
parents: 6419
diff changeset
  1449
		if (is_drive_through) {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  1450
			MakeDriveThroughRoadStop(tile, st->owner, st->index, rs_type, rts, (Axis)p1, town_owned_road);
6424
65bf2bbe789d (svn r8833) -Fix
tron
parents: 6419
diff changeset
  1451
		} else {
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  1452
			MakeRoadStop(tile, st->owner, st->index, rs_type, rts, (DiagDirection)p1);
6424
65bf2bbe789d (svn r8833) -Fix
tron
parents: 6419
diff changeset
  1453
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
		UpdateStationAcceptance(st, false);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1457
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
		InvalidateWindow(WC_STATION_LIST, st->owner);
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1459
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
6084
75d052b142e5 (svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents: 5972
diff changeset
  1460
		/* success, so don't delete the new station and the new road stop */
7794
ccc691b566eb (svn r10646) -Cleanup: AutoPtrT<>::Release() renamed to Detach()
KUDr
parents: 7768
diff changeset
  1461
		st_auto_delete.Detach();
ccc691b566eb (svn r10646) -Cleanup: AutoPtrT<>::Release() renamed to Detach()
KUDr
parents: 7768
diff changeset
  1462
		rs_auto_delete.Detach();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
9016
2b722bde93ec (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: 9015
diff changeset
  1467
2b722bde93ec (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: 9015
diff changeset
  1468
static void *ClearRoadStopStatusEnum(Vehicle *v, void *)
2b722bde93ec (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: 9015
diff changeset
  1469
{
2b722bde93ec (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: 9015
diff changeset
  1470
	if (v->type == VEH_ROAD) ClrBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
2b722bde93ec (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: 9015
diff changeset
  1471
2b722bde93ec (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: 9015
diff changeset
  1472
	return NULL;
2b722bde93ec (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: 9015
diff changeset
  1473
}
2b722bde93ec (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: 9015
diff changeset
  1474
2b722bde93ec (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: 9015
diff changeset
  1475
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1476
/** Remove a bus station
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1477
 * @param st Station to remove
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1478
 * @param flags operation to perform
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1479
 * @param tile TileIndex been queried
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1480
 * @return cost or failure of operation
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1481
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1482
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
  1483
{
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1484
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
		return CMD_ERROR;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1486
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1488
	bool is_truck = IsTruckStop(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1489
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1490
	RoadStop **primary_stop;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1491
	RoadStop *cur_stop;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1492
	if (is_truck) { // truck stop
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1493
		primary_stop = &st->truck_stops;
6087
b56c54f79335 (svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop
celestar
parents: 6085
diff changeset
  1494
		cur_stop = GetRoadStopByTile(tile, RoadStop::TRUCK);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1495
	} else {
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1496
		primary_stop = &st->bus_stops;
6087
b56c54f79335 (svn r8402) -Codechange: Move RoadStop-specific enums to the RoadStop class, and changed a one-member enum into a static const. Simplify their naming and add some doxygen-comments to RoadStop
celestar
parents: 6085
diff changeset
  1497
		cur_stop = GetRoadStopByTile(tile, RoadStop::BUS);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1498
	}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1499
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1500
	assert(cur_stop != NULL);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1501
9016
2b722bde93ec (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: 9015
diff changeset
  1502
	/* don't do the check for drive-through road stops when company bankrupts */
2b722bde93ec (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: 9015
diff changeset
  1503
	if (IsDriveThroughStopTile(tile) && (flags & DC_BANKRUPT)) {
2b722bde93ec (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: 9015
diff changeset
  1504
		/* remove the 'going through road stop' status from all vehicles on that tile */
2b722bde93ec (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: 9015
diff changeset
  1505
		if (flags & DC_EXEC) VehicleFromPos(tile, NULL, &ClearRoadStopStatusEnum);
2b722bde93ec (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: 9015
diff changeset
  1506
	} else {
2b722bde93ec (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: 9015
diff changeset
  1507
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
2b722bde93ec (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: 9015
diff changeset
  1508
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
	if (flags & DC_EXEC) {
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1511
		if (*primary_stop == cur_stop) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1512
			/* removed the first stop in the list */
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1513
			*primary_stop = cur_stop->next;
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1514
			/* removed the only stop? */
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1515
			if (*primary_stop == NULL) {
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1516
				st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP);
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1517
			}
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1518
		} else {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1519
			/* tell the predecessor in the list to skip this stop */
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1520
			RoadStop *pred = *primary_stop;
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1521
			while (pred->next != cur_stop) pred = pred->next;
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  1522
			pred->next = cur_stop->next;
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1523
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1525
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
5959
6a4c261987c3 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5948
diff changeset
  1526
		delete cur_stop;
4398
e889842a75a1 (svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents: 4397
diff changeset
  1527
		DoClearSquare(tile);
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1528
		st->rect.AfterRemoveTile(st, tile);
4398
e889842a75a1 (svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents: 4397
diff changeset
  1529
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  1534
	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
  1535
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1537
/** Remove a bus or truck stop
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1538
 * @param tile tile to remove the stop from
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6959
diff changeset
  1539
 * @param flags operation to perform
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1540
 * @param p1 not used
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1541
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1542
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1543
CommandCost CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1544
{
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1545
	/* Make sure the specified tile is a road stop of the correct type */
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1546
	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != p2) return CMD_ERROR;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1547
	Station *st = GetStationByTile(tile);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1548
	/* Save the stop info before it is removed */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1549
	bool is_drive_through = IsDriveThroughStopTile(tile);
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  1550
	RoadTypes rts = GetRoadTypes(tile);
7160
fc25fe36c045 (svn r9895) -Fix: assertion when removing roadstop.
rubidium
parents: 7158
diff changeset
  1551
	RoadBits road_bits = IsDriveThroughStopTile(tile) ?
fc25fe36c045 (svn r9895) -Fix: assertion when removing roadstop.
rubidium
parents: 7158
diff changeset
  1552
			((GetRoadStopDir(tile) == DIAGDIR_NE) ? ROAD_X : ROAD_Y) :
fc25fe36c045 (svn r9895) -Fix: assertion when removing roadstop.
rubidium
parents: 7158
diff changeset
  1553
			DiagDirToRoadBits(GetRoadStopDir(tile));
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1554
	bool is_towns_road = is_drive_through && GetStopBuiltOnTownRoad(tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1555
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1556
	CommandCost ret = RemoveRoadStop(st, flags, tile);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1557
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1558
	/* If the stop was a drive-through stop replace the road */
7442
a4f7989f27d4 (svn r10200) -Codechange: add "shortcut" for !CmdFailed (CmdSucceeded).
rubidium
parents: 7439
diff changeset
  1559
	if ((flags & DC_EXEC) && CmdSucceeded(ret) && is_drive_through) {
7229
e04350979783 (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: 7216
diff changeset
  1560
		/* Rebuild the drive throuhg road stop. As a road stop can only be
e04350979783 (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: 7216
diff changeset
  1561
		 * removed by the owner of the roadstop, _current_player is the
e04350979783 (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: 7216
diff changeset
  1562
		 * owner of the road stop. */
e04350979783 (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: 7216
diff changeset
  1563
		MakeRoadNormal(tile, road_bits, rts, is_towns_road ? ClosestTownFromTile(tile, (uint)-1)->index : 0,
e04350979783 (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: 7216
diff changeset
  1564
				is_towns_road ? OWNER_TOWN : _current_player, _current_player, _current_player);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1565
	}
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1566
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1567
	return ret;
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  1568
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1570
/* FIXME -- need to move to its corresponding Airport variable*/
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1571
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1572
/* Country Airfield (small) */
3429
12d01022976a (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1573
static const byte _airport_sections_country[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
	54, 53, 52, 65,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
	58, 57, 56, 55,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
	64, 63, 63, 62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1579
/* City Airport (large) */
3429
12d01022976a (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1580
static const byte _airport_sections_town[] = {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1581
	31,  9, 33,  9,  9, 32,
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1582
	27, 36, 29, 34,  8, 10,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
	30, 11, 35, 13, 20, 21,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
	51, 12, 14, 17, 19, 28,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
	38, 13, 15, 16, 18, 39,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
	26, 22, 23, 24, 25, 26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1589
/* Metropolitain Airport (large) - 2 runways */
3429
12d01022976a (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1590
static const byte _airport_sections_metropolitan[] = {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1591
	 31,  9, 33,  9,  9, 32,
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1592
	 27, 36, 29, 34,  8, 10,
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1593
	 30, 11, 35, 13, 20, 21,
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1594
	102,  8,  8,  8,  8, 28,
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1595
	 83, 84, 84, 84, 84, 83,
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1596
	 26, 23, 23, 23, 23, 26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1599
/* International Airport (large) - 2 runways */
3429
12d01022976a (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1600
static const byte _airport_sections_international[] = {
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  1601
	88, 89, 89, 89, 89, 89,  88,
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  1602
	51,  8,  8,  8,  8,  8,  32,
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1603
	30,  8, 11, 27, 11,  8,  10,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
	32,  8, 11, 27, 11,  8, 114,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
	87,  8, 11, 85, 11,  8, 114,
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1606
	87,  8,  8,  8,  8,  8,  90,
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1607
	26, 23, 23, 23, 23, 23,  26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1610
/* Intercontinental Airport (vlarge) - 4 runways */
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1611
static const byte _airport_sections_intercontinental[] = {
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1612
	102, 120,  89,  89,  89,  89,  89,  89, 118,
6593
97097178e0fc (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: 6587
diff changeset
  1613
	120,  23,  23,  23,  23,  23,  23, 119, 117,
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1614
	 87,  54,  87,   8,   8,   8,   8,  51, 117,
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1615
	 87, 162,  87,  85, 116, 116,   8,   9,  10,
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1616
	 87,   8,   8,  11,  31,  11,   8, 160,  32,
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1617
	 32, 160,   8,  11,  27,  11,   8,   8,  10,
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1618
	 87,   8,   8,  11,  30,  11,   8,   8,  10,
4066
108eb446f1ae (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
  1619
	 87, 142,   8,  11,  29,  11,  10, 163,  10,
108eb446f1ae (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
  1620
	 87, 164,  87,   8,   8,   8,  10,  37, 117,
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1621
	 87, 120,  89,  89,  89,  89,  89,  89, 119,
6593
97097178e0fc (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: 6587
diff changeset
  1622
	121,  23,  23,  23,  23,  23,  23, 119,  37
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1623
};
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1624
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1625
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1626
/* Commuter Airfield (small) */
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1627
static const byte _airport_sections_commuter[] = {
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1628
	85, 30, 115, 115, 32,
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1629
	87, 8,    8,   8, 10,
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1630
	87, 11,  11,  11, 10,
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1631
	26, 23,  23,  23, 26
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1632
};
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1633
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1634
/* Heliport */
3429
12d01022976a (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1635
static const byte _airport_sections_heliport[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	66,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1639
/* Helidepot */
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1640
static const byte _airport_sections_helidepot[] = {
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1641
	124, 32,
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1642
	122, 123
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1643
};
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1644
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  1645
/* Helistation */
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1646
static const byte _airport_sections_helistation[] = {
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1647
	 32, 134, 159, 158,
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1648
	161, 142, 142, 157
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1649
};
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1650
3471
c31dc50d54fb (svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents: 3435
diff changeset
  1651
static const byte * const _airport_sections[] = {
4059
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1652
	_airport_sections_country,           // Country Airfield (small)
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1653
	_airport_sections_town,              // City Airport (large)
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1654
	_airport_sections_heliport,          // Heliport
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1655
	_airport_sections_metropolitan,      // Metropolitain Airport (large)
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1656
	_airport_sections_international,     // International Airport (xlarge)
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1657
	_airport_sections_commuter,          // Commuter Airport (small)
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1658
	_airport_sections_helidepot,         // Helidepot
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1659
	_airport_sections_intercontinental,  // Intercontinental Airport (xxlarge)
f1442dfe1c8a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1660
	_airport_sections_helistation        // Helistation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1663
/** Place an Airport.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1664
 * @param tile tile where airport will be built
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6959
diff changeset
  1665
 * @param flags operation to perform
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1666
 * @param p1 airport type, @see airport.h
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1667
 * @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
  1668
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1669
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
  1670
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1671
	bool airport_upgrade = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1673
	/* Check if a valid, buildable airport was chosen for construction */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  1674
	if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1675
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1679
	Town *t = ClosestTownFromTile(tile, (uint)-1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
	/* Check if local auth refuses a new airport */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
		uint num = 0;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1684
		const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
		FOR_ALL_STATIONS(st) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1686
			if (st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
		if (num >= 2) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1690
			SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
			return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1694
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1695
	const AirportFTAClass *afc = GetAirport(p1);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1696
	int w = afc->size_x;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1697
	int h = afc->size_y;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1698
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  1699
	CommandCost cost = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  1700
	if (CmdFailed(cost)) return cost;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1701
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1702
	Station *st = NULL;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1703
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  1704
	if (!_patches.adjacent_stations || !HasBit(p2, 0)) {
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1705
		st = GetStationAround(tile, w, h, INVALID_STATION);
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1706
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1707
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
	/* Find a station close to us */
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
  1710
	if (st == NULL) st = GetClosestStationFromTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
5764
483bcb05ccf3 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5726
diff changeset
  1712
	if (w > _patches.station_spread || h > _patches.station_spread) {
483bcb05ccf3 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5726
diff changeset
  1713
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
483bcb05ccf3 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5726
diff changeset
  1714
		return CMD_ERROR;
483bcb05ccf3 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5726
diff changeset
  1715
	}
483bcb05ccf3 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5726
diff changeset
  1716
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1717
	/* In case of new station if DC_EXEC is NOT set we still need to create the station
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1718
	 * to test if everything is OK. In this case we need to delete it before return. */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
  1719
	AutoPtrT<Station> st_auto_delete;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1720
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
	if (st != NULL) {
6390
542cf60254b2 (svn r8794) -Fix
tron
parents: 6378
diff changeset
  1722
		if (st->owner != _current_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1724
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1725
		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
  1726
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
		if (st->airport_tile != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
			return_cmd_error(STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
		airport_upgrade = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1732
		/* allocate and initialize new station */
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1733
		st = new Station(tile);
7873
b3bccdcf85ef (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7872
diff changeset
  1734
		if (st == NULL) 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
  1735
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1736
		/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
  1737
		st_auto_delete = st;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1738
1265
0430e635b116 (svn r1769) Don't compute the same value twice, remove one function call
tron
parents: 1247
diff changeset
  1739
		st->town = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1741
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  1742
			SetBit(t->have_ratings, _current_player);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1743
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
6375
d30b83b2c70b (svn r8779) -Fix
tron
parents: 6367
diff changeset
  1747
		/* If only helicopters may use the airport generate a helicopter related (5)
d30b83b2c70b (svn r8779) -Fix
tron
parents: 6367
diff changeset
  1748
		 * station name, otherwise generate a normal airport name (1) */
8309
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
  1749
		if (!GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
			return CMD_ERROR;
6375
d30b83b2c70b (svn r8779) -Fix
tron
parents: 6367
diff changeset
  1751
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
  1754
	cost.AddCost(_price.build_airport * w * h);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
		st->airport_tile = tile;
5972
564f98b055d1 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5969
diff changeset
  1758
		st->AddFacility(FACIL_AIRPORT, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
		st->airport_type = (byte)p1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
		st->airport_flags = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1761
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1762
		st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1763
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1764
		/* if airport was demolished while planes were en-route to it, the
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1765
		 * positions can no longer be the same (v->u.air.pos), since different
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1766
		 * airports have different indexes. So update all planes en-route to this
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1767
		 * airport. Only update if
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1768
		 * 1. airport is upgraded
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1769
		 * 2. airport is added to existing station (unfortunately unavoideable)
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1770
		 */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1771
		if (airport_upgrade) UpdateAirplanesOnNewStation(st);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1772
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
		{
3471
c31dc50d54fb (svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents: 3435
diff changeset
  1774
			const byte *b = _airport_sections[p1];
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1775
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1776
			BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  1777
				MakeAirport(tile_cur, st->owner, st->index, *b - ((*b < 67) ? 8 : 24));
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  1778
				b++;
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1779
			} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1780
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
		UpdateStationAcceptance(st, false);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1784
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
		InvalidateWindow(WC_STATION_LIST, st->owner);
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1786
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1787
		/* success, so don't delete the new station */
7794
ccc691b566eb (svn r10646) -Cleanup: AutoPtrT<>::Release() renamed to Detach()
KUDr
parents: 7768
diff changeset
  1788
		st_auto_delete.Detach();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1792
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1794
static CommandCost RemoveAirport(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1796
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1799
	TileIndex tile = st->airport_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
6358
e7997742bf02 (svn r8755) -Fix
tron
parents: 6344
diff changeset
  1801
	const AirportFTAClass *afc = st->Airport();
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1802
	int w = afc->size_x;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1803
	int h = afc->size_y;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1804
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  1805
	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
  1806
6890
6c53cd7ce903 (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: 6694
diff changeset
  1807
	Vehicle *v;
6c53cd7ce903 (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: 6694
diff changeset
  1808
	FOR_ALL_VEHICLES(v) {
6c53cd7ce903 (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: 6694
diff changeset
  1809
		if (!(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) continue;
6c53cd7ce903 (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: 6694
diff changeset
  1810
6c53cd7ce903 (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: 6694
diff changeset
  1811
		if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR;
6c53cd7ce903 (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: 6694
diff changeset
  1812
	}
6c53cd7ce903 (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: 6694
diff changeset
  1813
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1814
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
8148
e836b6e36f6a (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: 8141
diff changeset
  1815
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
		if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
			DeleteAnimatedTile(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
			DoClearSquare(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
		}
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6984
diff changeset
  1821
	} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
	if (flags & DC_EXEC) {
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1824
		for (uint i = 0; i < afc->nof_depots; ++i) {
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1825
			DeleteWindowById(
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1826
				WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1827
			);
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1828
		}
755
823358e83abf (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 709
diff changeset
  1829
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  1830
		st->rect.AfterRemoveRect(st, tile, w, h);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  1831
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
		st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
		st->facilities &= ~FACIL_AIRPORT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1835
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1842
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1843
/** Build a buoy.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1844
 * @param tile tile where to place the bouy
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6959
diff changeset
  1845
 * @param flags operation to perform
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1846
 * @param p1 unused
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1847
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1849
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
  1850
{
8235
fc75e5ad02b6 (svn r11276) -Codechange: be more consistent with naming of some accessors.
rubidium
parents: 8226
diff changeset
  1851
	if (!IsWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
6632
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  1852
	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
  1853
8967
0b56f973bcf0 (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: 8962
diff changeset
  1854
	if (GetTileSlope(tile, NULL) != SLOPE_FLAT) return_cmd_error(STR_304B_SITE_UNSUITABLE);
0b56f973bcf0 (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: 8962
diff changeset
  1855
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1856
	/* allocate and initialize new station */
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1857
	Station *st = new Station(tile);
7873
b3bccdcf85ef (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7872
diff changeset
  1858
	if (st == NULL) 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
  1859
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1860
	/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
  1861
	AutoPtrT<Station> st_auto_delete(st);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1862
3055
25fd76668365 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1863
	st->town = ClosestTownFromTile(tile, (uint)-1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1864
	st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
8309
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
  1866
	if (!GenerateStationName(st, tile, STATIONNAMING_BUOY)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
	if (flags & DC_EXEC) {
3055
25fd76668365 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1869
		st->dock_tile = tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
		st->facilities |= FACIL_DOCK;
1751
954dd2900ac9 (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  1871
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
954dd2900ac9 (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  1872
		 * braindead.. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
		st->had_vehicle_of_type |= HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
		st->owner = OWNER_NONE;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1875
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  1876
		st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
8967
0b56f973bcf0 (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: 8962
diff changeset
  1878
		MakeBuoy(tile, st->index, GetWaterClass(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
		UpdateStationAcceptance(st, false);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1882
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
		InvalidateWindow(WC_STATION_LIST, st->owner);
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1884
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  1885
		/* success, so don't delete the new station */
7794
ccc691b566eb (svn r10646) -Cleanup: AutoPtrT<>::Release() renamed to Detach()
KUDr
parents: 7768
diff changeset
  1886
		st_auto_delete.Detach();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  1889
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
8605
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1892
/**
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1893
 * Tests whether the player's vehicles have this station in orders
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1894
 * When player == INVALID_PLAYER, then check all vehicles
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1895
 * @param station station ID
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1896
 * @param player player ID, INVALID_PLAYER to disable the check
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1897
 */
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1898
bool HasStationInUse(StationID station, PlayerID player)
1078
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1899
{
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1900
	const Vehicle *v;
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1901
	FOR_ALL_VEHICLES(v) {
8605
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1902
		if (player == INVALID_PLAYER || v->owner == player) {
1078
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1903
			const Order *order;
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1904
			FOR_VEHICLE_ORDERS(v, order) {
8605
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1905
				if (order->type == OT_GOTO_STATION && order->dest == station) {
1078
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1906
					return true;
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1907
				}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1908
			}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1909
		}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1910
	}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1911
	return false;
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1912
}
326bae748bcb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1913
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1914
static CommandCost RemoveBuoy(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
{
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  1916
	/* XXX: strange stuff */
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  1917
	if (!IsValidPlayer(_current_player))  return_cmd_error(INVALID_STRING_ID);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1919
	TileIndex tile = st->dock_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1920
8605
b1f538188811 (svn r11670) -Feature [FS#1565]: list neutral stations where the player has service in the station list too
smatz
parents: 8604
diff changeset
  1921
	if (HasStationInUse(st->index, INVALID_PLAYER)) return_cmd_error(STR_BUOY_IS_IN_USE);
9016
2b722bde93ec (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: 9015
diff changeset
  1922
	/* remove the buoy if there is a ship on tile when company goes bankrupt... */
2b722bde93ec (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: 9015
diff changeset
  1923
	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
  1924
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
		st->dock_tile = 0;
1751
954dd2900ac9 (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  1927
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
954dd2900ac9 (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  1928
		 * braindead.. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
		st->had_vehicle_of_type &= ~HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1932
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  1933
6204
c237d8081b58 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 6165
diff changeset
  1934
		/* We have to set the water tile's state to the same state as before the
c237d8081b58 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 6165
diff changeset
  1935
		 * buoy was placed. Otherwise one could plant a buoy on a canal edge,
c237d8081b58 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 6165
diff changeset
  1936
		 * remove it and flood the land (if the canal edge is at level 0) */
8967
0b56f973bcf0 (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: 8962
diff changeset
  1937
		MakeWaterKeepingClass(tile, GetTileOwner(tile));
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  1938
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  1944
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_truck_station);
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
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1947
static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1948
	{-1,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1949
	{ 0,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1950
	{ 0,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1951
	{ 0, -1}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
};
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1953
static const byte _dock_w_chk[4] = { 2, 1, 2, 1 };
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1954
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
  1955
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1956
/** Build a dock/haven.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1957
 * @param tile tile where dock will be built
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6959
diff changeset
  1958
 * @param flags operation to perform
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  1959
 * @param p1 (bit 0) - allow docks directly adjacent to other docks.
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1960
 * @param p2 unused
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1961
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1962
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
  1963
{
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  1964
	CommandCost cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1965
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8882
diff changeset
  1966
	DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8882
diff changeset
  1967
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_304B_SITE_UNSUITABLE);
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8882
diff changeset
  1968
	direction = ReverseDiagDir(direction);
3055
25fd76668365 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1969
8882
f54bd3d64027 (svn r11956) -Fix [FS#1675]: Disallow building locks and docks on rapids.
peter1138
parents: 8873
diff changeset
  1970
	/* Docks cannot be placed on rapids */
8967
0b56f973bcf0 (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: 8962
diff changeset
  1971
	if (IsWaterTile(tile)) return_cmd_error(STR_304B_SITE_UNSUITABLE);
8882
f54bd3d64027 (svn r11956) -Fix [FS#1675]: Disallow building locks and docks on rapids.
peter1138
parents: 8873
diff changeset
  1972
4619
fc11bc6a7fe7 (svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents: 4559
diff changeset
  1973
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
fc11bc6a7fe7 (svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents: 4559
diff changeset
  1974
6632
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  1975
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  1976
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1977
	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1978
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  1980
	TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  1982
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
3055
25fd76668365 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1983
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
25fd76668365 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1984
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1985
6632
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  1986
	if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
1a46c01ff627 (svn r9178) -Fix (r7573) [FS#679]: Don't allow building docks or buoys under bridges.
maedhros
parents: 6630
diff changeset
  1987
8967
0b56f973bcf0 (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: 8962
diff changeset
  1988
	/* Get the water class of the water tile before it is cleared.*/
0b56f973bcf0 (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: 8962
diff changeset
  1989
	WaterClass wc = GetWaterClass(tile_cur);
0b56f973bcf0 (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: 8962
diff changeset
  1990
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1991
	cost = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1992
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1993
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  1994
	tile_cur += TileOffsByDiagDir(direction);
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  1995
	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
  1996
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
3055
25fd76668365 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1997
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1998
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1999
	/* middle */
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  2000
	Station *st = NULL;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  2001
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2002
	if (!_patches.adjacent_stations || !HasBit(p1, 0)) {
7170
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  2003
		st = GetStationAround(
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  2004
				tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  2005
				_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION);
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  2006
		if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
bd34b6d0e4f1 (svn r9905) -Feature: Allow building new stations adjacent to existing stations by holding down control. Based on a patch by Wolf01.
maedhros
parents: 7160
diff changeset
  2007
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2008
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2009
	/* Find a station close to us */
6378
606e9543a45f (svn r8782) -Fix
tron
parents: 6377
diff changeset
  2010
	if (st == NULL) st = GetClosestStationFromTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2012
	/* In case of new station if DC_EXEC is NOT set we still need to create the station
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2013
	 * to test if everything is OK. In this case we need to delete it before return. */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
  2014
	AutoPtrT<Station> st_auto_delete;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2015
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
	if (st != NULL) {
6390
542cf60254b2 (svn r8794) -Fix
tron
parents: 6378
diff changeset
  2017
		if (st->owner != _current_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2019
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  2020
		if (!st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR;
1784
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2021
6eb3ab1bc33c (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  2022
		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
  2023
	} else {
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2024
		/* allocate and initialize new station */
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2025
		st = new Station(tile);
7873
b3bccdcf85ef (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7872
diff changeset
  2026
		if (st == NULL) 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
  2027
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2028
		/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
6095
55d5c0e6be3a (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 6088
diff changeset
  2029
		st_auto_delete = st;
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2030
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2031
		Town *t = st->town = ClosestTownFromTile(tile, (uint)-1);
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2032
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2033
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2034
			SetBit(t->have_ratings, _current_player);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2035
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2038
8309
017d4289aca3 (svn r11363) -Codechange: Remove some magical numbers
belugas
parents: 8291
diff changeset
  2039
		if (!GenerateStationName(st, tile, STATIONNAMING_DOCK)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2041
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
		st->dock_tile = tile;
5972
564f98b055d1 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5969
diff changeset
  2044
		st->AddFacility(FACIL_DOCK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  2046
		st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  2047
8967
0b56f973bcf0 (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: 8962
diff changeset
  2048
		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
  2049
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2050
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
		UpdateStationAcceptance(st, false);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  2052
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
		InvalidateWindow(WC_STATION_LIST, st->owner);
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  2054
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2055
		/* success, so don't delete the new station */
7794
ccc691b566eb (svn r10646) -Cleanup: AutoPtrT<>::Release() renamed to Detach()
KUDr
parents: 7768
diff changeset
  2056
		st_auto_delete.Detach();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2057
	}
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  2058
	return CommandCost(EXPENSES_CONSTRUCTION, _price.build_dock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2060
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  2061
static CommandCost RemoveDock(Station *st, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2062
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2063
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2065
	TileIndex tile1 = st->dock_tile;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2066
	TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2067
8254
5de2bbd26163 (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: 8235
diff changeset
  2068
	if (!EnsureNoVehicleOnGround(tile1)) return CMD_ERROR;
5de2bbd26163 (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: 8235
diff changeset
  2069
	if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2070
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2071
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2072
		DoClearSquare(tile1);
8967
0b56f973bcf0 (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: 8962
diff changeset
  2073
		MakeWaterKeepingClass(tile2, st->owner);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  2074
5927
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  2075
		st->rect.AfterRemoveTile(st, tile1);
d740cab19ca0 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5919
diff changeset
  2076
		st->rect.AfterRemoveTile(st, tile2);
5583
ed718fa4c69c (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5573
diff changeset
  2077
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  2078
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
		st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2081
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2082
8513
a22c0acc269a (svn r11577) -Fix: invalidate 'list trains/roadvehs/ships/planes' widgets when station part is added/removed
smatz
parents: 8512
diff changeset
  2083
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  2088
	return CommandCost(EXPENSES_CONSTRUCTION, _price.remove_dock);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
#include "table/station_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2093
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx)
3763
460bbb4a8154 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3754
diff changeset
  2094
{
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2095
	return &_station_display_datas[st][gfx];
3763
460bbb4a8154 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3754
diff changeset
  2096
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
static void DrawTile_Station(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
{
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2100
	const DrawTileSprites *t = NULL;
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2101
	RoadTypes roadtypes;
8662
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2102
	int32 total_offset;
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2103
	int32 custom_ground_offset;
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2104
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2105
	if (IsRailwayStation(ti->tile)) {
8662
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2106
		const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2107
		roadtypes = ROADTYPES_NONE;
8662
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2108
		total_offset = rti->total_offset;
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2109
		custom_ground_offset = rti->custom_ground_offset;
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2110
	} else {
8962
769b0c4cee15 (svn r12036) -Fix: For station tiles, only get road types for road stops.
peter1138
parents: 8925
diff changeset
  2111
		roadtypes = IsRoadStop(ti->tile) ? GetRoadTypes(ti->tile) : ROADTYPES_NONE;
8662
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2112
		total_offset = 0;
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2113
		custom_ground_offset = 0;
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2114
	}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2115
	uint32 relocation = 0;
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2116
	const Station *st = NULL;
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2117
	const StationSpec *statspec = NULL;
4227
55651eaaedb5 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  2118
	PlayerID owner = GetTileOwner(ti->tile);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2119
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5918
diff changeset
  2120
	SpriteID palette;
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  2121
	if (IsValidPlayer(owner)) {
4227
55651eaaedb5 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  2122
		palette = PLAYER_SPRITE_COLOR(owner);
55651eaaedb5 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  2123
	} else {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2124
		/* Some stations are not owner by a player, namely oil rigs */
4227
55651eaaedb5 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  2125
		palette = PALETTE_TO_GREY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2128
	/* don't show foundation for docks */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2129
	if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile))
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  2130
		DrawFoundation(ti, FOUNDATION_LEVELED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
3568
c1abc31df35b (svn r4450) - NewStations, rename *CustomStationSprite() to *CustomStationSpecIndex() to reflect their use, and alter the test for determining if a station has customised graphics.
peter1138
parents: 3554
diff changeset
  2132
	if (IsCustomStationSpecIndex(ti->tile)) {
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2133
		/* look for customization */
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2134
		st = GetStationByTile(ti->tile);
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2135
		statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2136
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2137
		//debug("Cust-o-mized %p", statspec);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2138
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2139
		if (statspec != NULL) {
3576
007e6b163bf5 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2140
			uint tile = GetStationGfx(ti->tile);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2141
3751
785501c18d0d (svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents: 3742
diff changeset
  2142
			relocation = GetCustomStationRelocation(statspec, st, ti->tile);
3576
007e6b163bf5 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2143
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2144
			if (HasBit(statspec->callbackmask, CBM_STATION_SPRITE_LAYOUT)) {
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2145
				uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
4886
d89110a382ae (svn r6823) - Codechange: Ignore bit 0 of a NewStation custom tile callback result. This fixes cosmetic problems with some add on stations.
peter1138
parents: 4873
diff changeset
  2146
				if (callback != CALLBACK_FAILED) tile = (callback & ~1) + GetRailStationAxis(ti->tile);
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2147
			}
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2148
3576
007e6b163bf5 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2149
			/* Ensure the chosen tile layout is valid for this custom station */
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2150
			if (statspec->renderdata != NULL) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2151
				t = &statspec->renderdata[tile < statspec->tiles ? tile : (uint)GetRailStationAxis(ti->tile)];
3754
04356ae401b4 (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2152
			}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2153
		}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2154
	}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2155
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2156
	if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationType(ti->tile)][GetStationGfx(ti->tile)];
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2157
8992
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2158
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2159
	if (IsBuoy(ti->tile) || IsDock(ti->tile)) {
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2160
		if (ti->tileh == SLOPE_FLAT) {
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2161
			DrawWaterClassGround(ti);
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2162
		} else {
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2163
			assert(IsDock(ti->tile));
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2164
			TileIndex water_tile = ti->tile + TileOffsByDiagDir(GetDockDirection(ti->tile));
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2165
			WaterClass wc = GetWaterClass(water_tile);
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2166
			if (wc == WATER_CLASS_SEA) {
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2167
				DrawShoreTile(ti->tileh);
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2168
			} else {
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2169
				DrawClearLandTile(ti, 3);
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2170
			}
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2171
		}
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2172
	} else {
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2173
		SpriteID image = t->ground.sprite;
8992
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2174
		if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2175
			image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2176
			image += custom_ground_offset;
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2177
		} else {
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2178
			image += total_offset;
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2179
		}
4fa931bf2417 (svn r12071) -Feature(ette): Draw river- and canal-edges under docks and shipdepots.
frosch
parents: 8967
diff changeset
  2180
		DrawGroundSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE);
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2181
	}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2182
3789
bf75e48227de (svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents: 3784
diff changeset
  2183
	if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
3355
a653b8e47f27 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3344
diff changeset
  2184
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2185
	if (HasBit(roadtypes, ROADTYPE_TRAM)) {
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2186
		Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2187
		DrawGroundSprite((HasBit(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE);
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2188
		DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2189
	}
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2190
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2191
	const DrawTileSeqStruct *dtss;
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2192
	foreach_draw_tile_seq(dtss, t->seq) {
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9059
diff changeset
  2193
		SpriteID image = dtss->image.sprite;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2194
		if (relocation == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) {
8662
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2195
			image += total_offset;
3775
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2196
		} else {
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2197
			image += relocation;
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2198
		}
f3f1ba3111fa (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2199
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2200
		SpriteID pal;
8654
83dc418497a9 (svn r11720) -Codechange: [NewGRF] Add support for bit 30 of station tile layouts; forcing a sprite to always be opaque.
peter1138
parents: 8640
diff changeset
  2201
		if (!(!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)) && HasBit(image, PALETTE_MODIFIER_COLOR)) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5918
diff changeset
  2202
			pal = palette;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5918
diff changeset
  2203
		} else {
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9059
diff changeset
  2204
			pal = dtss->image.pal;
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2205
		}
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2206
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2207
		if ((byte)dtss->delta_z != 0x80) {
4230
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2208
			AddSortableSpriteToDraw(
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5918
diff changeset
  2209
				image, pal,
4230
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2210
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2211
				dtss->size_x, dtss->size_y,
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7816
diff changeset
  2212
				dtss->size_z, ti->z + dtss->delta_z,
8654
83dc418497a9 (svn r11720) -Codechange: [NewGRF] Add support for bit 30 of station tile layouts; forcing a sprite to always be opaque.
peter1138
parents: 8640
diff changeset
  2213
				!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)
4230
cd86b1c47f33 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2214
			);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2215
		} else {
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8322
diff changeset
  2216
			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, IsTransparencySet(TO_BUILDINGS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2217
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2218
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2219
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2220
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2221
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
  2222
{
8662
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2223
	int32 total_offset = 0;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2224
	SpriteID pal = PLAYER_SPRITE_COLOR(_local_player);
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2225
	const DrawTileSprites *t = &_station_display_datas[st][image];
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2226
8662
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2227
	if (railtype != INVALID_RAILTYPE) {
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2228
		const RailtypeInfo *rti = GetRailTypeInfo(railtype);
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2229
		total_offset = rti->total_offset;
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2230
	}
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2231
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2232
	SpriteID img = t->ground.sprite;
8662
ea3cdf414e87 (svn r11729) -Codechange: Don't rely on the first railtype's sprite offset being zero when drawing road stations.
peter1138
parents: 8654
diff changeset
  2233
	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
  2234
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2235
	if (roadtype == ROADTYPE_TRAM) {
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
  2236
		DrawSprite(SPR_TRAMWAY_TRAM + (t->ground.sprite == SPR_ROAD_PAVED_STRAIGHT_X ? 1 : 0), PAL_NONE, x, y);
7187
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2237
	}
f7dc3204d457 (svn r9923) -Add: support for Action 0 Road vehicles, property 1C, bit 0.
rubidium
parents: 7179
diff changeset
  2238
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2239
	const DrawTileSeqStruct *dtss;
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2240
	foreach_draw_tile_seq(dtss, t->seq) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2241
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 9059
diff changeset
  2242
		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
  2243
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2244
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2245
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2246
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
  2247
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2248
	return GetTileMaxZ(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2249
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2250
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  2251
static Foundation GetFoundation_Station(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2252
{
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  2253
	return FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2254
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2255
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2256
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2257
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2258
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2259
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2260
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2261
static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2262
{
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  2263
	td->owner = GetTileOwner(tile);
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2264
	td->build_date = GetStationByTile(tile)->build_date;
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  2265
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2266
	StringID str;
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2267
	switch (GetStationType(tile)) {
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2268
		default: NOT_REACHED();
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2269
		case STATION_RAIL:    str = STR_305E_RAILROAD_STATION; break;
3882
86380e989bad (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2270
		case STATION_AIRPORT:
86380e989bad (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2271
			str = (IsHangar(tile) ? STR_305F_AIRCRAFT_HANGAR : STR_3060_AIRPORT);
86380e989bad (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2272
			break;
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2273
		case STATION_TRUCK:   str = STR_3061_TRUCK_LOADING_AREA; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2274
		case STATION_BUS:     str = STR_3062_BUS_STATION; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2275
		case STATION_OILRIG:  str = STR_4807_OIL_RIG; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2276
		case STATION_DOCK:    str = STR_3063_SHIP_DOCK; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2277
		case STATION_BUOY:    str = STR_3069_BUOY; break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2278
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2279
	td->str = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2280
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2281
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2282
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7173
diff changeset
  2283
static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode, uint sub_mode)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2284
{
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2285
	switch (mode) {
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2286
		case TRANSPORT_RAIL:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2287
			if (IsRailwayStation(tile) && !IsStationTileBlocked(tile)) {
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2288
				return TrackToTrackBits(GetRailStationTrack(tile)) * 0x101;
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2289
			}
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2290
			break;
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2291
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2292
		case TRANSPORT_WATER:
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2293
			/* buoy is coded as a station, it is always on open water */
6165
4da5ead702ad (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 6164
diff changeset
  2294
			if (IsBuoy(tile)) {
4da5ead702ad (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 6164
diff changeset
  2295
				TrackBits ts = TRACK_BIT_ALL;
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2296
				/* remove tracks that connect NE map edge */
6165
4da5ead702ad (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 6164
diff changeset
  2297
				if (TileX(tile) == 0) ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2298
				/* remove tracks that connect NW map edge */
6165
4da5ead702ad (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 6164
diff changeset
  2299
				if (TileY(tile) == 0) ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
4da5ead702ad (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 6164
diff changeset
  2300
				return uint32(ts) * 0x101;
4da5ead702ad (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 6164
diff changeset
  2301
			}
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2302
			break;
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2303
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2304
		case TRANSPORT_ROAD:
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7173
diff changeset
  2305
			if ((GetRoadTypes(tile) & sub_mode) != 0 && IsRoadStopTile(tile)) {
4158
a8f7265a6fd0 (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
  2306
				return AxisToTrackBits(DiagDirToAxis(GetRoadStopDir(tile))) * 0x101;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2307
			}
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2308
			break;
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2309
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2310
		default:
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2311
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2312
	}
1032
6020f9143b17 (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2313
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2314
	return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2315
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2316
2660
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2317
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2318
static void TileLoop_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2319
{
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2320
	/* FIXME -- GetTileTrackStatus_Station -> animated stationtiles
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2321
	 * hardcoded.....not good */
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2322
	switch (GetStationType(tile)) {
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2323
		case STATION_AIRPORT:
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2324
			switch (GetStationGfx(tile)) {
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2325
				case GFX_RADAR_LARGE_FIRST:
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2326
				case GFX_WINDSACK_FIRST : // for small airport
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2327
				case GFX_RADAR_INTERNATIONAL_FIRST:
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2328
				case GFX_RADAR_METROPOLITAN_FIRST:
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2329
				case GFX_RADAR_DISTRICTWE_FIRST: // radar district W-E airport
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2330
				case GFX_WINDSACK_INTERCON_FIRST : // for intercontinental airport
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2331
					AddAnimatedTile(tile);
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2332
					break;
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2333
			}
2660
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2334
			break;
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2335
8993
0794cc59940d (svn r12072) -Fix: Make docks at sea flood neighboured tiles.
frosch
parents: 8992
diff changeset
  2336
		case STATION_DOCK:
0794cc59940d (svn r12072) -Fix: Make docks at sea flood neighboured tiles.
frosch
parents: 8992
diff changeset
  2337
			if (GetTileSlope(tile, NULL) != SLOPE_FLAT) break; // only handle water part
0794cc59940d (svn r12072) -Fix: Make docks at sea flood neighboured tiles.
frosch
parents: 8992
diff changeset
  2338
		/* FALL THROUGH */
7768
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2339
		case STATION_OILRIG: //(station part)
2060e8d65a72 (svn r10601) -Codechange: store (and use) the type of stations instead of hardcoding station types by graphics IDs.
rubidium
parents: 7748
diff changeset
  2340
		case STATION_BUOY:
2660
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2341
			TileLoop_Water(tile);
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2342
			break;
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2343
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2344
		default: break;
fc0198e23f33 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2345
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2346
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2348
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2349
static void AnimateTile_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2350
{
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
  2351
	struct AnimData {
4467
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2352
		StationGfx from; // first sprite
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2353
		StationGfx to;   // last sprite
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2354
		byte delay;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
  2355
	};
4467
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2356
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2357
	static const AnimData data[] = {
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2358
		{ GFX_RADAR_LARGE_FIRST,         GFX_RADAR_LARGE_LAST,         3 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2359
		{ GFX_WINDSACK_FIRST,            GFX_WINDSACK_LAST,            1 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2360
		{ GFX_RADAR_INTERNATIONAL_FIRST, GFX_RADAR_INTERNATIONAL_LAST, 3 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2361
		{ GFX_RADAR_METROPOLITAN_FIRST,  GFX_RADAR_METROPOLITAN_LAST,  3 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2362
		{ GFX_RADAR_DISTRICTWE_FIRST,    GFX_RADAR_DISTRICTWE_LAST,    3 },
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2363
		{ GFX_WINDSACK_INTERCON_FIRST,   GFX_WINDSACK_INTERCON_LAST,   1 }
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2364
	};
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2365
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2366
	StationGfx gfx = GetStationGfx(tile);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2367
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2368
	for (const AnimData *i = data; i != endof(data); i++) {
4467
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2369
		if (i->from <= gfx && gfx <= i->to) {
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2370
			if ((_tick_counter & i->delay) == 0) {
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2371
				SetStationGfx(tile, gfx < i->to ? gfx + 1 : i->from);
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2372
				MarkTileDirtyByTile(tile);
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2373
			}
dede0d254ffb (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2374
			break;
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2375
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2376
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2377
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2378
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  2379
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2380
static void ClickTile_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2381
{
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2382
	if (IsHangar(tile)) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  2383
		ShowDepotWindow(tile, VEH_AIRCRAFT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2384
	} else {
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2385
		ShowStationViewWindow(GetStationIndex(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2386
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2387
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2388
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2389
static const byte _enter_station_speedtable[12] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2390
	215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2391
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2392
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
  2393
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
  2394
{
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  2395
	if (v->type == VEH_TRAIN) {
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2396
		if (IsRailwayStation(tile) && IsFrontEngine(v) &&
4559
c853d2440065 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  2397
				!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) {
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2398
			StationID station_id = GetStationIndex(tile);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  2399
8798
eea3a465bd86 (svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents: 8796
diff changeset
  2400
			if ((!(v->current_order.flags & OFB_NON_STOP) && !_patches.new_nonstop) ||
4527
b18634a31a4a (svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents: 4467
diff changeset
  2401
					(v->current_order.type == OT_GOTO_STATION && v->current_order.dest == station_id)) {
8798
eea3a465bd86 (svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents: 8796
diff changeset
  2402
				if (!(_patches.new_nonstop && v->current_order.flags & OFB_NON_STOP) &&
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2403
						v->current_order.type != OT_LEAVESTATION &&
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2404
						v->last_station_visited != station_id) {
3482
ba2072e463c8 (svn r4331) Replace some direction calculation magic with DiagDirection to make a bit more clear what's going on
tron
parents: 3480
diff changeset
  2405
					DiagDirection dir = DirToDiagDir(v->direction);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  2406
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2407
					x &= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2408
					y &= 0xF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2409
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6424
diff changeset
  2410
					if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  2411
					if (y == TILE_SIZE / 2) {
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  2412
						if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
  2413
						if (x == 12) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); /* enter station */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2414
						if (x < 12) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2415
							uint16 spd;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2416
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2417
							v->vehstatus |= VS_TRAIN_SLOWING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2418
							spd = _enter_station_speedtable[x];
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2419
							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
  2420
						}
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
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2423
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2424
		}
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  2425
	} else if (v->type == VEH_ROAD) {
6402
d8d29aef051f (svn r8809) -Fix (r8715): accidentally removed a part of an expression.
rubidium
parents: 6396
diff changeset
  2426
		if (v->u.road.state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)v->u.road.state) && v->u.road.frame == 0) {
7353
716c6dd9322a (svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros
parents: 7319
diff changeset
  2427
			if (IsRoadStop(tile) && IsRoadVehFront(v)) {
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2428
				/* Attempt to allocate a parking bay in a road stop */
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2429
				RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2430
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2431
				if (IsDriveThroughStopTile(tile)) {
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2432
					/* Vehicles entering a drive-through stop from the 'normal' side use first bay (bay 0). */
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2433
					byte side = ((DirToDiagDir(v->direction) == ReverseDiagDir(GetRoadStopDir(tile))) == (v->u.road.overtaking == 0)) ? 0 : 1;
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2434
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2435
					if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER;
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2436
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2437
					/* Check if the vehicle is stopping at this road stop */
6655
951b0ba32eb1 (svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents: 6632
diff changeset
  2438
					if (GetRoadStopType(tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) &&
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2439
							v->current_order.dest == GetStationIndex(tile)) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2440
						SetBit(v->u.road.state, RVS_IS_STOPPING);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2441
						rs->AllocateDriveThroughBay(side);
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2442
					}
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2443
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2444
					/* Indicate if vehicle is using second bay. */
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2445
					if (side == 1) SetBit(v->u.road.state, RVS_USING_SECOND_BAY);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2446
					/* Indicate a drive-through stop */
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2447
					SetBit(v->u.road.state, RVS_IN_DT_ROAD_STOP);
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2448
					return VETSB_CONTINUE;
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2449
				}
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2450
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2451
				/* For normal (non drive-through) road stops */
7965
c1a170885a60 (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: 7875
diff changeset
  2452
				/* Check if station is busy or if there are no free bays or whether it is a articulated vehicle. */
c1a170885a60 (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: 7875
diff changeset
  2453
				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
  2454
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2455
				SetBit(v->u.road.state, RVS_IN_ROAD_STOP);
2671
457c6cdbf9e7 (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2456
6316
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2457
				/* Allocate a bay and update the road state */
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2458
				uint bay_nr = rs->AllocateBay();
6326
c904c7ea1c8d (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 6324
diff changeset
  2459
				SB(v->u.road.state, RVS_USING_SECOND_BAY, 1, bay_nr);
6316
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2460
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2461
				/* Mark the station entrace as busy */
6ba1efc2b7fc (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 6214
diff changeset
  2462
				rs->SetEntranceBusy(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2463
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2464
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2465
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2466
6317
c73bda71ac16 (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 6316
diff changeset
  2467
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2468
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2469
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2470
/* this function is called for one station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2471
static void StationHandleBigTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2472
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2473
	UpdateStationAcceptance(st, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2474
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2475
	if (st->facilities == 0 && ++st->delete_ctr >= 8) delete st;
1239
6e61c510580e (svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents: 1231
diff changeset
  2476
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2477
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2478
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 497
diff changeset
  2479
static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2480
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2481
static void UpdateStationRating(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2482
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2483
	bool waiting_changed = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2484
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2485
	byte_inc_sat(&st->time_since_load);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2486
	byte_inc_sat(&st->time_since_unload);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2487
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2488
	GoodsEntry *ge = st->goods;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2489
	do {
6587
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2490
		/* Slowly increase the rating back to his original level in the case we
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2491
		 *  didn't deliver cargo yet to this station. This happens when a bribe
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2492
		 *  failed while you didn't moved that cargo yet to a station. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2493
		if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP) && ge->rating < INITIAL_STATION_RATING) {
6587
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2494
			ge->rating++;
7970
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7965
diff changeset
  2495
		}
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7965
diff changeset
  2496
6587
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2497
		/* Only change the rating if we are moving this cargo */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2498
		if (HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2499
			byte_inc_sat(&ge->days_since_pickup);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2500
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2501
			int rating = 0;
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
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2504
				int b = ge->last_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2505
				if ((b-=85) >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2506
					rating += b >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2507
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2508
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2509
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2510
				byte age = ge->last_age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2511
				(age >= 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2512
				(rating += 10, age >= 2) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2513
				(rating += 10, age >= 1) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2514
				(rating += 13, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2515
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2516
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  2517
			if (IsValidPlayer(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2519
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2520
				byte days = ge->days_since_pickup;
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2521
				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
  2522
				(days > 21) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2523
				(rating += 25, days > 12) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2524
				(rating += 25, days > 6) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2525
				(rating += 45, days > 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2526
				(rating += 35, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2527
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2528
7506
e52d89f5c7c1 (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: 7451
diff changeset
  2529
			uint waiting = ge->cargo.Count();
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2530
			(rating -= 90, waiting > 1500) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2531
			(rating += 55, waiting > 1000) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2532
			(rating += 35, waiting > 600) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2533
			(rating += 10, waiting > 300) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2534
			(rating += 20, waiting > 100) ||
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2535
			(rating += 10, true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2536
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2537
			{
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2538
				int or_ = ge->rating; // old rating
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2539
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2540
				/* only modify rating in steps of -2, -1, 0, 1 or 2 */
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8387
diff changeset
  2541
				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
  2542
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2543
				/* if rating is <= 64 and more than 200 items waiting,
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2544
				 * 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
  2545
				if (rating <= 64 && waiting >= 200) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2546
					int dec = Random() & 0x1F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2547
					if (waiting < 400) dec &= 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2548
					waiting -= dec + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2549
					waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2550
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2551
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  2552
				/* 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
  2553
				if (rating <= 127 && waiting != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2554
					uint32 r = Random();
5911
bb8088c97103 (svn r8120) -Fix (r8055): Station cargo waiting value clamp should be signed not unsigned. This resulted in cargo magically appearing...
peter1138
parents: 5860
diff changeset
  2555
					if (rating <= (int)GB(r, 0, 7)) {
7506
e52d89f5c7c1 (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: 7451
diff changeset
  2556
						/* Need to have int, otherwise it will just overflow etc. */
e52d89f5c7c1 (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: 7451
diff changeset
  2557
						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
  2558
						waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2559
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2560
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2561
7748
5f945356a9cd (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: 7593
diff changeset
  2562
				/* At some point we really must cap the cargo. Previously this
5f945356a9cd (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: 7593
diff changeset
  2563
				 * was a strict 4095, but now we'll have a less strict, but
5f945356a9cd (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: 7593
diff changeset
  2564
				 * increasingly agressive truncation of the amount of cargo. */
5f945356a9cd (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: 7593
diff changeset
  2565
				static const uint WAITING_CARGO_THRESHOLD  = 1 << 12;
5f945356a9cd (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: 7593
diff changeset
  2566
				static const uint WAITING_CARGO_CUT_FACTOR = 1 <<  6;
5f945356a9cd (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: 7593
diff changeset
  2567
				static const uint MAX_WAITING_CARGO        = 1 << 15;
5f945356a9cd (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: 7593
diff changeset
  2568
5f945356a9cd (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: 7593
diff changeset
  2569
				if (waiting > WAITING_CARGO_THRESHOLD) {
5f945356a9cd (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: 7593
diff changeset
  2570
					uint difference = waiting - WAITING_CARGO_THRESHOLD;
5f945356a9cd (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: 7593
diff changeset
  2571
					waiting -= (difference / WAITING_CARGO_CUT_FACTOR);
5f945356a9cd (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: 7593
diff changeset
  2572
5f945356a9cd (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: 7593
diff changeset
  2573
					waiting = min(waiting, MAX_WAITING_CARGO);
5f945356a9cd (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: 7593
diff changeset
  2574
					waiting_changed = true;
5f945356a9cd (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: 7593
diff changeset
  2575
				}
5f945356a9cd (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: 7593
diff changeset
  2576
7506
e52d89f5c7c1 (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: 7451
diff changeset
  2577
				if (waiting_changed) ge->cargo.Truncate(waiting);
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
	} while (++ge != endof(st->goods));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2581
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2582
	StationID index = st->index;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2583
	if (waiting_changed) {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8511
diff changeset
  2584
		InvalidateWindow(WC_STATION_VIEW, index); // update whole window
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2585
	} else {
8512
e77c8fb7c0ed (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 8511
diff changeset
  2586
		InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_RATINGLIST); // update only ratings list
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2587
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2588
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2589
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2590
/* called for every station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2591
static void StationHandleSmallTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2592
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2593
	if (st->facilities == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2594
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2595
	byte b = st->delete_ctr + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2596
	if (b >= 185) b = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2597
	st->delete_ctr = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2598
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2599
	if (b == 0) UpdateStationRating(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2600
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2601
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  2602
void OnTick_Station()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2603
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2604
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2605
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2606
	uint i = _station_tick_ctr;
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5220
diff changeset
  2607
	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
  2608
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2609
	if (IsValidStationID(i)) StationHandleBigTick(GetStation(i));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2610
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2611
	Station *st;
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2612
	FOR_ALL_STATIONS(st) StationHandleSmallTick(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2613
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2614
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  2615
void StationMonthlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2616
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2617
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2618
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2619
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  2620
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2621
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2622
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2623
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2624
	FOR_ALL_STATIONS(st) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2625
		if (st->owner == owner &&
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1239
diff changeset
  2626
				DistanceManhattan(tile, st->xy) <= radius) {
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
  2627
			for (CargoID i = 0; i < NUM_CARGO; i++) {
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2628
				GoodsEntry* ge = &st->goods[i];
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2629
7970
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7965
diff changeset
  2630
				if (ge->acceptance_pickup != 0) {
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8387
diff changeset
  2631
					ge->rating = Clamp(ge->rating + amount, 0, 255);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2632
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2633
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2634
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2635
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2636
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2637
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
  2638
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
  2639
{
7506
e52d89f5c7c1 (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: 7451
diff changeset
  2640
	st->goods[type].cargo.Append(new CargoPacket(st->index, amount));
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8425
diff changeset
  2641
	SetBit(st->goods[type].acceptance_pickup, GoodsEntry::PICKUP);
7506
e52d89f5c7c1 (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: 7451
diff changeset
  2642
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2643
	InvalidateWindow(WC_STATION_VIEW, st->index);
7319
f884be171f04 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 7257
diff changeset
  2644
	st->MarkTilesDirty(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2645
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2646
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2647
static bool IsUniqueStationName(const char *name)
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2648
{
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2649
	const Station *st;
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2650
	char buf[512];
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2651
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2652
	FOR_ALL_STATIONS(st) {
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2653
		SetDParam(0, st->index);
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2654
		GetString(buf, STR_STATION, lastof(buf));
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2655
		if (strcmp(buf, name) == 0) return false;
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2656
	}
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2657
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2658
	return true;
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2659
}
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2660
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2661
/** Rename a station
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  2662
 * @param tile unused
6979
d194d25020e7 (svn r9664) -Documentation: Doxygen corrections,errors and omissions
belugas
parents: 6959
diff changeset
  2663
 * @param flags operation to perform
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2664
 * @param p1 station ID that is to be renamed
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2665
 * @param p2 unused
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2666
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  2667
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
  2668
{
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2669
	if (!IsValidStationID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2670
	Station *st = GetStation(p1);
1774
0fc4a31265c2 (svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents: 1751
diff changeset
  2671
4352
8ddb01bc6075 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2672
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
1774
0fc4a31265c2 (svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents: 1751
diff changeset
  2673
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2674
	if (!IsUniqueStationName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7563
diff changeset
  2675
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2676
	if (flags & DC_EXEC) {
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  2677
		free(st->name);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  2678
		st->name = strdup(_cmd_text);
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  2679
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2680
		UpdateStationVirtCoord(st);
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  2681
		ResortStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2682
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2683
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2684
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7442
diff changeset
  2685
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2686
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2687
8387
30f519812d62 (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: 8360
diff changeset
  2688
/**
30f519812d62 (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: 8360
diff changeset
  2689
* Find all (non-buoy) stations around an industry tile
30f519812d62 (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: 8360
diff changeset
  2690
*
30f519812d62 (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: 8360
diff changeset
  2691
* @param tile: Center tile to search from
30f519812d62 (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: 8360
diff changeset
  2692
* @param w: Width of the center
30f519812d62 (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: 8360
diff changeset
  2693
* @param h: Height of the center
30f519812d62 (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: 8360
diff changeset
  2694
*
30f519812d62 (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: 8360
diff changeset
  2695
* @return: Set of found stations
30f519812d62 (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: 8360
diff changeset
  2696
*/
30f519812d62 (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: 8360
diff changeset
  2697
StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2698
{
8387
30f519812d62 (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: 8360
diff changeset
  2699
	StationSet station_set;
30f519812d62 (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: 8360
diff changeset
  2700
30f519812d62 (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: 8360
diff changeset
  2701
	int w_prod; // width and height of the "producer" of the cargo
3000
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2702
	int h_prod;
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2703
	int max_rad;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2704
	if (_patches.modified_catchment) {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2705
		w_prod = w;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2706
		h_prod = h;
7994
d5e8a6a01c4d (svn r11013) -Fix [FS#1171]: MoveGoodsToStation's search area is too small as it assumed a lower maximum catchment area than the real maximum catchment area. Based on a patch by PhilSophus.
rubidium
parents: 7990
diff changeset
  2707
		w += 2 * MAX_CATCHMENT;
d5e8a6a01c4d (svn r11013) -Fix [FS#1171]: MoveGoodsToStation's search area is too small as it assumed a lower maximum catchment area than the real maximum catchment area. Based on a patch by PhilSophus.
rubidium
parents: 7990
diff changeset
  2708
		h += 2 * MAX_CATCHMENT;
d5e8a6a01c4d (svn r11013) -Fix [FS#1171]: MoveGoodsToStation's search area is too small as it assumed a lower maximum catchment area than the real maximum catchment area. Based on a patch by PhilSophus.
rubidium
parents: 7990
diff changeset
  2709
		max_rad = MAX_CATCHMENT;
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2710
	} else {
3000
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2711
		w_prod = 0;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2712
		h_prod = 0;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2713
		w += 8;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2714
		h += 8;
9069
7b9573ccc411 (svn r12154) -Codechange: removed a magic number
glx
parents: 9067
diff changeset
  2715
		max_rad = CA_UNMODIFIED;
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2716
	}
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2717
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  2718
	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
  2719
		cur_tile = TILE_MASK(cur_tile);
3000
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2720
		if (!IsTileType(cur_tile, MP_STATION)) continue;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2721
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2722
		Station *st = GetStationByTile(cur_tile);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2723
8387
30f519812d62 (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: 8360
diff changeset
  2724
		if (st->IsBuoy()) continue; // bouys don't accept cargo
30f519812d62 (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: 8360
diff changeset
  2725
30f519812d62 (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: 8360
diff changeset
  2726
30f519812d62 (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: 8360
diff changeset
  2727
		if (_patches.modified_catchment) {
30f519812d62 (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: 8360
diff changeset
  2728
			/* min and max coordinates of the producer relative */
30f519812d62 (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: 8360
diff changeset
  2729
			const int x_min_prod = max_rad + 1;
30f519812d62 (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: 8360
diff changeset
  2730
			const int x_max_prod = max_rad + w_prod;
30f519812d62 (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: 8360
diff changeset
  2731
			const int y_min_prod = max_rad + 1;
30f519812d62 (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: 8360
diff changeset
  2732
			const int y_max_prod = max_rad + h_prod;
30f519812d62 (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: 8360
diff changeset
  2733
30f519812d62 (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: 8360
diff changeset
  2734
			int rad = FindCatchmentRadius(st);
30f519812d62 (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: 8360
diff changeset
  2735
30f519812d62 (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: 8360
diff changeset
  2736
			int x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur);
30f519812d62 (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: 8360
diff changeset
  2737
			if (w_cur < x_min_prod) {
30f519812d62 (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: 8360
diff changeset
  2738
				x_dist = x_min_prod - w_cur;
30f519812d62 (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: 8360
diff changeset
  2739
			} else if (w_cur > x_max_prod) {
30f519812d62 (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: 8360
diff changeset
  2740
				x_dist = w_cur - x_max_prod;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2741
			}
8387
30f519812d62 (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: 8360
diff changeset
  2742
30f519812d62 (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: 8360
diff changeset
  2743
			if (x_dist > rad) continue;
30f519812d62 (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: 8360
diff changeset
  2744
30f519812d62 (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: 8360
diff changeset
  2745
			int y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur);
30f519812d62 (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: 8360
diff changeset
  2746
			if (h_cur < y_min_prod) {
30f519812d62 (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: 8360
diff changeset
  2747
				y_dist = y_min_prod - h_cur;
30f519812d62 (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: 8360
diff changeset
  2748
			} else if (h_cur > y_max_prod) {
30f519812d62 (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: 8360
diff changeset
  2749
				y_dist = h_cur - y_max_prod;
30f519812d62 (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: 8360
diff changeset
  2750
			}
30f519812d62 (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: 8360
diff changeset
  2751
30f519812d62 (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: 8360
diff changeset
  2752
			if (y_dist > rad) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2753
		}
8387
30f519812d62 (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: 8360
diff changeset
  2754
30f519812d62 (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: 8360
diff changeset
  2755
		/* Insert the station in the set. This will fail if it has
30f519812d62 (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: 8360
diff changeset
  2756
		 * already been added.
30f519812d62 (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: 8360
diff changeset
  2757
		 */
30f519812d62 (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: 8360
diff changeset
  2758
		station_set.insert(st);
30f519812d62 (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: 8360
diff changeset
  2759
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  2760
	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
  2761
8387
30f519812d62 (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: 8360
diff changeset
  2762
	return station_set;
30f519812d62 (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: 8360
diff changeset
  2763
}
30f519812d62 (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: 8360
diff changeset
  2764
30f519812d62 (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: 8360
diff changeset
  2765
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
30f519812d62 (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: 8360
diff changeset
  2766
{
30f519812d62 (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: 8360
diff changeset
  2767
	Station *st1 = NULL;	// Station with best rating
30f519812d62 (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: 8360
diff changeset
  2768
	Station *st2 = NULL;	// Second best station
30f519812d62 (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: 8360
diff changeset
  2769
	uint best_rating1 = 0;	// rating of st1
30f519812d62 (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: 8360
diff changeset
  2770
	uint best_rating2 = 0;	// rating of st2
30f519812d62 (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: 8360
diff changeset
  2771
30f519812d62 (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: 8360
diff changeset
  2772
	StationSet all_stations = FindStationsAroundIndustryTile(tile, w, h);
30f519812d62 (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: 8360
diff changeset
  2773
	for (StationSet::iterator st_iter = all_stations.begin(); st_iter != all_stations.end(); ++st_iter) {
30f519812d62 (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: 8360
diff changeset
  2774
		Station *st = *st_iter;
30f519812d62 (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: 8360
diff changeset
  2775
30f519812d62 (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: 8360
diff changeset
  2776
		/* Is the station reserved exclusively for somebody else? */
30f519812d62 (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: 8360
diff changeset
  2777
		if (st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue;
30f519812d62 (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: 8360
diff changeset
  2778
30f519812d62 (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: 8360
diff changeset
  2779
		if (st->goods[type].rating == 0) continue; // Lowest possible rating, better not to give cargo anymore
30f519812d62 (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: 8360
diff changeset
  2780
30f519812d62 (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: 8360
diff changeset
  2781
		if (_patches.selectgoods && st->goods[type].last_speed == 0) continue; // Selectively servicing stations, and not this one
30f519812d62 (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: 8360
diff changeset
  2782
30f519812d62 (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: 8360
diff changeset
  2783
		if (IsCargoInClass(type, CC_PASSENGERS)) {
30f519812d62 (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: 8360
diff changeset
  2784
			if (st->facilities == FACIL_TRUCK_STOP) continue; // passengers are never served by just a truck stop
30f519812d62 (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: 8360
diff changeset
  2785
		} else {
30f519812d62 (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: 8360
diff changeset
  2786
			if (st->facilities == FACIL_BUS_STOP) continue; // non-passengers are never served by just a bus stop
30f519812d62 (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: 8360
diff changeset
  2787
		}
30f519812d62 (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: 8360
diff changeset
  2788
30f519812d62 (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: 8360
diff changeset
  2789
		/* This station can be used, add it to st1/st2 */
30f519812d62 (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: 8360
diff changeset
  2790
		if (st1 == NULL || st->goods[type].rating >= best_rating1) {
30f519812d62 (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: 8360
diff changeset
  2791
			st2 = st1; best_rating2 = best_rating1; st1 = st; best_rating1 = st->goods[type].rating;
30f519812d62 (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: 8360
diff changeset
  2792
		} else if (st2 == NULL || st->goods[type].rating >= best_rating2) {
30f519812d62 (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: 8360
diff changeset
  2793
			st2 = st; best_rating2 = st->goods[type].rating;
30f519812d62 (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: 8360
diff changeset
  2794
		}
30f519812d62 (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: 8360
diff changeset
  2795
	}
30f519812d62 (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: 8360
diff changeset
  2796
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2797
	/* no stations around at all? */
8387
30f519812d62 (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: 8360
diff changeset
  2798
	if (st1 == NULL) return 0;
30f519812d62 (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: 8360
diff changeset
  2799
30f519812d62 (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: 8360
diff changeset
  2800
	if (st2 == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2801
		/* only one station around */
8387
30f519812d62 (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: 8360
diff changeset
  2802
		uint moved = amount * best_rating1 / 256 + 1;
30f519812d62 (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: 8360
diff changeset
  2803
		UpdateStationWaiting(st1, type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2804
		return moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2805
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2806
8387
30f519812d62 (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: 8360
diff changeset
  2807
	/* 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
  2808
	assert(st1 != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2809
	assert(st2 != NULL);
8387
30f519812d62 (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: 8360
diff changeset
  2810
	assert(best_rating1 != 0 || best_rating2 != 0);
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
	/* the 2nd highest one gets a penalty */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2813
	best_rating2 >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2814
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2815
	/* amount given to station 1 */
8387
30f519812d62 (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: 8360
diff changeset
  2816
	uint t = (best_rating1 * (amount + 1)) / (best_rating1 + best_rating2);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2817
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2818
	uint moved = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2819
	if (t != 0) {
8387
30f519812d62 (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: 8360
diff changeset
  2820
		moved = t * best_rating1 / 256 + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2821
		amount -= t;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2822
		UpdateStationWaiting(st1, type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2823
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2824
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2825
	if (amount != 0) {
3000
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2826
		amount = amount * best_rating2 / 256 + 1;
711d2ababe20 (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2827
		moved += amount;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2828
		UpdateStationWaiting(st2, type, amount);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2829
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2830
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2831
	return moved;
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2834
void BuildOilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2835
{
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2836
	Station *st = new Station();
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2837
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2838
	if (st == NULL) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5550
diff changeset
  2839
		DEBUG(misc, 0, "Can't allocate station for oilrig at 0x%X, reverting to oilrig only", tile);
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2840
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2841
	}
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2842
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2843
	st->town = ClosestTownFromTile(tile, (uint)-1);
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2844
	st->sign.width_1 = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2845
8322
ff4cc107a313 (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: 8310
diff changeset
  2846
	if (!GenerateStationName(st, tile, STATIONNAMING_OILRIG)) {
ff4cc107a313 (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: 8310
diff changeset
  2847
		DEBUG(misc, 0, "Can't allocate station-name for oilrig at 0x%X, reverting to oilrig only", tile);
ff4cc107a313 (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: 8310
diff changeset
  2848
		delete st;
ff4cc107a313 (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: 8310
diff changeset
  2849
		return;
ff4cc107a313 (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: 8310
diff changeset
  2850
	}
ff4cc107a313 (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: 8310
diff changeset
  2851
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2852
	MakeOilrig(tile, st->index);
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2853
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2854
	st->owner = OWNER_NONE;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2855
	st->airport_flags = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2856
	st->airport_type = AT_OILRIG;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2857
	st->xy = tile;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2858
	st->bus_stops = NULL;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2859
	st->truck_stops = NULL;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2860
	st->airport_tile = tile;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2861
	st->dock_tile = tile;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2862
	st->train_tile = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2863
	st->had_vehicle_of_type = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2864
	st->time_since_load = 255;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2865
	st->time_since_unload = 255;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2866
	st->delete_ctr = 0;
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6574
diff changeset
  2867
	st->last_vehicle_type = VEH_INVALID;
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2868
	st->facilities = FACIL_AIRPORT | FACIL_DOCK;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2869
	st->build_date = _date;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2870
6676
30aea9ac89bc (svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents: 6655
diff changeset
  2871
	for (CargoID j = 0; j < NUM_CARGO; j++) {
7970
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7965
diff changeset
  2872
		st->goods[j].acceptance_pickup = 0;
7506
e52d89f5c7c1 (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: 7451
diff changeset
  2873
		st->goods[j].days_since_pickup = 255;
6587
bc0bd6259485 (svn r9070) -Fix [FS#404]: if bribe failed and you didn't pick up cargo yet, you wouldn't ever be able to do so for a given station
truelight
parents: 6585
diff changeset
  2874
		st->goods[j].rating = INITIAL_STATION_RATING;
2427
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2875
		st->goods[j].last_speed = 0;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2876
		st->goods[j].last_age = 255;
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2877
	}
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2878
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2879
	UpdateStationVirtCoordDirty(st);
b7a0ad02af26 (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2880
	UpdateStationAcceptance(st, false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2881
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2882
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2883
void DeleteOilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2884
{
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2885
	Station* st = GetStationByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2886
6138
c9a4aadfaaac (svn r8499) -Fix
tron
parents: 6130
diff changeset
  2887
	MakeWater(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2888
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2889
	st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2890
	st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2891
	st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2892
	st->airport_flags = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2893
	UpdateStationVirtCoordDirty(st);
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  2894
	if (st->facilities == 0) delete st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2895
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2896
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2427
diff changeset
  2897
static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2898
{
1901
fb05044cf5c3 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  2899
	if (!IsTileOwner(tile, old_player)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2900
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4638
diff changeset
  2901
	if (new_player != PLAYER_SPECTATOR) {
3315
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2902
		Station* st = GetStationByTile(tile);
1f65f8260092 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2903
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  2904
		SetTileOwner(tile, new_player);
9014
223a4ddb80bb (svn r12093) -Fix: do not set station owner for buoys when merging company
smatz
parents: 8993
diff changeset
  2905
		if (!IsBuoy(tile)) st->owner = new_player; // do not set st->owner for buoys
3812
d9b3041ee3d0 (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  2906
		RebuildStationLists();
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 59
diff changeset
  2907
		InvalidateWindowClasses(WC_STATION_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2908
	} else {
9016
2b722bde93ec (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: 9015
diff changeset
  2909
		if (IsDriveThroughStopTile(tile)) {
2b722bde93ec (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: 9015
diff changeset
  2910
			/* Remove the drive-through road stop */
9015
4a44c6974ac1 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 9014
diff changeset
  2911
			DoCommand(tile, 0, (GetStationType(tile) == STATION_TRUCK) ? RoadStop::TRUCK : RoadStop::BUS, DC_EXEC | DC_BANKRUPT, CMD_REMOVE_ROAD_STOP);
9016
2b722bde93ec (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: 9015
diff changeset
  2912
			assert(IsTileType(tile, MP_ROAD));
2b722bde93ec (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: 9015
diff changeset
  2913
			/* Change owner of tile and all roadtypes */
2b722bde93ec (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: 9015
diff changeset
  2914
			ChangeTileOwner(tile, old_player, new_player);
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2915
		} else {
9015
4a44c6974ac1 (svn r12094) -Codechange: use DC_BANKRUPT command flag when removing player property to allow further fixes
smatz
parents: 9014
diff changeset
  2916
			DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
9016
2b722bde93ec (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: 9015
diff changeset
  2917
			/* Set tile owner of water under (now removed) buoy and dock to OWNER_NONE.
2b722bde93ec (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: 9015
diff changeset
  2918
			 * Update owner of buoy if it was not removed (was in orders).
2b722bde93ec (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: 9015
diff changeset
  2919
			 * Do not update when owned by OWNER_WATER (sea and rivers). */
2b722bde93ec (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: 9015
diff changeset
  2920
			if ((IsTileType(tile, MP_WATER) || IsBuoyTile(tile)) && IsTileOwner(tile, old_player)) SetTileOwner(tile, OWNER_NONE);
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2921
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2922
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2923
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2924
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2925
/**
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2926
 * Check if a drive-through road stop tile can be cleared.
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2927
 * Road stops built on town-owned roads check the conditions
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2928
 * that would allow clearing of the original road.
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2929
 * @param tile road stop tile to check
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2930
 * @return true if the road can be cleared
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2931
 */
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2932
static bool CanRemoveRoadWithStop(TileIndex tile)
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2933
{
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2934
	/* The road can always be cleared if it was not a town-owned road */
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2935
	if (!GetStopBuiltOnTownRoad(tile)) return true;
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2936
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2937
	bool edge_road;
7157
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  2938
	return CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, &edge_road, ROADTYPE_ROAD) &&
270bc5b64e08 (svn r9892) -Codechange: lots of ground work for allowing multiple types of "road" with multiple owners on a single tile.
rubidium
parents: 7092
diff changeset
  2939
				CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_TRAM), OWNER_TOWN, &edge_road, ROADTYPE_TRAM);
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2940
}
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2941
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7411
diff changeset
  2942
static CommandCost ClearTile_Station(TileIndex tile, byte flags)
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2943
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2944
	if (flags & DC_AUTO) {
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2945
		switch (GetStationType(tile)) {
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2946
			case STATION_RAIL:    return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2947
			case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST);
9059
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9016
diff changeset
  2948
			case STATION_TRUCK:   return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_CARGO_TRAM_STATION : STR_3047_MUST_DEMOLISH_TRUCK_STATION);
04edde3eb0c6 (svn r12141) -Codechange: Introduce IsNormalRoad[Tile](), IsRoadDepot[Tile]() and HasTileRoadType(); and use them.
frosch
parents: 9016
diff changeset
  2949
			case STATION_BUS:     return_cmd_error(HasTileRoadType(tile, ROADTYPE_TRAM) ? STR_MUST_DEMOLISH_PASSENGER_TRAM_STATION : STR_3046_MUST_DEMOLISH_BUS_STATION);
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2950
			case STATION_BUOY:    return_cmd_error(STR_306A_BUOY_IN_THE_WAY);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2951
			case STATION_DOCK:    return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2952
			case STATION_OILRIG:
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2953
				SetDParam(0, STR_4807_OIL_RIG);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2954
				return_cmd_error(STR_4800_IN_THE_WAY);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2955
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2956
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2957
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2958
	Station *st = GetStationByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2959
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2960
	switch (GetStationType(tile)) {
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2961
		case STATION_RAIL:    return RemoveRailroadStation(st, tile, flags);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2962
		case STATION_AIRPORT: return RemoveAirport(st, flags);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2963
		case STATION_TRUCK:
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2964
			if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile))
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2965
				return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION);
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2966
			return RemoveRoadStop(st, flags, tile);
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2967
		case STATION_BUS:
6442
10b44714b85d (svn r8852) -Fix (r8735): make the dynamite tool for drive through road stops as if it were removing a normal road tile (consider the local authority and such).
rubidium
parents: 6441
diff changeset
  2968
			if (IsDriveThroughStopTile(tile) && !CanRemoveRoadWithStop(tile))
6338
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2969
				return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION);
0fb4f452873c (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6326
diff changeset
  2970
			return RemoveRoadStop(st, flags, tile);
3334
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2971
		case STATION_BUOY:    return RemoveBuoy(st, flags);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2972
		case STATION_DOCK:    return RemoveDock(st, flags);
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2973
		default: break;
b72ac8637a30 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2974
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2975
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2976
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2977
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2978
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  2979
void InitializeStations()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2980
{
1272
d3e09adb7736 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
  2981
	/* Clean the station pool and create 1 block in it */
7875
8707d2caf12f (svn r10748) -Codechange: call the pool cleanup functions for stations directly instead of using the wrapper functions.
rubidium
parents: 7873
diff changeset
  2982
	_Station_pool.CleanPool();
8707d2caf12f (svn r10748) -Codechange: call the pool cleanup functions for stations directly instead of using the wrapper functions.
rubidium
parents: 7873
diff changeset
  2983
	_Station_pool.AddBlockToPool();
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2984
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  2985
	/* Clean the roadstop pool and create 1 block in it */
7875
8707d2caf12f (svn r10748) -Codechange: call the pool cleanup functions for stations directly instead of using the wrapper functions.
rubidium
parents: 7873
diff changeset
  2986
	_RoadStop_pool.CleanPool();
8707d2caf12f (svn r10748) -Codechange: call the pool cleanup functions for stations directly instead of using the wrapper functions.
rubidium
parents: 7873
diff changeset
  2987
	_RoadStop_pool.AddBlockToPool();
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2988
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2989
	_station_tick_ctr = 0;
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2990
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2991
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2992
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2993
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  2994
void AfterLoadStations()
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2995
{
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2996
	/* Update the speclists of all stations to point to the currently loaded custom stations. */
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2997
	Station *st;
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2998
	FOR_ALL_STATIONS(st) {
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  2999
		for (uint i = 0; i < st->num_specs; i++) {
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3000
			if (st->speclist[i].grfid == 0) continue;
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3001
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3002
			st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx);
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3003
		}
7506
e52d89f5c7c1 (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: 7451
diff changeset
  3004
e52d89f5c7c1 (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: 7451
diff changeset
  3005
		for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3006
	}
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3007
}
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3008
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7987
diff changeset
  3009
static CommandCost TerraformTile_Station(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7987
diff changeset
  3010
{
8078
bdf94bf88568 (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: 8041
diff changeset
  3011
	if (_patches.build_on_slopes && AutoslopeEnabled()) {
bdf94bf88568 (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: 8041
diff changeset
  3012
		/* TODO: If you implement newgrf callback 149 'land slope check', you have to decide what to do with it here.
bdf94bf88568 (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: 8041
diff changeset
  3013
		 *       TTDP does not call it.
bdf94bf88568 (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: 8041
diff changeset
  3014
		 */
bdf94bf88568 (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: 8041
diff changeset
  3015
		if (!IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
bdf94bf88568 (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: 8041
diff changeset
  3016
			switch (GetStationType(tile)) {
bdf94bf88568 (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: 8041
diff changeset
  3017
				case STATION_RAIL: {
bdf94bf88568 (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: 8041
diff changeset
  3018
					DiagDirection direction = AxisToDiagDir(GetRailStationAxis(tile));
bdf94bf88568 (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: 8041
diff changeset
  3019
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
bdf94bf88568 (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: 8041
diff changeset
  3020
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  3021
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
8078
bdf94bf88568 (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: 8041
diff changeset
  3022
				}
bdf94bf88568 (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: 8041
diff changeset
  3023
bdf94bf88568 (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: 8041
diff changeset
  3024
				case STATION_AIRPORT:
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  3025
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
8078
bdf94bf88568 (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: 8041
diff changeset
  3026
bdf94bf88568 (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: 8041
diff changeset
  3027
				case STATION_TRUCK:
bdf94bf88568 (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: 8041
diff changeset
  3028
				case STATION_BUS: {
bdf94bf88568 (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: 8041
diff changeset
  3029
					DiagDirection direction = GetRoadStopDir(tile);
bdf94bf88568 (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: 8041
diff changeset
  3030
					if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, direction)) break;
bdf94bf88568 (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: 8041
diff changeset
  3031
					if (IsDriveThroughStopTile(tile)) {
bdf94bf88568 (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: 8041
diff changeset
  3032
						if (!AutoslopeCheckForEntranceEdge(tile, z_new, tileh_new, ReverseDiagDir(direction))) break;
bdf94bf88568 (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: 8041
diff changeset
  3033
					}
8726
5ae45b46506b (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8721
diff changeset
  3034
					return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
8078
bdf94bf88568 (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: 8041
diff changeset
  3035
				}
bdf94bf88568 (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: 8041
diff changeset
  3036
bdf94bf88568 (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: 8041
diff changeset
  3037
				default: break;
bdf94bf88568 (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: 8041
diff changeset
  3038
			}
bdf94bf88568 (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: 8041
diff changeset
  3039
		}
bdf94bf88568 (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: 8041
diff changeset
  3040
	}
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7987
diff changeset
  3041
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7987
diff changeset
  3042
}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7987
diff changeset
  3043
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3044
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  3045
extern const TileTypeProcs _tile_type_station_procs = {
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3046
	DrawTile_Station,           /* draw_tile_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3047
	GetSlopeZ_Station,          /* get_slope_z_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3048
	ClearTile_Station,          /* clear_tile_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3049
	GetAcceptedCargo_Station,   /* get_accepted_cargo_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3050
	GetTileDesc_Station,        /* get_tile_desc_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3051
	GetTileTrackStatus_Station, /* get_tile_track_status_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3052
	ClickTile_Station,          /* click_tile_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3053
	AnimateTile_Station,        /* animate_tile_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3054
	TileLoop_Station,           /* tile_loop_clear */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3055
	ChangeTileOwner_Station,    /* change_tile_owner_clear */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3056
	NULL,                       /* get_produced_cargo_proc */
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3057
	VehicleEnter_Station,       /* vehicle_enter_tile_proc */
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
  3058
	GetFoundation_Station,      /* get_foundation_proc */
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7987
diff changeset
  3059
	TerraformTile_Station,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3060
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3061
1881
023a134a4b12 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1876
diff changeset
  3062
static const SaveLoad _roadstop_desc[] = {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3063
	SLE_VAR(RoadStop,xy,           SLE_UINT32),
5969
8aa5b3220178 (svn r8212) -Fix
tron
parents: 5967
diff changeset
  3064
	SLE_CONDNULL(1, 0, 44),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3065
	SLE_VAR(RoadStop,status,       SLE_UINT8),
1285
dee20e32bffe (svn r1789) -Fix: there is no need to save the index, it is done for us
truelight
parents: 1284
diff changeset
  3066
	/* Index was saved in some versions, but this is not needed */
3222
8bfed4267cba (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  3067
	SLE_CONDNULL(4, 0, 8),
5967
d862ebaf5035 (svn r8207) -Fix
tron
parents: 5960
diff changeset
  3068
	SLE_CONDNULL(2, 0, 44),
3479
a4d992b5d24d (svn r4324) Remove the unused road stop type attribute from struct RoadStop
tron
parents: 3478
diff changeset
  3069
	SLE_CONDNULL(1, 0, 25),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3070
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3071
	SLE_REF(RoadStop,next,         REF_ROADSTOPS),
6118
99a95cda1174 (svn r8449) -Fix
tron
parents: 6095
diff changeset
  3072
	SLE_CONDNULL(2, 0, 44),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3073
3431
0d7fa19d0b4a (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3429
diff changeset
  3074
	SLE_CONDNULL(4, 0, 24),
3475
1b68d263ae0e (svn r4320) -Fix/Codechange: rs->num_vehicles is no longer saved or loaded, but computed on the fly. Partly fixes FS#101
celestar
parents: 3474
diff changeset
  3075
	SLE_CONDNULL(1, 25, 25),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3076
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3077
	SLE_END()
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3078
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3079
1881
023a134a4b12 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1876
diff changeset
  3080
static const SaveLoad _station_desc[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3081
	SLE_CONDVAR(Station, xy,                         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3082
	SLE_CONDVAR(Station, xy,                         SLE_UINT32,                  6, SL_MAX_VERSION),
6130
f67231d82e91 (svn r8477) -Fix
tron
parents: 6129
diff changeset
  3083
	SLE_CONDNULL(4, 0, 5), // bus/lorry tile
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3084
	SLE_CONDVAR(Station, train_tile,                 SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3085
	SLE_CONDVAR(Station, train_tile,                 SLE_UINT32,                  6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3086
	SLE_CONDVAR(Station, airport_tile,               SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3087
	SLE_CONDVAR(Station, airport_tile,               SLE_UINT32,                  6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3088
	SLE_CONDVAR(Station, dock_tile,                  SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3089
	SLE_CONDVAR(Station, dock_tile,                  SLE_UINT32,                  6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3090
	    SLE_REF(Station, town,                       REF_TOWN),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3091
	    SLE_VAR(Station, trainst_w,                  SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3092
	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
  3093
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  3094
	/* alpha_order was stored here in savegame format 0 - 3 */
3222
8bfed4267cba (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  3095
	SLE_CONDNULL(1, 0, 3),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3096
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3097
	    SLE_VAR(Station, string_id,                  SLE_STRINGID),
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8750
diff changeset
  3098
	SLE_CONDSTR(Station, name,                       SLE_STR, 0,                 84, SL_MAX_VERSION),
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3099
	    SLE_VAR(Station, had_vehicle_of_type,        SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3100
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3101
	    SLE_VAR(Station, time_since_load,            SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3102
	    SLE_VAR(Station, time_since_unload,          SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3103
	    SLE_VAR(Station, delete_ctr,                 SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3104
	    SLE_VAR(Station, owner,                      SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3105
	    SLE_VAR(Station, facilities,                 SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3106
	    SLE_VAR(Station, airport_type,               SLE_UINT8),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3107
6129
a31e9d63bba2 (svn r8476) -Fix
tron
parents: 6128
diff changeset
  3108
	SLE_CONDNULL(2, 0, 5), // Truck/bus stop status
6128
46154e074b58 (svn r8475) -Fix
tron
parents: 6127
diff changeset
  3109
	SLE_CONDNULL(1, 0, 4), // Blocked months
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3110
6321
62564548351b (svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents: 6317
diff changeset
  3111
	SLE_CONDVAR(Station, airport_flags,              SLE_VAR_U64 | SLE_FILE_U16,  0,  2),
62564548351b (svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents: 6317
diff changeset
  3112
	SLE_CONDVAR(Station, airport_flags,              SLE_VAR_U64 | SLE_FILE_U32,  3, 45),
62564548351b (svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents: 6317
diff changeset
  3113
	SLE_CONDVAR(Station, airport_flags,              SLE_UINT64,                 46, SL_MAX_VERSION),
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3114
3580
607e4245d024 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3576
diff changeset
  3115
	SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3116
	SLE_CONDVAR(Station, last_vehicle_type,          SLE_UINT8,                  26, SL_MAX_VERSION),
3554
c16eadc2d060 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  3117
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  3118
	/* Was custom station class and id */
3574
bf5f6c1af32c (svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents: 3568
diff changeset
  3119
	SLE_CONDNULL(2, 3, 25),
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3120
	SLE_CONDVAR(Station, build_date,                 SLE_FILE_U16 | SLE_VAR_I32,  3, 30),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3121
	SLE_CONDVAR(Station, build_date,                 SLE_INT32,                  31, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3122
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3123
	SLE_CONDREF(Station, bus_stops,                  REF_ROADSTOPS,               6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3124
	SLE_CONDREF(Station, truck_stops,                REF_ROADSTOPS,               6, SL_MAX_VERSION),
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3125
3687
109ec5cdb932 (svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents: 3682
diff changeset
  3126
	/* Used by newstations for graphic variations */
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3127
	SLE_CONDVAR(Station, random_bits,                SLE_UINT16,                 27, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3128
	SLE_CONDVAR(Station, waiting_triggers,           SLE_UINT8,                  27, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  3129
	SLE_CONDVAR(Station, num_specs,                  SLE_UINT8,                  27, SL_MAX_VERSION),
3687
109ec5cdb932 (svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents: 3682
diff changeset
  3130
6996
99dd61b18d69 (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: 6987
diff changeset
  3131
	SLE_CONDLST(Station, loading_vehicles,           REF_VEHICLE,                57, SL_MAX_VERSION),
99dd61b18d69 (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: 6987
diff changeset
  3132
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  3133
	/* reserve extra space in savegame here. (currently 32 bytes) */
3222
8bfed4267cba (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  3134
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3135
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3136
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3137
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3138
7506
e52d89f5c7c1 (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: 7451
diff changeset
  3139
static uint16 _waiting_acceptance;
e52d89f5c7c1 (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: 7451
diff changeset
  3140
static uint16 _cargo_source;
e52d89f5c7c1 (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: 7451
diff changeset
  3141
static uint32 _cargo_source_xy;
e52d89f5c7c1 (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: 7451
diff changeset
  3142
static uint16 _cargo_days;
e52d89f5c7c1 (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: 7451
diff changeset
  3143
static Money  _cargo_feeder_share;
e52d89f5c7c1 (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: 7451
diff changeset
  3144
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3145
static const SaveLoad _station_speclist_desc[] = {
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3146
	SLE_CONDVAR(StationSpecList, grfid,    SLE_UINT32, 27, SL_MAX_VERSION),
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3147
	SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8,  27, SL_MAX_VERSION),
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3148
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3149
	SLE_END()
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3150
};
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3151
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3152
7987
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3153
void SaveLoad_STNS(Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3154
{
7987
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3155
	static const SaveLoad _goods_desc[] = {
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3156
		SLEG_CONDVAR(            _waiting_acceptance, SLE_UINT16,                  0, 67),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3157
		 SLE_CONDVAR(GoodsEntry, acceptance_pickup,   SLE_UINT8,                  68, SL_MAX_VERSION),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3158
		SLE_CONDNULL(2,                                                           51, 67),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3159
		     SLE_VAR(GoodsEntry, days_since_pickup,   SLE_UINT8),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3160
		     SLE_VAR(GoodsEntry, rating,              SLE_UINT8),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3161
		SLEG_CONDVAR(            _cargo_source,       SLE_FILE_U8 | SLE_VAR_U16,   0, 6),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3162
		SLEG_CONDVAR(            _cargo_source,       SLE_UINT16,                  7, 67),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3163
		SLEG_CONDVAR(            _cargo_source_xy,    SLE_UINT32,                 44, 67),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3164
		SLEG_CONDVAR(            _cargo_days,         SLE_UINT8,                   0, 67),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3165
		     SLE_VAR(GoodsEntry, last_speed,          SLE_UINT8),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3166
		     SLE_VAR(GoodsEntry, last_age,            SLE_UINT8),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3167
		SLEG_CONDVAR(            _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, 14, 64),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3168
		SLEG_CONDVAR(            _cargo_feeder_share, SLE_INT64,                  65, 67),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3169
		 SLE_CONDLST(GoodsEntry, cargo.packets,       REF_CARGO_PACKET,           68, SL_MAX_VERSION),
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3170
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3171
		SLE_END()
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3172
};
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3173
b3627df3493a (svn r11002) -Codechange: unhackify the cargo packet list saving (a little).
rubidium
parents: 7970
diff changeset
  3174
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3175
	SlObject(st, _station_desc);
6959
0066ab0d9b93 (svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138
parents: 6949
diff changeset
  3176
7506
e52d89f5c7c1 (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: 7451
diff changeset
  3177
	_waiting_acceptance = 0;
e52d89f5c7c1 (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: 7451
diff changeset
  3178
6959
0066ab0d9b93 (svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138
parents: 6949
diff changeset
  3179
	uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
0066ab0d9b93 (svn r9638) -Feature: Increase cargo types from 12 to 32 and enable newcargo flag in NewGRF loader.
peter1138
parents: 6949
diff changeset
  3180
	for (CargoID i = 0; i < num_cargo; i++) {
7506
e52d89f5c7c1 (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: 7451
diff changeset
  3181
		GoodsEntry *ge = &st->goods[i];
e52d89f5c7c1 (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: 7451
diff changeset
  3182
		SlObject(ge, _goods_desc);
7509
5adc45aa7c3c (svn r10269) -Fix [FS#912]: station ratings were shown for all cargos instead of only the cargos that have been transported.
rubidium
parents: 7506
diff changeset
  3183
		if (CheckSavegameVersion(68)) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
  3184
			SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
7506
e52d89f5c7c1 (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: 7451
diff changeset
  3185
			if (GB(_waiting_acceptance, 0, 12) != 0) {
e52d89f5c7c1 (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: 7451
diff changeset
  3186
				/* Don't construct the packet with station here, because that'll fail with old savegames */
e52d89f5c7c1 (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: 7451
diff changeset
  3187
				CargoPacket *cp = new CargoPacket();
e52d89f5c7c1 (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: 7451
diff changeset
  3188
				/* In old versions, enroute_from used 0xFF as INVALID_STATION */
e52d89f5c7c1 (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: 7451
diff changeset
  3189
				cp->source          = (CheckSavegameVersion(7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
e52d89f5c7c1 (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: 7451
diff changeset
  3190
				cp->count           = GB(_waiting_acceptance, 0, 12);
e52d89f5c7c1 (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: 7451
diff changeset
  3191
				cp->days_in_transit = _cargo_days;
e52d89f5c7c1 (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: 7451
diff changeset
  3192
				cp->feeder_share    = _cargo_feeder_share;
e52d89f5c7c1 (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: 7451
diff changeset
  3193
				cp->source_xy       = _cargo_source_xy;
e52d89f5c7c1 (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: 7451
diff changeset
  3194
				cp->days_in_transit = _cargo_days;
e52d89f5c7c1 (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: 7451
diff changeset
  3195
				cp->feeder_share    = _cargo_feeder_share;
7970
204ece3a05d5 (svn r10981) -Fix [FS#1156] (r10970): stations gave ratings for accepted cargo too.
rubidium
parents: 7965
diff changeset
  3196
				SB(ge->acceptance_pickup, GoodsEntry::PICKUP, 1, 1);
7506
e52d89f5c7c1 (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: 7451
diff changeset
  3197
				ge->cargo.Append(cp);
e52d89f5c7c1 (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: 7451
diff changeset
  3198
			}
e52d89f5c7c1 (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: 7451
diff changeset
  3199
		}
1266
9dc5638fe8cc (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  3200
	}
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3201
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3202
	if (st->num_specs != 0) {
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3203
		/* Allocate speclist memory when loading a game */
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5852
diff changeset
  3204
		if (st->speclist == NULL) st->speclist = CallocT<StationSpecList>(st->num_specs);
6395
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3205
		for (uint i = 0; i < st->num_specs; i++) {
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3206
			SlObject(&st->speclist[i], _station_speclist_desc);
51c2bbcb357f (svn r8799) -Fix
tron
parents: 6393
diff changeset
  3207
		}
3765
e057e2b740d4 (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  3208
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3209
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3210
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3211
static void Save_STNS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3212
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3213
	Station *st;
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  3214
	/* Write the stations */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3215
	FOR_ALL_STATIONS(st) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3216
		SlSetArrayIndex(st->index);
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3217
		SlAutolength((AutolengthProc*)SaveLoad_STNS, st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3218
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3219
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3220
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3221
static void Load_STNS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3222
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3223
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3224
	while ((index = SlIterateArray()) != -1) {
5916
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  3225
		Station *st = new (index) Station();
75c6d5cf1600 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5911
diff changeset
  3226
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3227
		SaveLoad_STNS(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3228
8291
443b58ba6f8a (svn r11345) -Cleanup: a bit of comment style fixing
belugas
parents: 8254
diff changeset
  3229
		/* this means it's an oldstyle savegame without support for nonuniform stations */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  3230
		if (st->train_tile != 0 && st->trainst_h == 0) {
3033
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3231
			uint w = GB(st->trainst_w, 4, 4);
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3232
			uint h = GB(st->trainst_w, 0, 4);
e4f7c60a1742 (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  3233
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 6424
diff changeset
  3234
			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
  3235
			st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3236
			st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3237
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3238
	}
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  3239
1472
043304846688 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
  3240
	/* This is to ensure all pointers are within the limits of _stations_size */
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5220
diff changeset
  3241
	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
  3242
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  3243
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3244
static void Save_ROADSTOP()
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3245
{
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3246
	RoadStop *rs;
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3247
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3248
	FOR_ALL_ROADSTOPS(rs) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3249
		SlSetArrayIndex(rs->index);
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3250
		SlObject(rs, _roadstop_desc);
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3251
	}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3252
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3253
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  3254
static void Load_ROADSTOP()
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3255
{
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3256
	int index;
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3257
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3258
	while ((index = SlIterateArray()) != -1) {
5967
d862ebaf5035 (svn r8207) -Fix
tron
parents: 5960
diff changeset
  3259
		RoadStop *rs = new (index) RoadStop(INVALID_TILE);
5959
6a4c261987c3 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5948
diff changeset
  3260
1284
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3261
		SlObject(rs, _roadstop_desc);
06a52178bf46 (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3262
	}
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3263
}
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3264
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  3265
extern const ChunkHandler _station_chunk_handlers[] = {
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3266
	{ 'STNS', Save_STNS,      Load_STNS,      CH_ARRAY },
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3267
	{ '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
  3268
};