src/station_cmd.cpp
author tron
Fri, 16 Feb 2007 09:38:43 +0000
changeset 6032 fe6a454ac1ba
parent 6018 5d143f68ac94
child 6039 764b76f50475
permissions -rw-r--r--
(svn r8755) -Fix

Abbreviate GetAirport(st->airport_type) to st->Airport()
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
     3
/** @file station_cmd.c */
2213
bab9abeaa644 (svn r2731) -Fix [ 1244171 ]: Hangar orders are now properly invalidated as soon as the airport is removed
celestar
parents: 2187
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
     7
#include "bridge_map.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1295
diff changeset
     8
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2148
diff changeset
     9
#include "functions.h"
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
    10
#include "station_map.h"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1335
diff changeset
    11
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 500
diff changeset
    12
#include "table/strings.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 595
diff changeset
    13
#include "map.h"
1209
2e00193652b2 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1190
diff changeset
    14
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
#include "airport.h"
405
415546028e8d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    27
#include "sprite.h"
1313
f1013ec3d318 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    28
#include "depot.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2671
diff changeset
    29
#include "train.h"
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
    30
#include "water_map.h"
3515
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
    31
#include "industry_map.h"
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
    32
#include "newgrf_callbacks.h"
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
    33
#include "newgrf_station.h"
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
    34
#include "yapf/yapf.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4231
diff changeset
    35
#include "date.h"
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    36
#include "helpers.hpp"
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
    37
#include "misc/autoptr.hpp"
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
    38
#include "road.h"
5666
d0e00c728f41 (svn r8126) -Fix (r8125): missing #include fixes compilation error on g++ (still some warnings, working on it)
KUDr
parents: 5665
diff changeset
    39
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    40
/**
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    41
 * Called if a new block is added to the station-pool
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    42
 */
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    43
static void StationPoolNewBlock(uint start_item)
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    44
{
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    45
	Station *st;
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    46
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    47
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
4348
d9ddb0558a48 (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
    48
	 *  TODO - This is just a temporary stage, this will be removed. */
4980
1e1cb22b3d27 (svn r6983) Use the pool macros for the Station pool
tron
parents: 4910
diff changeset
    49
	for (st = GetStation(start_item); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) st->index = start_item++;
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    50
}
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    51
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    52
static void StationPoolCleanBlock(uint start_item, uint end_item)
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    53
{
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    54
	uint i;
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    55
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    56
	for (i = start_item; i <= end_item; i++) {
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    57
		Station *st = GetStation(i);
5996
4bcab9c286d8 (svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents: 5995
diff changeset
    58
		if (st->IsValid()) st->~Station();
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    59
	}
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    60
}
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
    61
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    62
/**
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    63
 * Called if a new block is added to the roadstop-pool
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    64
 */
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    65
static void RoadStopPoolNewBlock(uint start_item)
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    66
{
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    67
	RoadStop *rs;
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    68
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    69
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    70
	 * TODO - This is just a temporary stage, this will be removed. */
5718
ce37296bb03c (svn r8212) -Fix
tron
parents: 5716
diff changeset
    71
	for (rs = GetRoadStop(start_item); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) {
ce37296bb03c (svn r8212) -Fix
tron
parents: 5716
diff changeset
    72
		rs->xy    = INVALID_TILE;
ce37296bb03c (svn r8212) -Fix
tron
parents: 5716
diff changeset
    73
		rs->index = start_item++;
ce37296bb03c (svn r8212) -Fix
tron
parents: 5716
diff changeset
    74
	}
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    75
}
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
    76
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 5116
diff changeset
    77
DEFINE_OLD_POOL(Station, Station, StationPoolNewBlock, StationPoolCleanBlock)
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 5116
diff changeset
    78
DEFINE_OLD_POOL(RoadStop, RoadStop, RoadStopPoolNewBlock, NULL)
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    79
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
    80
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
extern void UpdateAirplanesOnNewStation(Station *st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    83
5836
a60d2114780e (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: 5834
diff changeset
    84
RoadStop* GetRoadStopByTile(TileIndex tile, RoadStop::Type type)
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    85
{
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
    86
	const Station* st = GetStationByTile(tile);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    87
	RoadStop* rs;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    88
5876
01bdebe2e50b (svn r8474) -Fix
tron
parents: 5867
diff changeset
    89
	for (rs = st->GetPrimaryRoadStop(type); rs->xy != tile; rs = rs->next) {
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    90
		assert(rs->next != NULL);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    91
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    92
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    93
	return rs;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    94
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    95
5913
727fc088635a (svn r8539) -Fix
tron
parents: 5906
diff changeset
    96
727fc088635a (svn r8539) -Fix
tron
parents: 5906
diff changeset
    97
static uint GetNumRoadStopsInStation(const Station* st, RoadStop::Type type)
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
    98
{
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
    99
	uint num = 0;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   100
	const RoadStop *rs;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   101
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   102
	assert(st != NULL);
5876
01bdebe2e50b (svn r8474) -Fix
tron
parents: 5867
diff changeset
   103
	for (rs = st->GetPrimaryRoadStop(type); rs != NULL; rs = rs->next) num++;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   104
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   105
	return num;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   106
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   107
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   108
703
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   109
/* Calculate the radius of the station. Basicly it is the biggest
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   110
 *  radius that is available within the station */
2643
f1fec6d1559a (svn r3185) const
tron
parents: 2642
diff changeset
   111
static uint FindCatchmentRadius(const Station* st)
703
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   112
{
5601
d58f82901b2f (svn r8055) -Codechange: Replace the different max, dmax, maxu whatever macros by a simple template function max(), that requires two arguments of the same type. While I'm at it change a variable called "max" to "maxval" in a function that calls max().
celestar
parents: 5587
diff changeset
   113
	CatchmentAera ret = CA_NONE;
703
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   114
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   115
	if (st->bus_stops != NULL)   ret = max(ret, CA_BUS);
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   116
	if (st->truck_stops != NULL) ret = max(ret, CA_TRUCK);
703
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   117
	if (st->train_tile) ret = max(ret, CA_TRAIN);
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   118
	if (st->dock_tile)  ret = max(ret, CA_DOCK);
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   119
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   120
	if (st->airport_tile) {
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   121
		switch (st->airport_type) {
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   122
			case AT_OILRIG:        ret = max(ret, CA_AIR_OILPAD);   break;
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   123
			case AT_SMALL:         ret = max(ret, CA_AIR_SMALL);    break;
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   124
			case AT_HELIPORT:      ret = max(ret, CA_AIR_HELIPORT); break;
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   125
			case AT_LARGE:         ret = max(ret, CA_AIR_LARGE);    break;
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   126
			case AT_METROPOLITAN:  ret = max(ret, CA_AIR_METRO);    break;
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   127
			case AT_INTERNATIONAL: ret = max(ret, CA_AIR_INTER);    break;
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
   128
			case AT_COMMUTER:      ret = max(ret, CA_AIR_COMMUTER); break;
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
   129
			case AT_HELIDEPOT:     ret = max(ret, CA_AIR_HELIDEPOT); break;
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
   130
			case AT_INTERCON:      ret = max(ret, CA_AIR_INTERCON); break;
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
   131
			case AT_HELISTATION:   ret = max(ret, CA_AIR_HELISTATION); break;
703
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   132
		}
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   133
	}
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   134
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   135
	return ret;
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   136
}
3f64a428fcbc (svn r1153) -Fix: FindCatchmentRadius is now a function that uses the enums instead
truelight
parents: 701
diff changeset
   137
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
#define CHECK_STATIONS_ERR ((Station*)-1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   140
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
   141
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	// check around to see if there's any stations there
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   143
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   144
		if (IsTileType(tile_cur, MP_STATION)) {
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
   145
			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
   146
			{
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   147
				Station *st = GetStation(t);
28
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   148
				// you cannot take control of an oilrig!!
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   149
				if (st->airport_type == AT_OILRIG && st->facilities == (FACIL_AIRPORT|FACIL_DOCK))
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   150
					continue;
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   151
			}
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   152
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   153
			if (closest_station == INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
				closest_station = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
			} else if (closest_station != t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
				_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
				return CHECK_STATIONS_ERR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
		}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   160
	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   161
	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
   162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1078
diff changeset
   164
static Station *AllocateStation(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
{
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   166
	Station *st = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   168
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   169
	 * TODO - This is just a temporary stage, this will be removed. */
4980
1e1cb22b3d27 (svn r6983) Use the pool macros for the Station pool
tron
parents: 4910
diff changeset
   170
	for (st = GetStation(0); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) {
5996
4bcab9c286d8 (svn r8707) -Codechange: Turn IsValidStation into a method of Station
celestar
parents: 5995
diff changeset
   171
		if (!st->IsValid()) {
1551
b1c7df6daa63 (svn r2055) -CodeChange: Begun introducting StationID
celestar
parents: 1527
diff changeset
   172
			StationID index = st->index;
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   173
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   174
			memset(st, 0, sizeof(Station));
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   175
			st->index = index;
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   176
			return st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   180
	/* Check if we can add a block to the pool */
4980
1e1cb22b3d27 (svn r6983) Use the pool macros for the Station pool
tron
parents: 4910
diff changeset
   181
	if (AddBlockToPool(&_Station_pool)) return AllocateStation();
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   182
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   183
	_error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
   184
	return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
3515
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   188
/**
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   189
 * Counts the numbers of tiles matching a specific type in the area around
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   190
 * @param tile the center tile of the 'count area'
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   191
 * @param type the type of tile searched for
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   192
 * @param industry when type == MP_INDUSTRY, the type of the industry,
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   193
 *                 in all other cases this parameter is ignored
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   194
 * @result the noumber of matching tiles around
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   195
 */
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   196
static int CountMapSquareAround(TileIndex tile, TileType type, IndustryType industry)
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   197
{
3515
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   198
	TileIndex cur_tile;
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   199
	int dx, dy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
3515
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   202
	for (dx = -3; dx <= 3; dx++) {
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   203
		for (dy = -3; dy <= 3; dy++) {
3682
e435df955cf6 (svn r4602) - Fix: an assertion triggered when building a station near the south corner of the map (appeared in r4367)
glx
parents: 3676
diff changeset
   204
			cur_tile = TILE_MASK(tile + TileDiffXY(dx, dy));
3515
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   205
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   206
			if (IsTileType(cur_tile, type)) {
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   207
				switch (type) {
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   208
					case MP_INDUSTRY:
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   209
						if (GetIndustryType(cur_tile) == industry)
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   210
							num++;
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   211
						break;
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   212
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   213
					case MP_WATER:
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   214
						if (!IsWater(cur_tile))
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   215
							break;
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   216
						/* FALL THROUGH WHEN WATER TILE */
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   217
					case MP_TREES:
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   218
						num++;
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   219
						break;
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   220
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   221
					default:
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   222
						break;
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   223
				}
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   224
			}
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   225
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	return num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
#define M(x) ((x) - STR_SV_STNAME)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   233
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
   234
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	static const uint32 _gen_station_name_bits[] = {
1454
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   236
		0,                                      /* 0 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   237
		1 << M(STR_SV_STNAME_AIRPORT),          /* 1 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   238
		1 << M(STR_SV_STNAME_OILFIELD),         /* 2 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   239
		1 << M(STR_SV_STNAME_DOCKS),            /* 3 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   240
		0x1FF << M(STR_SV_STNAME_BUOY_1),       /* 4 */
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   241
		1 << M(STR_SV_STNAME_HELIPORT),         /* 5 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	};
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
	Town *t = st->town;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	uint32 free_names = (uint32)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
	int found;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	uint z,z2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	unsigned long tmp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
		Station *s;
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
		FOR_ALL_STATIONS(s) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   254
			if (s != st && s->town==t) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
				uint str = M(s->string_id);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
				if (str <= 0x20) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
					if (str == M(STR_SV_STNAME_FOREST))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
						str = M(STR_SV_STNAME_WOODS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
					CLRBIT(free_names, str);
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
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   262
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   264
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	/* check default names */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
	tmp = free_names & _gen_station_name_bits[flag];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	if (tmp != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
		found = FindFirstBit(tmp);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
		goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	/* check mine? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) {
3515
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   274
		if (CountMapSquareAround(tile, MP_INDUSTRY, IT_COAL_MINE) >= 2 ||
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   275
				CountMapSquareAround(tile, MP_INDUSTRY, IT_IRON_MINE) >= 2 ||
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   276
				CountMapSquareAround(tile, MP_INDUSTRY, IT_COPPER_MINE) >= 2 ||
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   277
				CountMapSquareAround(tile, MP_INDUSTRY, IT_GOLD_MINE) >= 2 ||
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   278
				CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) {
1454
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   279
			found = M(STR_SV_STNAME_MINES);
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   280
			goto done;
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   281
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
	/* check close enough to town to get central as name? */
1245
3822f77cbc53 (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1239
diff changeset
   285
	if (DistanceMax(tile,t->xy) < 8) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
		found = M(STR_SV_STNAME);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
		if (HASBIT(free_names, M(STR_SV_STNAME))) goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
		found = M(STR_SV_STNAME_CENTRAL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
		if (HASBIT(free_names, M(STR_SV_STNAME_CENTRAL))) goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	}
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
	/* Check lakeside */
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   294
	if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   295
			DistanceFromEdge(tile) < 20 &&
3515
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   296
			CountMapSquareAround(tile, MP_WATER, 0) >= 5) {
1454
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   297
		found = M(STR_SV_STNAME_LAKESIDE);
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   298
		goto done;
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   299
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	/* Check woods */
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   302
	if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && (
3515
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   303
				CountMapSquareAround(tile, MP_TREES, 0) >= 8 ||
86dccaaef457 (svn r4367) CodeChange : Remove another direct map access in station_cmd.c. Replace an array of TileIndexDiffC by a use of loop with TileDiffXY. Thanks to Rubidium
belugas
parents: 3503
diff changeset
   304
				CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2)
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   305
			) {
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   306
		found = _opt.landscape == LT_DESERT ?
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   307
			M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
1454
ffc16bcbe046 (svn r1958) GenerateStationName() tidyup.
pasky
parents: 1424
diff changeset
   308
		goto done;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	/* check elevation compared to town */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	z = GetTileZ(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	z2 = GetTileZ(t->xy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	if (z < z2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
		found = M(STR_SV_STNAME_VALLEY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
		if (HASBIT(free_names, M(STR_SV_STNAME_VALLEY))) goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	} else if (z > z2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
		found = M(STR_SV_STNAME_HEIGHTS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
		if (HASBIT(free_names, M(STR_SV_STNAME_HEIGHTS))) goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
	/* check direction compared to town */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
		static const int8 _direction_and_table[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
			~( (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
			~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
			~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
			~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) ),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
		};
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   330
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   331
		free_names &= _direction_and_table[
926
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   332
			(TileX(tile) < TileX(t->xy)) +
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   333
			(TileY(tile) < TileY(t->xy)) * 2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	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));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	if (tmp == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
		_error_message = STR_3007_TOO_MANY_STATIONS_LOADING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
		return false;
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
	found = FindFirstBit(tmp);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
done:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
	st->string_id = found + STR_SV_STNAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
#undef M
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   349
static Station* GetClosestStationFromTile(TileIndex tile, uint threshold, PlayerID owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
{
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   351
	Station* best_station = NULL;
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   352
	Station* st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
	FOR_ALL_STATIONS(st) {
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4638
diff changeset
   355
		if ((owner == PLAYER_SPECTATOR || st->owner == owner)) {
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   356
			uint cur_dist = DistanceManhattan(tile, st->xy);
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   357
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   358
			if (cur_dist < threshold) {
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   359
				threshold = cur_dist;
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   360
				best_station = st;
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   361
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
	return best_station;
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
// Update the virtual coords needed to draw the station sign.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
// st = Station to update for.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
static void UpdateStationVirtCoord(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
{
3422
a6eba3443452 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 3418
diff changeset
   372
	Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   373
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
	pt.y -= 32;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   375
	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
   376
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   377
	SetDParam(0, st->index);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   378
	SetDParam(1, st->facilities);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	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
   380
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
// Update the virtual coords needed to draw the station sign for all stations.
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1078
diff changeset
   383
void UpdateAllStationVirtCoord(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   385
	Station* st;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   386
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
	FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   388
		UpdateStationVirtCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
// Update the station virt coords while making the modified parts dirty.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
static void UpdateStationVirtCoordDirty(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
{
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   395
	st->MarkDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
	UpdateStationVirtCoord(st);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   397
	st->MarkDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
// Get a mask of the cargo types that the station accepts.
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   401
static uint GetAcceptanceMask(const Station *st)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	uint mask = 0;
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   404
	uint i;
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   405
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   406
	for (i = 0; i != NUM_CARGO; i++) {
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   407
		if (st->goods[i].waiting_acceptance & 0x8000) mask |= 1 << i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	return mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
// Items contains the two cargo names that are to be accepted or rejected.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
// msg is the string id of the message to display.
5690
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   414
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
   415
{
5690
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   416
	for (uint i = 0; i < num_items; i++) {
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   417
		SetDParam(i + 1, _cargoc.names_s[cargo[i]]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
	}
5690
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   419
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   420
	SetDParam(0, st->index);
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   421
	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
   422
}
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
// Get a list of the cargo types being produced around the tile.
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   425
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile,
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   426
	int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
	int x1,y1,x2,y2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
	int xc,yc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
2133
d7f582b7001d (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   432
	memset(produced, 0, sizeof(AcceptedCargo));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
926
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   434
	x = TileX(tile);
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   435
	y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   437
	// expand the region by rad tiles on each side
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
	// while making sure that we remain inside the board.
856
918759cedca8 (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 847
diff changeset
   439
	x2 = min(x + w + rad, MapSizeX());
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   440
	x1 = max(x - rad, 0);
568
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   441
856
918759cedca8 (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 847
diff changeset
   442
	y2 = min(y + h + rad, MapSizeY());
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   443
	y1 = max(y - rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   450
	for (yc = y1; yc != y2; yc++) {
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   451
		for (xc = x1; xc != x2; xc++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
			if (!(IS_INSIDE_1D(xc, x, w) && IS_INSIDE_1D(yc, y, h))) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
				GetProducedCargoProc *gpc;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   454
				TileIndex tile = TileXY(xc, yc);
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   455
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   456
				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
   457
				if (gpc != NULL) {
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3334
diff changeset
   458
					CargoID cargos[2] = { CT_INVALID, CT_INVALID };
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   459
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
					gpc(tile, cargos);
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   461
					if (cargos[0] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
						produced[cargos[0]]++;
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   463
						if (cargos[1] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
							produced[cargos[1]]++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
			}
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   469
		}
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   470
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
// Get a list of the cargo types that are accepted around the tile.
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   474
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile,
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   475
	int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	int x1,y1,x2,y2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
	int xc,yc;
473
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   480
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   481
	memset(accepts, 0, sizeof(AcceptedCargo));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
926
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   483
	x = TileX(tile);
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   484
	y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   486
	// expand the region by rad tiles on each side
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
	// while making sure that we remain inside the board.
856
918759cedca8 (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 847
diff changeset
   488
	x2 = min(x + w + rad, MapSizeX());
918759cedca8 (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 847
diff changeset
   489
	y2 = min(y + h + rad, MapSizeY());
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   490
	x1 = max(x - rad, 0);
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   491
	y1 = max(y - rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   498
	for (yc = y1; yc != y2; yc++) {
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   499
		for (xc = x1; xc != x2; xc++) {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   500
			TileIndex tile = TileXY(xc, yc);
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   501
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   502
			if (!IsTileType(tile, MP_STATION)) {
473
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   503
				AcceptedCargo ac;
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   504
				uint i;
473
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   505
77f0ef57e7cf (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   506
				GetAcceptedCargo(tile, ac);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   507
				for (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
   508
			}
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   509
		}
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   510
	}
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
2793
a0d17504b599 (svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents: 2767
diff changeset
   513
typedef struct ottd_Rectangle {
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   514
	uint min_x;
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   515
	uint min_y;
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   516
	uint max_x;
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   517
	uint max_y;
2793
a0d17504b599 (svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents: 2767
diff changeset
   518
} ottd_Rectangle;
a0d17504b599 (svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents: 2767
diff changeset
   519
5103
fbd04229cae3 (svn r7174) -CodeChange: CheckStationSpreadOut() now uses MergePoint() for bounding rectangle calculation.
KUDr
parents: 5098
diff changeset
   520
static inline void MergePoint(ottd_Rectangle* rect, TileIndex tile)
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   521
{
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   522
	uint x = TileX(tile);
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   523
	uint y = TileY(tile);
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   524
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   525
	if (rect->min_x > x) rect->min_x = x;
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   526
	if (rect->min_y > y) rect->min_y = y;
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   527
	if (rect->max_x < x) rect->max_x = x;
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   528
	if (rect->max_y < y) rect->max_y = y;
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   529
}
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   530
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
// Update the acceptance for a station.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
// show_msg controls whether to display a message that acceptance was changed.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
static void UpdateStationAcceptance(Station *st, bool show_msg)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
	uint old_acc, new_acc;
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   536
	const RoadStop *cur_rs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
	int i;
2793
a0d17504b599 (svn r3341) -Codechange: make mingw32 happy, and renamed Rectangle, because it already exists on that platform
truelight
parents: 2767
diff changeset
   538
	ottd_Rectangle rect;
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   539
	int rad;
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   540
	AcceptedCargo accepts;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
1507
18cb39ddddfd (svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents: 1477
diff changeset
   542
	rect.min_x = MapSizeX();
18cb39ddddfd (svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents: 1477
diff changeset
   543
	rect.min_y = MapSizeY();
18cb39ddddfd (svn r2011) - Fix: [ 1162209 ] Fix OS/2 build (orudge) #2
darkvater
parents: 1477
diff changeset
   544
	rect.max_x = rect.max_y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	// Don't update acceptance for a buoy
5896
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5890
diff changeset
   546
	if (st->IsBuoy()) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
	/* old accepted goods types */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	old_acc = GetAcceptanceMask(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	// Put all the tiles that span an area in the table.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	if (st->train_tile != 0) {
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   553
		MergePoint(&rect, st->train_tile);
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   554
		MergePoint(&rect,
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   555
			st->train_tile + TileDiffXY(st->trainst_w - 1, st->trainst_h - 1)
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   556
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   558
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
	if (st->airport_tile != 0) {
6032
fe6a454ac1ba (svn r8755) -Fix
tron
parents: 6018
diff changeset
   560
		const AirportFTAClass* afc = st->Airport();
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
   561
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   562
		MergePoint(&rect, st->airport_tile);
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   563
		MergePoint(&rect,
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
   564
			st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1)
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   565
		);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   566
	}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   567
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   568
	if (st->dock_tile != 0) MergePoint(&rect, st->dock_tile);
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   569
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   570
	for (cur_rs = st->bus_stops; cur_rs != NULL; cur_rs = cur_rs->next) {
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   571
		MergePoint(&rect, cur_rs->xy);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   572
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   574
	for (cur_rs = st->truck_stops; cur_rs != NULL; cur_rs = cur_rs->next) {
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   575
		MergePoint(&rect, cur_rs->xy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
   577
2631
2ed0eb408229 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
   578
	rad = (_patches.modified_catchment) ? FindCatchmentRadius(st) : 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
	// And retrieve the acceptance.
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   581
	if (rect.max_x >= rect.min_x) {
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   582
		GetAcceptanceAroundTiles(
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   583
			accepts,
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   584
			TileXY(rect.min_x, rect.min_y),
1423
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   585
			rect.max_x - rect.min_x + 1,
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   586
			rect.max_y - rect.min_y + 1,
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   587
			rad
11cd644bf8f8 (svn r1927) Replace implementation of UpdateStationAcceptance(). The new one doesn't malloc() and calculates the station area in one pass instead of 3
tron
parents: 1417
diff changeset
   588
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
		memset(accepts, 0, sizeof(accepts));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
	// Adjust in case our station only accepts fewer kinds of goods
1424
38b76de179c9 (svn r1928) Miscellaneous cleanups (data types, whitespace, const correctness)
tron
parents: 1423
diff changeset
   594
	for (i = 0; i != NUM_CARGO; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
		uint amt = min(accepts[i], 15);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		// Make sure the station can accept the goods type.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
		if ((i != CT_PASSENGERS && !(st->facilities & (byte)~FACIL_BUS_STOP)) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
				(i == CT_PASSENGERS && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
			amt = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
2504
5ae89f643cdc (svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents: 2502
diff changeset
   602
		SB(st->goods[i].waiting_acceptance, 12, 4, amt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
	// Only show a message in case the acceptance was actually changed.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	new_acc = GetAcceptanceMask(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
	if (old_acc == new_acc)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   609
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
	// show a message to report that the acceptance was changed?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
	if (show_msg && st->owner == _local_player && st->facilities) {
5690
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   612
		/* List of accept and reject strings for different number of
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   613
		 * cargo types */
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   614
		static const StringID accept_msg[] = {
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   615
			STR_3040_NOW_ACCEPTS,
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   616
			STR_3041_NOW_ACCEPTS_AND,
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   617
		};
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   618
		static const StringID reject_msg[] = {
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   619
			STR_303E_NO_LONGER_ACCEPTS,
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   620
			STR_303F_NO_LONGER_ACCEPTS_OR,
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   621
		};
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   622
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   623
		/* Array of accepted and rejected cargo types */
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   624
		CargoID accepts[2] = { CT_INVALID, CT_INVALID };
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   625
		CargoID rejects[2] = { CT_INVALID, CT_INVALID };
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   626
		uint num_acc = 0;
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   627
		uint num_rej = 0;
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   628
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   629
		/* Test each cargo type to see if its acceptange has changed */
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   630
		for (CargoID i = 0; i < NUM_CARGO; i++) {
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   631
			if (HASBIT(new_acc, i)) {
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   632
				if (!HASBIT(old_acc, i) && num_acc < lengthof(accepts)) {
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   633
					/* New cargo is accepted */
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   634
					accepts[num_acc++] = i;
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   635
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
			} else {
5690
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   637
				if (HASBIT(old_acc, i) && num_rej < lengthof(rejects)) {
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   638
					/* Old cargo is no longer accepted */
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   639
					rejects[num_rej++] = i;
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   640
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
			}
5690
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   642
		}
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   643
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   644
		/* Show news message if there are any changes */
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   645
		if (num_acc > 0) ShowRejectOrAcceptNews(st, num_acc, accepts, accept_msg[num_acc - 1]);
2f290fd103cd (svn r8153) -Codechange: Change UpdateStationAcceptance() and ShowRejectOrAcceptNews() to work with cargo IDs instead of cargo names, and explicitly list the different strings to use.
peter1138
parents: 5683
diff changeset
   646
		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
   647
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	// redraw the station view since acceptance changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
5098
7de23befaee4 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   653
static void UpdateStationSignCoord(Station *st)
7de23befaee4 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   654
{
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
   655
	StationRect *r = &st->rect;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
   656
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
   657
	if (r->IsEmpty()) return; // no tiles belong to this station
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
   658
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
   659
	// clamp sign coord to be inside the station rect
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
   660
	st->xy = TileXY(clampu(TileX(st->xy), r->left, r->right), clampu(TileY(st->xy), r->top, r->bottom));
5098
7de23befaee4 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   661
	UpdateStationVirtCoordDirty(st);
7de23befaee4 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   662
}
7de23befaee4 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   663
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
// This is called right after a station was deleted.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
// It checks if the whole station is free of substations, and if so, the station will be
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
// deleted after a little while.
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   667
static void DeleteStationIfEmpty(Station* st)
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   668
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
	if (st->facilities == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
		st->delete_ctr = 0;
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
   671
		RebuildStationLists();
28
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   672
		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
   673
	}
5098
7de23befaee4 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   674
	/* station remains but it probably lost some parts - station sign should stay in the station boundaries */
7de23befaee4 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
   675
	UpdateStationSignCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   678
static int32 ClearTile_Station(TileIndex tile, byte flags);
977
ab88e042b39d (svn r1472) -Fix: correct error message for when trying to build a railroad station over a bus/truck/etc-station.
darkvater
parents: 972
diff changeset
   679
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
// Tries to clear the given area. Returns the cost in case of success.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
// Or an error code if it failed.
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   682
int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
	int32 cost = 0, ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   686
	Slope tileh;
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1328
diff changeset
   687
	uint z;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1328
diff changeset
   688
	int allowed_z = -1;
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1328
diff changeset
   689
	int flat_z;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
	BEGIN_TILE_LOOP(tile_cur, w, h, tile)
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   692
		if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) {
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   693
			return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   694
		}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5380
diff changeset
   695
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   696
		if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
		tileh = GetTileSlope(tile_cur, &z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
2085
876f20a0e843 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2049
diff changeset
   700
		/* Prohibit building if
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   701
		 *   1) The tile is "steep" (i.e. stretches two height levels)
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   702
		 * -OR-
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   703
		 *   2) The tile is non-flat if
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   704
		 *     a) the player building is an "old-school" AI
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   705
		 *   -OR-
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   706
		 *     b) the build_on_slopes switch is disabled
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
   707
		 */
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   708
		if (IsSteepSlope(tileh) ||
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   709
				((_is_old_ai_player || !_patches.build_on_slopes) && tileh != SLOPE_FLAT)) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   710
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
		flat_z = z;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   714
		if (tileh != SLOPE_FLAT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
			// need to check so the entrance to the station is not pointing at a slope.
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   716
			if ((invalid_dirs&1 && !(tileh & SLOPE_NE) && (uint)w_cur == w) ||
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4399
diff changeset
   717
					(invalid_dirs&2 && !(tileh & SLOPE_SE) && h_cur == 1) ||
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   718
					(invalid_dirs&4 && !(tileh & SLOPE_SW) && w_cur == 1) ||
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
   719
					(invalid_dirs&8 && !(tileh & SLOPE_NW) && (uint)h_cur == h)) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   720
				return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
			cost += _price.terraform;
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   723
			flat_z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   725
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
		// get corresponding flat level and make sure that all parts of the station have the same level.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
		if (allowed_z == -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
			// first tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
			allowed_z = flat_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
		} else if (allowed_z != flat_z) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   731
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   734
		// if station is set, then we have special handling to allow building on top of already existing stations.
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   735
		// so station points to INVALID_STATION if we can build on any station. or it points to a station if we're only allowed to build
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
		// on exactly that station.
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1032
diff changeset
   737
		if (station != NULL && IsTileType(tile_cur, MP_STATION)) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
   738
			if (!IsRailwayStation(tile_cur)) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   739
				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
   740
			} else {
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
   741
				StationID st = GetStationIndex(tile_cur);
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   742
				if (*station == INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
					*station = st;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   744
				} else if (*station != st) {
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   745
					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
   746
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
		} else {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
   749
			ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   750
			if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
			cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
	END_TILE_LOOP(tile_cur, w, h, tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
	return cost;
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
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   758
static bool CanExpandRailroadStation(Station* st, uint* fin, Axis axis)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
	uint curw = st->trainst_w, curh = st->trainst_h;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   761
	TileIndex tile = fin[0];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
	uint w = fin[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	uint h = fin[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
	if (_patches.nonuniform_stations) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
		// determine new size of train station region..
926
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   767
		int x = min(TileX(st->train_tile), TileX(tile));
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   768
		int y = min(TileY(st->train_tile), TileY(tile));
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   769
		curw = max(TileX(st->train_tile) + curw, TileX(tile) + w) - x;
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   770
		curh = max(TileY(st->train_tile) + curh, TileY(tile) + h) - y;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   771
		tile = TileXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	} else {
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   773
		// check so the orientation is the same
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
   774
		if (GetRailStationAxis(st->train_tile) != axis) {
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   775
			_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED;
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   776
			return false;
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   777
		}
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
		// check if the new station adjoins the old station in either direction
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   780
		if (curw == w && st->train_tile == tile + TileDiffXY(0, h)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
			// above
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
			curh += h;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   783
		} else if (curw == w && st->train_tile == tile - TileDiffXY(0, curh)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
			// below
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   785
			tile -= TileDiffXY(0, curh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
			curh += h;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   787
		} else if (curh == h && st->train_tile == tile + TileDiffXY(w, 0)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
			// to the left
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
			curw += w;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   790
		} else if (curh == h && st->train_tile == tile - TileDiffXY(curw, 0)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
			// to the right
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   792
			tile -= TileDiffXY(curw, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
			curw += w;
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   794
		} else {
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   795
			_error_message = STR_306D_NONUNIFORM_STATIONS_DISALLOWED;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
			return false;
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   797
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
	// make sure the final size is not too big.
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   800
	if (curw > _patches.station_spread || curh > _patches.station_spread) {
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   801
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   802
		return false;
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   803
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
	// now tile contains the new value for st->train_tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
	// curw, curh contain the new value for width and height
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
	fin[0] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	fin[1] = curw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
	fin[2] = curh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
536
03d80fecb999 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   813
static inline byte *CreateSingle(byte *layout, int n)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	do *layout++ = 0; while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
	layout[((n-1) >> 1)-n] = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
536
03d80fecb999 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   821
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
   822
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	do *layout++ = b; while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	if (n > 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
		layout[0-n] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
		layout[n-1-n] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   832
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
   833
{
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   834
	if (statspec != NULL && statspec->lengths >= plat_len &&
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   835
			statspec->platforms[plat_len - 1] >= numtracks &&
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   836
			statspec->layouts[plat_len - 1][numtracks - 1]) {
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   837
		/* Custom layout defined, follow it. */
3676
680dfa6336a1 (svn r4593) CodeChange : Renamed spec (when using StationSpec) to statspec.
belugas
parents: 3657
diff changeset
   838
		memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1],
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
   839
			plat_len * numtracks);
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   840
		return;
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   841
	}
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   842
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
	if (plat_len == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
		CreateSingle(layout, numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	} else {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   846
		if (numtracks & 1) layout = CreateSingle(layout, plat_len);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   847
		numtracks >>= 1;
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
		while (--numtracks >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
			layout = CreateMulti(layout, plat_len, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
			layout = CreateMulti(layout, plat_len, 6);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   856
/** Build railroad station
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
   857
 * @param tile_org starting position of station dragging/placement
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   858
 * @param p1 various bitstuffed elements
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   859
 * - p1 = (bit  0)    - orientation (p1 & 1)
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   860
 * - p1 = (bit  8-15) - number of tracks
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   861
 * - p1 = (bit 16-23) - platform length
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   862
 * @param p2 various bitstuffed elements
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   863
 * - p2 = (bit  0- 3) - railtype (p2 & 0xF)
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   864
 * - p2 = (bit  8-15) - custom station class
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   865
 * - p2 = (bit 16-23) - custom station id
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
   867
int32 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
   868
{
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   869
	Station *st;
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   870
	int w_org, h_org;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
	int32 cost, ret;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   872
	StationID est;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
	int plat_len, numtracks;
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   874
	Axis axis;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
	uint finalvalues[3];
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   876
	const StationSpec *statspec;
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   877
	int specindex;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
	/* Does the authority allow this? */
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   882
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   883
	if (!ValParamRailtype(p2 & 0xF)) return CMD_ERROR;
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   884
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   885
	/* unpack parameters */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   886
	axis = (Axis)(p1 & 1);
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   887
	numtracks = GB(p1,  8, 8);
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
   888
	plat_len  = GB(p1, 16, 8);
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   889
	/* w = length, h = num_tracks */
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   890
	if (axis == AXIS_X) {
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   891
		w_org = plat_len;
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   892
		h_org = numtracks;
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   893
	} else {
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   894
		h_org = plat_len;
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
   895
		w_org = numtracks;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
1781
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   898
	if (h_org > _patches.station_spread || w_org > _patches.station_spread) return CMD_ERROR;
5e2fef482637 (svn r2285) - Codechange: Fix up some of the missing things from server-checking; namely bridge-type, bridge-length, dragged end-tile (bridge/station), station_spread
Darkvater
parents: 1775
diff changeset
   899
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	// these values are those that will be stored in train_tile and station_platforms
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	finalvalues[0] = tile_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
	finalvalues[1] = w_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
	finalvalues[2] = h_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station)
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
   906
	est = INVALID_STATION;
313
0c7cac001d1a (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   907
	// If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
0c7cac001d1a (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   908
	//  for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   909
	ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   910
	if (CmdFailed(ret)) return ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
	cost = ret + (numtracks * _price.train_station_track + _price.train_station_length) * plat_len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
	// Make sure there are no similar stations around us.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	st = GetStationAround(tile_org, w_org, h_org, est);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
	// See if there is a deleted station close to us.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
		st = GetClosestStationFromTile(tile_org, 8, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
		if (st != NULL && st->facilities) st = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   923
	/* In case of new station if DC_EXEC is NOT set we still need to create the station
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   924
	 * to test if everything is OK. In this case we need to delete it before return. */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
   925
	AutoPtrT<Station> st_auto_delete;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   926
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	if (st != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
		// Reuse an existing station.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
		if (st->owner != OWNER_NONE && st->owner != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
			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
   931
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
		if (st->train_tile != 0) {
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 71
diff changeset
   933
			// check if we want to expanding an already existing station?
2422
897a01f7c624 (svn r2948) -Fix: the old AI needs a special flag that triggers all kind of special
truelight
parents: 2395
diff changeset
   934
			if (_is_old_ai_player || !_patches.join_stations)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
				return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD);
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
   936
			if (!CanExpandRailroadStation(st, finalvalues, axis))
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   937
				return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
1189
257509152c47 (svn r1693) -Fix: [ 1108618 ] A wrong error message was displayed when trying to
Celestar
parents: 1174
diff changeset
   940
		//XXX can't we pack this in the "else" part of the if above?
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
   941
		if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR;
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4399
diff changeset
   942
	} else {
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   943
		/* allocate and initialize new station */
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   944
		st = new Station(tile_org);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   945
		if (st == NULL) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   946
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   947
		/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
   948
		st_auto_delete = st;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   949
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
		st->town = ClosestTownFromTile(tile_org, (uint)-1);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   951
		if (!GenerateStationName(st, tile_org, 0)) return CMD_ERROR;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   952
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   953
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
			SETBIT(st->town->have_ratings, _current_player);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
   955
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   958
	/* Check if the given station class is valid */
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   959
	if (GB(p2, 8, 8) >= STAT_CLASS_MAX) return CMD_ERROR;
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   960
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   961
	/* Check if we can allocate a custom stationspec to this station */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   962
	statspec = GetCustomStationSpec((StationClassID)GB(p2, 8, 8), GB(p2, 16, 8));
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   963
	specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC);
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   964
	if (specindex == -1) return CMD_ERROR;
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
   965
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   966
	if (statspec != NULL) {
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   967
		/* Perform NewStation checks */
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   968
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   969
		/* Check if the station size is permitted */
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   970
		if (HASBIT(statspec->disallowed_platforms, numtracks - 1) || HASBIT(statspec->disallowed_lengths, plat_len - 1)) {
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   971
			return CMD_ERROR;
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   972
		}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   973
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   974
		/* Check if the station is buildable */
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   975
		if (HASBIT(statspec->callbackmask, CBM_STATION_AVAIL) && GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) {
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   976
			return CMD_ERROR;
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   977
		}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   978
	}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
   979
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	if (flags & DC_EXEC) {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
   981
		TileIndexDiff tile_delta;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
		byte *layout_ptr;
3769
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
   983
		byte numtracks_orig;
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
   984
		Track track;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
313
0c7cac001d1a (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   986
		// Now really clear the land below the station
0c7cac001d1a (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   987
		// It should never return CMD_ERROR.. but you never know ;)
0c7cac001d1a (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   988
		//  (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags)
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   989
		ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _patches.nonuniform_stations ? &est : NULL);
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
   990
		if (CmdFailed(ret)) return ret;
313
0c7cac001d1a (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   991
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
		st->train_tile = finalvalues[0];
5721
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   993
		st->AddFacility(FACIL_TRAIN, finalvalues[0]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
		st->trainst_w = finalvalues[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
		st->trainst_h = finalvalues[2];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   997
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
   998
		st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
   999
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
  1000
		tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
  1001
		track = AxisToTrack(axis);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1002
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1003
		layout_ptr = (byte*)alloca(numtracks * plat_len);
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1004
		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
  1005
3769
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1006
		numtracks_orig = numtracks;
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1007
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
		do {
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1774
diff changeset
  1009
			TileIndex tile = tile_org;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
			int w = plat_len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
			do {
3769
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1012
				byte layout = *layout_ptr++;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1013
				MakeRailStation(tile, st->owner, st->index, axis, layout, (RailType)GB(p2, 0, 4));
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1014
				SetCustomStationSpecIndex(tile, specindex);
3742
c5ef7a92daa5 (svn r4724) - Newstations: Add per-tile random data for station tiles.
peter1138
parents: 3741
diff changeset
  1015
				SetStationTileRandomBits(tile, GB(Random(), 0, 4));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1017
				if (statspec != NULL) {
3784
213a1a3f8697 (svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents: 3775
diff changeset
  1018
					/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
213a1a3f8697 (svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents: 3775
diff changeset
  1019
					uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false);
3769
7d3b35126fc1 (svn r4761) - Newstations: support platform information in variable 10 (callback parameter 1) when building a station
peter1138
parents: 3766
diff changeset
  1020
					uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, st, tile);
3784
213a1a3f8697 (svn r4780) - Newstations: when building using a dynamic layout, add the station axis to the returned tile type. Also supply correct parameters to var 10.
peter1138
parents: 3775
diff changeset
  1021
					if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, callback + axis);
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1022
				}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  1023
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
				tile += tile_delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
			} while (--w);
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1026
			SetSignalsOnBothDir(tile_org, track);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1027
			YapfNotifyTrackLayoutChange(tile_org, track);
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1028
			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
  1029
		} while (--numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1031
		st->MarkTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
		UpdateStationAcceptance(st, false);
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1034
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
		InvalidateWindow(WC_STATION_LIST, st->owner);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1036
		/* success, so don't delete the new station */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1037
		st_auto_delete.Release();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
static void MakeRailwayStationAreaSmaller(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	uint w = st->trainst_w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
	uint h = st->trainst_h;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1047
	TileIndex tile = st->train_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
	uint i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
restart:
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1051
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
	// too small?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
	if (w != 0 && h != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
		// check the left side, x = constant, y changes
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1055
		for (i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(0, i));) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
			// the left side is unused?
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1057
			if (++i == h) {
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1058
				tile += TileDiffXY(1, 0);
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1059
				w--;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1060
				goto restart;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1061
			}
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1062
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
		// check the right side, x = constant, y changes
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1065
		for (i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(w - 1, i));) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
			// the right side is unused?
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1067
			if (++i == h) {
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1068
				w--;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1069
				goto restart;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1070
			}
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1071
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
		// check the upper side, y = constant, x changes
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1074
		for (i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, 0));) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
			// the left side is unused?
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1076
			if (++i == w) {
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1077
				tile += TileDiffXY(0, 1);
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1078
				h--;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1079
				goto restart;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1080
			}
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1081
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
		// check the lower side, y = constant, x changes
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1084
		for (i = 0; !st->TileBelongsToRailStation(tile + TileDiffXY(i, h - 1));) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
			// the left side is unused?
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1086
			if (++i == w) {
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1087
				h--;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1088
				goto restart;
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1089
			}
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1090
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
		tile = 0;
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
	st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
	st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
	st->train_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1100
/** Remove a single tile from a railroad station.
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1101
 * This allows for custom-built station with holes and weird layouts
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1102
 * @param tile tile of station piece to remove
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1103
 * @param p1 unused
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1104
 * @param p2 unused
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1105
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1106
int32 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
  1107
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
889
64d2f7d5f02b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
  1110
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
64d2f7d5f02b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
  1111
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	// make sure the specified tile belongs to the current player, and that it is a railroad station.
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1113
	if (!IsTileType(tile, MP_STATION) || !IsRailwayStation(tile) || !_patches.nonuniform_stations) return CMD_ERROR;
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  1114
	st = GetStationByTile(tile);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1115
	if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	// if we reached here, it means we can actually delete it. do that.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
	if (flags & DC_EXEC) {
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1119
		uint specindex = GetCustomStationSpecIndex(tile);
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1120
		Track track = GetRailStationTrack(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
		DoClearSquare(tile);
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1122
		st->rect.AfterRemoveTile(st, tile);
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1123
		SetSignalsOnBothDir(tile, track);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1124
		YapfNotifyTrackLayoutChange(tile, track);
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1125
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1126
		DeallocateSpecFromStation(st, specindex);
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1127
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
		// now we need to make the "spanned" area of the railway station smaller if we deleted something at the edges.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
		// we also need to adjust train_tile.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
		MakeRailwayStationAreaSmaller(st);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1131
		st->MarkTilesDirty();
5098
7de23befaee4 (svn r7169) -Fix: [FS#388] Station sign (and base station coordinates) didn't move along with station when station moved by walking. (HMage)
KUDr
parents: 4982
diff changeset
  1132
		UpdateStationSignCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
		// if we deleted the whole station, delete the train facility.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
		if (st->train_tile == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
			st->facilities &= ~FACIL_TRAIN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
			UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
			DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	return _price.remove_rail_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
3928
53fe96558353 (svn r5063) -Codechange: Add a function to determine the length of a platform (request by KUDr)
celestar
parents: 3900
diff changeset
  1144
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1145
static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	int w,h;
5362
1a3af9aa3697 (svn r7547) -Fix: The cost of rail station removal was calculated based on the area occupied by the station. This produced unreasonably large removal costs for non-uniform stations. Now it is based on number of station tiles actually removed.
KUDr
parents: 5247
diff changeset
  1148
	int32 cost = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1150
	/* 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
  1151
	if (_current_player == OWNER_WATER && _patches.nonuniform_stations)
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1152
		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
  1153
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	/* Current player owns the station? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
	/* determine width and height of platforms */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
	tile = st->train_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
	w = st->trainst_w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
	h = st->trainst_h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1162
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	assert(w != 0 && h != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	/* clear all areas of the station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
		int w_bak = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
			// for nonuniform stations, only remove tiles that are actually train station tiles
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1170
			if (st->TileBelongsToRailStation(tile)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
				if (!EnsureNoVehicle(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
					return CMD_ERROR;
5362
1a3af9aa3697 (svn r7547) -Fix: The cost of rail station removal was calculated based on the area occupied by the station. This produced unreasonably large removal costs for non-uniform stations. Now it is based on number of station tiles actually removed.
KUDr
parents: 5247
diff changeset
  1173
				cost += _price.remove_rail_station;
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1174
				if (flags & DC_EXEC) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1175
					Track track = GetRailStationTrack(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
					DoClearSquare(tile);
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1177
					SetSignalsOnBothDir(tile, track);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1178
					YapfNotifyTrackLayoutChange(tile, track);
2824
4409cab99b02 (svn r3372) - Fix: update signal states when building or removing rail station blocks
peter1138
parents: 2817
diff changeset
  1179
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
			}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1181
			tile += TileDiffXY(1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
		} while (--w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
		w = w_bak;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1184
		tile += TileDiffXY(-w, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
	} while (--h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
	if (flags & DC_EXEC) {
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1188
		st->rect.AfterRemoveRect(st, st->train_tile, st->trainst_w, st->trainst_h);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  1189
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
		st->train_tile = 0;
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  1191
		st->trainst_w = st->trainst_h = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
		st->facilities &= ~FACIL_TRAIN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
3587
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1194
		free(st->speclist);
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1195
		st->num_specs = 0;
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1196
		st->speclist  = NULL;
c434d5c3dcaa (svn r4473) - Newstations:
peter1138
parents: 3585
diff changeset
  1197
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1201
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
3435
dfba5b1c7c2d (svn r4265) - Fix: compile warning on VS2005 (parameter 2 different from declaration)
Darkvater
parents: 3431
diff changeset
  1205
int32 DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
{
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  1207
	const Station* st = GetStationByTile(tile);
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  1208
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
	// tile is not a railroad station?
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1212
	if (!IsRailwayStation(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3222
diff changeset
  1214
	if (GetRailType(tile) == totype) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
5116
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5103
diff changeset
  1216
	// 'hidden' elrails can't be downgraded to normal rail when elrails are disabled
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5103
diff changeset
  1217
	if (_patches.disable_elrails && totype == RAILTYPE_RAIL && GetRailType(tile) == RAILTYPE_ELECTRIC) return CMD_ERROR;
3c0c3da214ca (svn r7195) -Feature: [FS#297, optional elrails] New patches/vehicles option 'disable electrified railways'.
KUDr
parents: 5103
diff changeset
  1218
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	if (exec) {
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3222
diff changeset
  1220
		SetRailType(tile, totype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
		MarkTileDirtyByTile(tile);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  1222
		YapfNotifyTrackLayoutChange(tile, GetRailStationTrack(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	return _price.build_rail >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1228
/**
5836
a60d2114780e (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: 5834
diff changeset
  1229
 * @param[in] truck_station Determines whether a stop is RoadStop::BUS or RoadStop::TRUCK
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
  1230
 * @param[in] station The station to do the whole procedure for
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1231
 * @return a pointer to where to link a new RoadStop*
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4528
diff changeset
  1232
 */
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1233
static RoadStop **FindRoadStopSpot(bool truck_station, Station* st)
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1234
{
3691
56dfcf599c3f (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1235
	RoadStop **primary_stop = (truck_station) ? &st->truck_stops : &st->bus_stops;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1236
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1237
	if (*primary_stop == NULL) {
3691
56dfcf599c3f (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1238
		//we have no roadstop of the type yet, so write a "primary stop"
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1239
		return primary_stop;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1240
	} else {
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1241
		//there are stops already, so append to the end of the list
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1242
		RoadStop *stop = *primary_stop;
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1243
		while (stop->next != NULL) stop = stop->next;
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1244
		return &stop->next;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1245
	}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1246
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1247
3691
56dfcf599c3f (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1248
/** Build a bus or truck stop
56dfcf599c3f (svn r4619) -Codechange: Rename FindRoadStationSpot into FindRoadStopSpot and try to document it a little.
celestar
parents: 3687
diff changeset
  1249
 * @param tile tile to build the stop at
3333
5feb21487332 (svn r4111) Fix/Remove some stale comments
tron
parents: 3315
diff changeset
  1250
 * @param p1 entrance direction (DiagDirection)
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1251
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1252
 *           bit 1: 0 for normal, 1 for drive-through
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1254
int32 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
  1255
{
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1256
	Station *st;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1257
	RoadStop *road_stop;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
	int32 cost;
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1259
	int32 ret;
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1260
	bool type = HASBIT(p2, 0);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1261
	bool is_drive_through = HASBIT(p2, 1);
6018
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1262
	bool build_over_road  = is_drive_through && IsTileType(tile, MP_STREET) && GetRoadTileType(tile) == ROAD_TILE_NORMAL;
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1263
	Owner cur_owner = _current_player;
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1264
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1781
diff changeset
  1265
	/* Saveguard the parameters */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1266
	if (!IsValidDiagDirection((DiagDirection)p1)) return CMD_ERROR;
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1267
	/* If it is a drive-through stop check for valid axis */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1268
	if (is_drive_through && !IsValidAxis((Axis)p1)) return CMD_ERROR;
6018
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1269
	/* Road bits in the wrong direction */
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1270
	if (build_over_road && (GetRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return CMD_ERROR;
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1271
	/* Not allowed to build over this road */
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1272
	if (build_over_road && !IsTileOwner(tile, _current_player) && !(IsTileOwner(tile, OWNER_TOWN) && _patches.road_stop_on_town_road)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
6018
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1279
	if (build_over_road && IsTileOwner(tile, OWNER_TOWN)) _current_player = OWNER_TOWN;
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1280
	ret = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1281
	_current_player = cur_owner;
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1282
	if (CmdFailed(ret)) return ret;
6018
5d143f68ac94 (svn r8741) -Fix (r8735): make the saveguards of CmdBuildRoadStop more robust and add roadstops.grf to the list of required grfs.
rubidium
parents: 6012
diff changeset
  1283
	cost = build_over_road ? 0 : ret; // Don't add cost of clearing road when overbuilding
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1285
	st = GetStationAround(tile, 1, 1, INVALID_STATION);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1286
	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
	/* Find a station close to us */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
		st = GetClosestStationFromTile(tile, 8, _current_player);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  1291
		if (st != NULL && st->facilities != 0) st = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1294
	//give us a road stop in the list, and check if something went wrong
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5709
diff changeset
  1295
	road_stop = new RoadStop(tile);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1296
	if (road_stop == NULL) {
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1297
		return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1298
	}
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1299
5833
a0abc408c0bb (svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents: 5721
diff changeset
  1300
	/* ensure that in case of error (or no DC_EXEC) the new road stop gets deleted upon return */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1301
	AutoPtrT<RoadStop> rs_auto_delete(road_stop);
5833
a0abc408c0bb (svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents: 5721
diff changeset
  1302
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  1303
	if (st != NULL &&
5837
e9c21cf7c7d9 (svn r8403) -Fix (r8402): Forgot to remove an enum
celestar
parents: 5836
diff changeset
  1304
			GetNumRoadStopsInStation(st, RoadStop::BUS) + GetNumRoadStopsInStation(st, RoadStop::TRUCK) >= RoadStop::LIMIT) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1305
		return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1306
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1307
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1308
	/* In case of new station if DC_EXEC is NOT set we still need to create the station
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1309
	* to test if everything is OK. In this case we need to delete it before return. */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1310
	AutoPtrT<Station> st_auto_delete;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1311
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
	if (st != NULL) {
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1313
		if (st->owner != OWNER_NONE && st->owner != _current_player) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1315
		}
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1316
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1317
		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
  1318
	} else {
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1319
		/* allocate and initialize new station */
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1320
		st = new Station(tile);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1321
		if (st == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1323
		/* ensure that in case of error (or no DC_EXEC) the new station gets deleted upon return */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1324
		st_auto_delete = st;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1325
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1326
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1327
		Town *t = st->town = ClosestTownFromTile(tile, (uint)-1);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1328
		if (!GenerateStationName(st, tile, 0)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1330
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
			SETBIT(t->have_ratings, _current_player);
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1332
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1337
	cost += (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
  1338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
	if (flags & DC_EXEC) {
5906
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1340
		// Insert into linked list of RoadStops
d743f61aba80 (svn r8531) -Fix
tron
parents: 5905
diff changeset
  1341
		RoadStop **currstop = FindRoadStopSpot(type, st);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1342
		*currstop = road_stop;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1343
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1344
		//initialize an empty station
5721
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
  1345
		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
  1346
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1347
		st->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  1348
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1349
		MakeRoadStop(tile, st->owner, st->index, type ? RoadStop::TRUCK : RoadStop::BUS, is_drive_through, (DiagDirection)p1);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1350
		if (is_drive_through & HASBIT(p2, 3)) SetStopBuiltOnTownRoad(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
		UpdateStationAcceptance(st, false);
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1354
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
		InvalidateWindow(WC_STATION_LIST, st->owner);
5833
a0abc408c0bb (svn r8399) -Fix (r8185): a new road stop was always created in CmdBuildRoadStop(), but it was not deleted if DC_EXEC flag was not set or if the station creation failed
glx
parents: 5721
diff changeset
  1356
		/* success, so don't delete the new station and the new road stop */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1357
		st_auto_delete.Release();
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1358
		rs_auto_delete.Release();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
// Remove a bus station
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1364
static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
{
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1366
	RoadStop **primary_stop;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1367
	RoadStop *cur_stop;
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1368
	bool is_truck = IsTruckStop(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1370
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
		return CMD_ERROR;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1372
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1374
	if (is_truck) { // truck stop
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1375
		primary_stop = &st->truck_stops;
5836
a60d2114780e (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: 5834
diff changeset
  1376
		cur_stop = GetRoadStopByTile(tile, RoadStop::TRUCK);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1377
	} else {
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1378
		primary_stop = &st->bus_stops;
5836
a60d2114780e (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: 5834
diff changeset
  1379
		cur_stop = GetRoadStopByTile(tile, RoadStop::BUS);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1380
	}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1381
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1382
	assert(cur_stop != NULL);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1383
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2916
diff changeset
  1384
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
	if (flags & DC_EXEC) {
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1387
		if (*primary_stop == cur_stop) {
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1388
			// removed the first stop in the list
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1389
			*primary_stop = cur_stop->next;
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1390
			// removed the only stop?
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1391
			if (*primary_stop == NULL) {
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1392
				st->facilities &= (is_truck ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP);
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1393
			}
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1394
		} else {
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1395
			// tell the predecessor in the list to skip this stop
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1396
			RoadStop *pred = *primary_stop;
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1397
			while (pred->next != cur_stop) pred = pred->next;
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  1398
			pred->next = cur_stop->next;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1399
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5697
diff changeset
  1401
		delete cur_stop;
4398
9232bcc7422a (svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents: 4397
diff changeset
  1402
		DoClearSquare(tile);
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1403
		st->rect.AfterRemoveTile(st, tile);
4398
9232bcc7422a (svn r6151) -Codechange: DeleteStation/DeleteRoadStop removes a station/RoadStop from the pool
truelight
parents: 4397
diff changeset
  1404
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  1409
	return (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
  1410
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1412
/** Remove a bus or truck stop
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1413
 * @param tile tile to remove the stop from
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1414
 * @param p1 not used
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1415
 * @param p2 bit 0: 0 for Bus stops, 1 for truck stops
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1416
 */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1417
int32 CmdRemoveRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1418
{
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1419
	Station* st;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1420
	bool is_drive_through;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1421
	bool is_towns_road = false;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1422
	RoadBits road_bits;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1423
	int32 ret;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1424
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1425
	/* Make sure the specified tile is a road stop of the correct type */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1426
	if (!IsTileType(tile, MP_STATION) || !IsRoadStop(tile) || (uint32)GetRoadStopType(tile) != p2) return CMD_ERROR;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1427
	st = GetStationByTile(tile);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1428
	/* Save the stop info before it is removed */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1429
	is_drive_through = IsDriveThroughStopTile(tile);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1430
	road_bits = GetAnyRoadBits(tile);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1431
	if (is_drive_through) is_towns_road = GetStopBuiltOnTownRoad(tile);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1432
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1433
	ret = RemoveRoadStop(st, flags, tile);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1434
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1435
	/* If the stop was a drive-through stop replace the road */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1436
	if ((flags & DC_EXEC) && !CmdFailed(ret) && is_drive_through) {
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1437
		uint index = 0;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1438
		Owner cur_owner = _current_player;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1439
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1440
		if (is_towns_road) {
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1441
			index = ClosestTownFromTile(tile, _patches.dist_local_authority)->index;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1442
			_current_player = OWNER_TOWN;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1443
		}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1444
		DoCommand(tile, road_bits, index, DC_EXEC, CMD_BUILD_ROAD);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1445
		_current_player = cur_owner;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1446
	}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1447
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1448
	return ret;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  1449
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
// FIXME -- need to move to its corresponding Airport variable
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
// Country Airfield (small)
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1453
static const byte _airport_sections_country[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
	54, 53, 52, 65,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
	58, 57, 56, 55,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
	64, 63, 63, 62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
// City Airport (large)
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1460
static const byte _airport_sections_town[] = {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1461
	31,  9, 33,  9,  9, 32,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1462
	27, 36, 29, 34,  8, 10,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	30, 11, 35, 13, 20, 21,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
	51, 12, 14, 17, 19, 28,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
	38, 13, 15, 16, 18, 39,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
	26, 22, 23, 24, 25, 26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
// Metropolitain Airport (large) - 2 runways
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1470
static const byte _airport_sections_metropolitan[] = {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1471
	 31,  9, 33,  9,  9, 32,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1472
	 27, 36, 29, 34,  8, 10,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1473
	 30, 11, 35, 13, 20, 21,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1474
	102,  8,  8,  8,  8, 28,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1475
	 83, 84, 84, 84, 84, 83,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1476
	 26, 23, 23, 23, 23, 26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
// International Airport (large) - 2 runways
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1480
static const byte _airport_sections_international[] = {
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  1481
	88, 89, 89, 89, 89, 89,  88,
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  1482
	51,  8,  8,  8,  8,  8,  32,
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1483
	30,  8, 11, 27, 11,  8,  10,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
	32,  8, 11, 27, 11,  8, 114,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
	87,  8, 11, 85, 11,  8, 114,
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1486
	87,  8,  8,  8,  8,  8,  90,
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1487
	26, 23, 23, 23, 23, 23,  26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1490
// Intercontinental Airport (vlarge) - 4 runways
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1491
static const byte _airport_sections_intercontinental[] = {
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1492
	102, 120,  89,  89,  89,  89,  89,  89, 118,
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1493
	120,  22,  22,  22,  22,  22,  22, 119, 117,
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1494
	 87,  54,  87,   8,   8,   8,   8,  51, 117,
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1495
	 87, 162,  87,  85, 116, 116,   8,   9,  10,
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1496
	 87,   8,   8,  11,  31,  11,   8, 160,  32,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1497
	 32, 160,   8,  11,  27,  11,   8,   8,  10,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1498
	 87,   8,   8,  11,  30,  11,   8,   8,  10,
4066
2d099b946f10 (svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents: 4059
diff changeset
  1499
	 87, 142,   8,  11,  29,  11,  10, 163,  10,
2d099b946f10 (svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents: 4059
diff changeset
  1500
	 87, 164,  87,   8,   8,   8,  10,  37, 117,
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1501
	 87, 120,  89,  89,  89,  89,  89,  89, 119,
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  1502
	121,  22,  22,  22,  22,  22,  22, 119,  37
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1503
};
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1504
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1505
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1506
// Commuter Airfield (small)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1507
static const byte _airport_sections_commuter[] = {
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1508
	85, 30, 115, 115, 32,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1509
	87, 8,    8,   8, 10,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1510
	87, 11,  11,  11, 10,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1511
	26, 23,  23,  23, 26
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1512
};
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1513
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
// Heliport
3429
20b7bab277c1 (svn r4257) -Codechange: Renamed the airport_map5_tiles_* variables into airport_sections_*
celestar
parents: 3422
diff changeset
  1515
static const byte _airport_sections_heliport[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
	66,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1519
// Helidepot
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1520
static const byte _airport_sections_helidepot[] = {
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1521
	124, 32,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1522
	122, 123
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1523
};
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1524
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1525
// Helistation
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1526
static const byte _airport_sections_helistation[] = {
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1527
	 32, 134, 159, 158,
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1528
	161, 142, 142, 157
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1529
};
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1530
3471
e454e2c0c23e (svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents: 3435
diff changeset
  1531
static const byte * const _airport_sections[] = {
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1532
	_airport_sections_country,           // Country Airfield (small)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1533
	_airport_sections_town,              // City Airport (large)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1534
	_airport_sections_heliport,          // Heliport
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1535
	_airport_sections_metropolitan,      // Metropolitain Airport (large)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1536
	_airport_sections_international,     // International Airport (xlarge)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1537
	_airport_sections_commuter,          // Commuter Airport (small)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1538
	_airport_sections_helidepot,         // Helidepot
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1539
	_airport_sections_intercontinental,  // Intercontinental Airport (xxlarge)
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1540
	_airport_sections_helistation        // Helistation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1543
/** Place an Airport.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1544
 * @param tile tile where airport will be built
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1545
 * @param p1 airport type, @see airport.h
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1546
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1548
int32 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
  1549
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
	int32 cost;
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1553
	int32 ret;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1554
	int w, h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1555
	bool airport_upgrade = true;
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
  1556
	const AirportFTAClass* afc;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1560
	/* Check if a valid, buildable airport was chosen for construction */
3471
e454e2c0c23e (svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents: 3435
diff changeset
  1561
	if (p1 > lengthof(_airport_sections) || !HASBIT(GetValidAirports(), p1)) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1562
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
	t = ClosestTownFromTile(tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
	/* Check if local auth refuses a new airport */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
		uint num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
		FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1572
			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
  1573
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
		if (num >= 2) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1576
			SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
			return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
  1581
	afc = GetAirport(p1);
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
  1582
	w = afc->size_x;
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
  1583
	h = afc->size_y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
3183
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1585
	ret = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1586
	if (CmdFailed(ret)) return ret;
90c676e6a50d (svn r3829) Reduce the use of _error_message by directly returning error codes instead of using this global variable
tron
parents: 3161
diff changeset
  1587
	cost = ret;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1589
	st = GetStationAround(tile, w, h, INVALID_STATION);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1590
	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
	/* Find a station close to us */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1594
		st = GetClosestStationFromTile(tile, 8, _current_player);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1595
		if (st != NULL && st->facilities) st = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
5513
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1598
	if (w > _patches.station_spread || h > _patches.station_spread) {
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1599
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1600
		return CMD_ERROR;
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1601
	}
1ccea4948917 (svn r7810) -Fix: FS#504 Building airport whose size exceeds max station spread-out caused assert. (Zuu)
KUDr
parents: 5475
diff changeset
  1602
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1603
	/* In case of new station if DC_EXEC is NOT set we still need to create the station
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1604
	 * to test if everything is OK. In this case we need to delete it before return. */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1605
	AutoPtrT<Station> st_auto_delete;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1606
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
	if (st != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
		if (st->owner != OWNER_NONE && st->owner != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
			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
  1610
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1611
		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
  1612
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
		if (st->airport_tile != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1614
			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
  1615
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1616
		airport_upgrade = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1618
		/* allocate and initialize new station */
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1619
		st = new Station(tile);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1620
		if (st == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1622
		/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1623
		st_auto_delete = st;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1624
1265
71ed55c20f6e (svn r1769) Don't compute the same value twice, remove one function call
tron
parents: 1247
diff changeset
  1625
		st->town = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1627
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
			SETBIT(t->have_ratings, _current_player);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1629
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
		// if airport type equals Heliport then generate
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
		// type 5 name, which is heliport, otherwise airport names (1)
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  1635
		if (!GenerateStationName(st, tile, (p1 == AT_HELIPORT)||(p1 == AT_HELIDEPOT)||(p1 == AT_HELISTATION) ? 5 : 1))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
			return CMD_ERROR;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
	cost += _price.build_airport * w * h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
		st->airport_tile = tile;
5721
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
  1643
		st->AddFacility(FACIL_AIRPORT, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
		st->airport_type = (byte)p1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
		st->airport_flags = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1646
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1647
		st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  1648
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1649
		/* if airport was demolished while planes were en-route to it, the
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1650
		 * positions can no longer be the same (v->u.air.pos), since different
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1651
		 * airports have different indexes. So update all planes en-route to this
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1652
		 * airport. Only update if
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1653
		 * 1. airport is upgraded
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1654
		 * 2. airport is added to existing station (unfortunately unavoideable)
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1655
		 */
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1656
		if (airport_upgrade) UpdateAirplanesOnNewStation(st);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1657
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
		{
3471
e454e2c0c23e (svn r4316) -Codechange: finished r4257 (forgot one variable there)
celestar
parents: 3435
diff changeset
  1659
			const byte *b = _airport_sections[p1];
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1660
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1661
			BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1662
				MakeAirport(tile_cur, st->owner, st->index, *b++);
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1663
			} END_TILE_LOOP(tile_cur, w, h, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
		UpdateStationAcceptance(st, false);
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1668
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
		InvalidateWindow(WC_STATION_LIST, st->owner);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1670
		/* success, so don't delete the new station */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1671
		st_auto_delete.Release();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
static int32 RemoveAirport(Station *st, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1679
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
	int w,h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
	int32 cost;
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
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
	tile = st->airport_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
6032
fe6a454ac1ba (svn r8755) -Fix
tron
parents: 6018
diff changeset
  1688
	const AirportFTAClass *afc = st->Airport();
3876
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
  1689
	w = afc->size_x;
468642825a10 (svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
tron
parents: 3873
diff changeset
  1690
	h = afc->size_y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
	cost = w * h * _price.remove_airport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1694
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1695
		if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
		if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
			DeleteAnimatedTile(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
			DoClearSquare(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
		}
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1701
	} END_TILE_LOOP(tile_cur, w,h,tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
	if (flags & DC_EXEC) {
700
14816640f344 (svn r1150) Fixes:
tron
parents: 679
diff changeset
  1704
		uint i;
14816640f344 (svn r1150) Fixes:
tron
parents: 679
diff changeset
  1705
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1706
		for (i = 0; i < afc->nof_depots; ++i) {
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1707
			DeleteWindowById(
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1708
				WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1709
			);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  1710
		}
755
80091de50044 (svn r1211) -Feature: Introduce sticky windows to all vehicle windows...Just make sure you do not sticky more than 23 at a time. Also a lot of places in the code invalidated the 'status bar' of the vehicle, referring to it as widget 4. This is now widget 5 and has been #definitized
darkvater
parents: 709
diff changeset
  1711
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1712
		st->rect.AfterRemoveRect(st, tile, w, h);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  1713
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
		st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
		st->facilities &= ~FACIL_AIRPORT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1724
/** Build a buoy.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1725
 * @param tile tile where to place the bouy
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1726
 * @param p1 unused
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1727
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1729
int32 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
  1730
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
3374
faff80c38bcc (svn r4173) -Codechange: Use IsClearWaterTile for buoy construction
celestar
parents: 3362
diff changeset
  1735
	if (!IsClearWaterTile(tile) || tile == 0) return_cmd_error(STR_304B_SITE_UNSUITABLE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1737
	/* allocate and initialize new station */
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1738
	st = new Station(tile);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1739
	if (st == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1741
	/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1742
	AutoPtrT<Station> st_auto_delete(st);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1743
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1744
	st->town = ClosestTownFromTile(tile, (uint)-1);
0
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
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1747
	if (!GenerateStationName(st, tile, 4)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
	if (flags & DC_EXEC) {
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1750
		st->dock_tile = tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
		st->facilities |= FACIL_DOCK;
1751
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  1752
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  1753
		 * braindead.. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
		st->had_vehicle_of_type |= HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
		st->owner = OWNER_NONE;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1756
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  1757
		st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1759
		MakeBuoy(tile, st->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
		UpdateStationAcceptance(st, false);
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1763
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
		InvalidateWindow(WC_STATION_LIST, st->owner);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1765
		/* success, so don't delete the new station */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1766
		st_auto_delete.Release();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1767
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1769
	return _price.build_dock;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
1078
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1772
/* Checks if any ship is servicing the buoy specified. Returns yes or no */
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1773
static bool CheckShipsOnBuoy(Station *st)
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1774
{
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1775
	const Vehicle *v;
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1776
	FOR_ALL_VEHICLES(v) {
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1777
		if (v->type == VEH_Ship) {
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1778
			const Order *order;
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1779
			FOR_VEHICLE_ORDERS(v, order) {
4527
fa30d19685c2 (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
  1780
				if (order->type == OT_GOTO_STATION && order->dest == st->index) {
1078
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1781
					return true;
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1782
				}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1783
			}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1784
		}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1785
	}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1786
	return false;
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1787
}
1b9163f2e7eb (svn r1579) Fix: [ 1105963 ] Buoys can now only be removed if no ship has it in their schedule.
dominik
parents: 1067
diff changeset
  1788
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
static int32 RemoveBuoy(Station *st, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1791
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1792
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  1793
	/* XXX: strange stuff */
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  1794
	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
  1795
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1796
	tile = st->dock_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1798
	if (CheckShipsOnBuoy(st))   return_cmd_error(STR_BUOY_IS_IN_USE);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1799
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1801
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
		st->dock_tile = 0;
1751
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  1803
		/* Buoys are marked in the Station struct by this flag. Yes, it is this
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1706
diff changeset
  1804
		 * braindead.. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
		st->had_vehicle_of_type &= ~HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
5953
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1808
		/* We have to set the water tile's state to the same state as before the
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1809
		 * buoy was placed. Otherwise one could plant a buoy on a canal edge,
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1810
		 * remove it and flood the land (if the canal edge is at level 0) */
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1811
		Owner o = GetTileOwner(tile);
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1812
		if (o == OWNER_WATER) {
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1813
			MakeWater(tile);
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1814
		} else {
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1815
			MakeCanal(tile, o);
b40dc8f4dc69 (svn r8619) -Fix: store the ownership of a water tile in the buoy tile and set the ownership of the water tile when the buoy is removed. This solves the issue of removing ownership from canal tiles thus making is possible for other players to remove the canal tile.
rubidium
parents: 5914
diff changeset
  1816
		}
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  1817
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
	return _price.remove_truck_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1826
static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1827
	{-1,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1828
	{ 0,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1829
	{ 0,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1830
	{ 0, -1}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
};
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1832
static const byte _dock_w_chk[4] = { 2, 1, 2, 1 };
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  1833
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
  1834
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1835
/** Build a dock/haven.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1836
 * @param tile tile where dock will be built
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1837
 * @param p1 unused
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1838
 * @param p2 unused
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1839
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1840
int32 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
  1841
{
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1842
	TileIndex tile_cur;
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3123
diff changeset
  1843
	DiagDirection direction;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1849
	switch (GetTileSlope(tile, NULL)) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  1850
		case SLOPE_SW: direction = DIAGDIR_NE; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  1851
		case SLOPE_SE: direction = DIAGDIR_NW; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  1852
		case SLOPE_NW: direction = DIAGDIR_SE; break;
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  1853
		case SLOPE_NE: direction = DIAGDIR_SW; break;
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1854
		default: return_cmd_error(STR_304B_SITE_UNSUITABLE);
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1855
	}
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1856
4619
aa9747946f8e (svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents: 4559
diff changeset
  1857
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
aa9747946f8e (svn r6477) - Fix a loop-hole that allowed docks to be built regardless of town authority rating.
peter1138
parents: 4559
diff changeset
  1858
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1859
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1860
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1861
	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1862
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1863
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  1864
	tile_cur = tile + TileOffsByDiagDir(direction);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1866
	if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  1868
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1869
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1870
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  1872
	cost = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1873
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  1875
	tile_cur += TileOffsByDiagDir(direction);
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  1876
	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
  1877
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
3055
ed20cba49858 (svn r3644) Don't use FindLandscapeHeightByTile() when it's overkill - often it was just a complicated way of writing GetTileSlope(tile, NULL)
tron
parents: 3047
diff changeset
  1878
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1879
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
	/* middle */
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1881
	st = GetStationAround(
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
  1882
		tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1883
		_dock_w_chk[direction], _dock_h_chk[direction], INVALID_STATION);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1884
	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1885
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
	/* Find a station close to us */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
		st = GetClosestStationFromTile(tile, 8, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
		if (st!=NULL && st->facilities) st = NULL;
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
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1892
	/* In case of new station if DC_EXEC is NOT set we still need to create the station
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1893
	* to test if everything is OK. In this case we need to delete it before return. */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1894
	AutoPtrT<Station> st_auto_delete;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1895
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1896
	if (st != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
		if (st->owner != OWNER_NONE && st->owner != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
			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
  1899
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1900
		if (!st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR;
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1901
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1902
		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
  1903
	} else {
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1904
		/* allocate and initialize new station */
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1905
		st = new Station(tile);
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1906
		if (st == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1908
		/* ensure that in case of error (or no DC_EXEC) the station gets deleted upon return */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1909
		st_auto_delete = st;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1910
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1911
		Town *t = st->town = ClosestTownFromTile(tile, (uint)-1);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1912
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1913
		if (IsValidPlayer(_current_player) && (flags & DC_EXEC) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
			SETBIT(t->have_ratings, _current_player);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1915
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
1784
d0698aac0c2e (svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents: 1782
diff changeset
  1919
		if (!GenerateStationName(st, tile, 3)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1920
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1921
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
		st->dock_tile = tile;
5721
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
  1924
		st->AddFacility(FACIL_DOCK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1926
		st->rect.BeforeAddRect(tile, _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TRY);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  1927
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  1928
		MakeDock(tile, st->owner, st->index, direction);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1929
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
		UpdateStationAcceptance(st, false);
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  1932
		RebuildStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
		InvalidateWindow(WC_STATION_LIST, st->owner);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  1934
		/* success, so don't delete the new station */
5844
60231b36473e (svn r8414) -Codechange: Use own AutoPtrT instead of std::auto_ptr.
KUDr
parents: 5837
diff changeset
  1935
		st_auto_delete.Release();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
	return _price.build_dock;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
}
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
static int32 RemoveDock(Station *st, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1942
	TileIndex tile1;
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  1943
	TileIndex tile2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1945
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
	tile1 = st->dock_tile;
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  1948
	tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1950
	if (!EnsureNoVehicle(tile1)) return CMD_ERROR;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1951
	if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
		DoClearSquare(tile1);
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  1955
		MakeWater(tile2);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  1956
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1957
		st->rect.AfterRemoveTile(st, tile1);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  1958
		st->rect.AfterRemoveTile(st, tile2);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  1959
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3102
diff changeset
  1960
		MarkTileDirtyByTile(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1961
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1962
		st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1963
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1965
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1966
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1967
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1968
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
	return _price.remove_dock;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1972
#include "table/station_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
3763
7098c393c172 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3754
diff changeset
  1974
const DrawTileSprites *GetStationTileLayout(byte gfx)
7098c393c172 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3754
diff changeset
  1975
{
7098c393c172 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3754
diff changeset
  1976
	return &_station_display_datas[gfx];
7098c393c172 (svn r4754) - Newstations: expose default station display data via a function so we can use it (rarely) in other places.
peter1138
parents: 3754
diff changeset
  1977
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
5963
b29b12638654 (svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents: 5953
diff changeset
  1979
/* For drawing canal edges on buoys */
b29b12638654 (svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents: 5953
diff changeset
  1980
extern void DrawCanalWater(TileIndex tile);
b29b12638654 (svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents: 5953
diff changeset
  1981
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1982
static void DrawTile_Station(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1984
	const DrawTileSeqStruct *dtss;
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1985
	const DrawTileSprites *t = NULL;
3242
4c32bf21153b (svn r3916) Get/Set the rail type by [GS]etRailType{Crossing,OnBridge,}()
tron
parents: 3222
diff changeset
  1986
	RailType railtype = GetRailType(ti->tile);
2254
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2213
diff changeset
  1987
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1988
	uint32 relocation = 0;
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  1989
	const Station *st = NULL;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  1990
	const StationSpec *statspec = NULL;
4227
3ff996bf3f28 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  1991
	PlayerID owner = GetTileOwner(ti->tile);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  1992
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  1993
	SpriteID palette;
4227
3ff996bf3f28 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  1994
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  1995
	if (IsValidPlayer(owner)) {
4227
3ff996bf3f28 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  1996
		palette = PLAYER_SPRITE_COLOR(owner);
3ff996bf3f28 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  1997
	} else {
3ff996bf3f28 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  1998
		// Some stations are not owner by a player, namely oil rigs
3ff996bf3f28 (svn r5773) Clarify why the owner is checked before a palette is chosen when drawing a station tile: some stations are not owned by players
tron
parents: 4177
diff changeset
  1999
		palette = PALETTE_TO_GREY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2001
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2002
	// don't show foundation for docks
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2003
	if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
		DrawFoundation(ti, ti->tileh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
3568
c60d7aceed1a (svn r4450) - NewStations, rename *CustomStationSprite() to *CustomStationSpecIndex() to reflect their use, and alter the test for determining if a station has customised graphics.
peter1138
parents: 3554
diff changeset
  2006
	if (IsCustomStationSpecIndex(ti->tile)) {
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2007
		// look for customization
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2008
		st = GetStationByTile(ti->tile);
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2009
		statspec = st->speclist[GetCustomStationSpecIndex(ti->tile)].spec;
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2010
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2011
		//debug("Cust-o-mized %p", statspec);
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2012
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2013
		if (statspec != NULL) {
3576
18fb92480771 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2014
			uint tile = GetStationGfx(ti->tile);
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2015
3751
ce6408fdb788 (svn r4739) - Newstations: remove cargo type parameter of GetCustomStationRelocation() as we can determine it internally
peter1138
parents: 3742
diff changeset
  2016
			relocation = GetCustomStationRelocation(statspec, st, ti->tile);
3576
18fb92480771 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2017
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2018
			if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) {
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2019
				uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile);
4886
19d09a4386ad (svn r6823) - Codechange: Ignore bit 0 of a NewStation custom tile callback result. This fixes cosmetic problems with some add on stations.
peter1138
parents: 4873
diff changeset
  2020
				if (callback != CALLBACK_FAILED) tile = (callback & ~1) + GetRailStationAxis(ti->tile);
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2021
			}
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2022
3576
18fb92480771 (svn r4462) - Newstations: ensure the chosen tile layout is available from a custom station
peter1138
parents: 3574
diff changeset
  2023
			/* Ensure the chosen tile layout is valid for this custom station */
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2024
			if (statspec->renderdata != NULL) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2025
				t = &statspec->renderdata[tile < statspec->tiles ? tile : (uint)GetRailStationAxis(ti->tile)];
3754
4c8cbaaa0bbe (svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
peter1138
parents: 3751
diff changeset
  2026
			}
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2027
		}
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2028
	}
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2029
3737
1e4df4eb9298 (svn r4719) - Newstations: instead of drawing nothing, fall back to the default sprite layout if a station layout specifies so.
peter1138
parents: 3699
diff changeset
  2030
	if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationGfx(ti->tile)];
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2031
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2032
	image = t->ground_sprite;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2033
	if (HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) {
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2034
		image += GetCustomStationGroundRelocation(statspec, st, ti->tile);
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2035
		image += rti->custom_ground_offset;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2036
	} else {
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2037
		image += rti->total_offset;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2038
	}
449
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2039
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2040
	// station_land array has been increased from 82 elements to 114
2856e9ce0754 (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  2041
	// but this is something else. If AI builds station with 114 it looks all weird
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2042
	DrawGroundSprite(image, HASBIT(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
3789
c50647c927e4 (svn r4785) - Newstations: don't draw catenary on non-track tiles
glx
parents: 3784
diff changeset
  2044
	if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
3355
e414a0b104a6 (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas.
celestar
parents: 3344
diff changeset
  2045
5963
b29b12638654 (svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents: 5953
diff changeset
  2046
	if (IsBuoyTile(ti->tile) && (ti->z != 0 || !IsTileOwner(ti->tile, OWNER_WATER))) DrawCanalWater(ti->tile);
b29b12638654 (svn r8635) -Fix: draw canal edges under buoys that are in a canal.
rubidium
parents: 5953
diff changeset
  2047
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2048
	foreach_draw_tile_seq(dtss, t->seq) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2049
		SpriteID pal;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2050
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2051
		image = dtss->image;
5709
b9169cdd6019 (svn r8186) -Fix (FS#557): Apply railtype offset to station graphics if no custom station is in use.
peter1138
parents: 5708
diff changeset
  2052
		if (relocation == 0 || HASBIT(image, SPRITE_MODIFIER_USE_OFFSET)) {
3775
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2053
			image += rti->total_offset;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2054
		} else {
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2055
			image += relocation;
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2056
		}
0fb5118536c3 (svn r4767) - Newstations: fix loading / use of custom ground sprites
peter1138
parents: 3771
diff changeset
  2057
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2058
		if (_display_opt & DO_TRANS_BUILDINGS) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2059
			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2060
			pal = PALETTE_TO_TRANSPARENT;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2061
		} else if (HASBIT(image, PALETTE_MODIFIER_COLOR)) {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2062
			pal = palette;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2063
		} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2064
			pal = dtss->pal;
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2065
		}
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2066
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2067
		if ((byte)dtss->delta_z != 0x80) {
4230
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2068
			AddSortableSpriteToDraw(
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2069
				image, pal,
4230
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2070
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2071
				dtss->size_x, dtss->size_y,
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2072
				dtss->size_z, ti->z + dtss->delta_z
f4e93251e2f6 (svn r5787) Rename width, height and unk of struct DrawTileSeqStruct to size_{x,y,z}
tron
parents: 4227
diff changeset
  2073
			);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2074
		} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2075
			AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2076
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2077
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2078
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
2520
8a52362c4ada (svn r3049) Replace byte/int/uint by RailType where appropriate
tron
parents: 2517
diff changeset
  2080
void StationPickerDrawSprite(int x, int y, RailType railtype, int image)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2081
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2082
	SpriteID pal, img;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2083
	const DrawTileSeqStruct *dtss;
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2084
	const DrawTileSprites *t;
2254
99de94953104 (svn r2774) -Codechange: Removed TRACKTYPE_SPRITE_PITCH globally and replaced it by a member of RailtypeInfo
celestar
parents: 2213
diff changeset
  2085
	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2087
	pal = PLAYER_SPRITE_COLOR(_local_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2089
	t = &_station_display_datas[image];
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2090
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2091
	img = t->ground_sprite;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2092
	DrawSprite(img + rti->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
  2093
384
809833b4068d (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  2094
	foreach_draw_tile_seq(dtss, t->seq) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5667
diff changeset
  2096
		DrawSprite(dtss->image + rti->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
  2097
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2100
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
  2101
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4230
diff changeset
  2102
	return GetTileMaxZ(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2105
static Slope GetSlopeTileh_Station(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2106
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3630
diff changeset
  2107
	return SLOPE_FLAT;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2108
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2109
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2110
static void GetAcceptedCargo_Station(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2111
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2113
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2114
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2115
static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  2119
	td->owner = GetTileOwner(tile);
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2120
	td->build_date = GetStationByTile(tile)->build_date;
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 2008
diff changeset
  2121
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2122
	switch (GetStationType(tile)) {
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2123
		default: NOT_REACHED();
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2124
		case STATION_RAIL:    str = STR_305E_RAILROAD_STATION; break;
3882
c2e3e12e71d6 (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2125
		case STATION_AIRPORT:
c2e3e12e71d6 (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2126
			str = (IsHangar(tile) ? STR_305F_AIRCRAFT_HANGAR : STR_3060_AIRPORT);
c2e3e12e71d6 (svn r4938) Remove STATION_HANGAR, because it isn't really a station type of its own
tron
parents: 3876
diff changeset
  2127
			break;
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2128
		case STATION_TRUCK:   str = STR_3061_TRUCK_LOADING_AREA; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2129
		case STATION_BUS:     str = STR_3062_BUS_STATION; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2130
		case STATION_OILRIG:  str = STR_4807_OIL_RIG; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2131
		case STATION_DOCK:    str = STR_3063_SHIP_DOCK; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2132
		case STATION_BUOY:    str = STR_3069_BUOY; break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2133
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2134
	td->str = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2137
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2138
static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode)
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2139
{
1032
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2140
	switch (mode) {
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2141
		case TRANSPORT_RAIL:
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2142
			if (IsRailwayStation(tile) && !IsStationTileBlocked(tile)) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2143
				return TrackToTrackBits(GetRailStationTrack(tile)) * 0x101;
1032
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2144
			}
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2145
			break;
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2146
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2147
		case TRANSPORT_WATER:
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2148
			// buoy is coded as a station, it is always on open water
5914
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2149
			if (IsBuoy(tile)) {
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2150
				TrackBits ts = TRACK_BIT_ALL;
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2151
				// remove tracks that connect NE map edge
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2152
				if (TileX(tile) == 0) ts &= ~(TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT);
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2153
				// remove tracks that connect NW map edge
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2154
				if (TileY(tile) == 0) ts &= ~(TRACK_BIT_Y | TRACK_BIT_LEFT | TRACK_BIT_UPPER);
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2155
				return uint32(ts) * 0x101;
a038862ff1b9 (svn r8540) -Fix[YAPF]: Assert when buoy is placed on NE or NW map edge (Dan)
KUDr
parents: 5913
diff changeset
  2156
			}
1032
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2157
			break;
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2158
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2159
		case TRANSPORT_ROAD:
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2160
			if (IsRoadStopTile(tile)) {
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 4077
diff changeset
  2161
				return AxisToTrackBits(DiagDirToAxis(GetRoadStopDir(tile))) * 0x101;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2162
			}
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2163
			break;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3884
diff changeset
  2164
1032
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2165
		default:
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2166
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2167
	}
1032
b8094fcab4bc (svn r1533) Turn an if cascade into a switch and move a const array to the only location where it is used
tron
parents: 1024
diff changeset
  2168
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2169
	return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2170
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2171
2660
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2172
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2173
static void TileLoop_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
{
2660
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2175
	// FIXME -- GetTileTrackStatus_Station -> animated stationtiles
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2176
	// hardcoded.....not good
3540
3bcf5348842b (svn r4403) CodeChange : Add GetStationGfx and make use of [G|S]etStationGfx accessors. Also, use GetStationGfx instead of directly accessing the map for functions in station_map.h
belugas
parents: 3527
diff changeset
  2177
	switch (GetStationGfx(tile)) {
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2178
		case GFX_RADAR_LARGE_FIRST:
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2179
		case GFX_WINDSACK_FIRST : // for small airport
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2180
		case GFX_RADAR_INTERNATIONAL_FIRST:
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2181
		case GFX_RADAR_METROPOLITAN_FIRST:
4059
b1e1c1193f0a (svn r5346) - Feature: Add 4 new airports. 2 for aircraft, 2 for helicopters.
richk
parents: 4000
diff changeset
  2182
		case GFX_RADAR_DISTRICTWE_FIRST: // radar district W-E airport
4066
2d099b946f10 (svn r5362) - Fix: Updated sprites in New Airports to be allow cleaner replacement by newgrf graphics. All tiles now use SPR_AIRPORT_APRON as the tarmac. Created two new sprites in airports.grf for half-grass half-tarmac tiles on Intercontinental airport.
richk
parents: 4059
diff changeset
  2183
		case GFX_WINDSACK_INTERCON_FIRST : // for intercontinental airport
2660
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2184
			AddAnimatedTile(tile);
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2185
			break;
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2186
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2187
		case GFX_OILRIG_BASE: //(station part)
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2188
		case GFX_BUOY_BASE:
2660
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2189
			TileLoop_Water(tile);
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2190
			break;
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2191
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2192
		default: break;
204d363bf481 (svn r3202) If cascade -> switch
tron
parents: 2643
diff changeset
  2193
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2194
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2195
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2196
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2197
static void AnimateTile_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
{
4467
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2199
	typedef struct AnimData {
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2200
		StationGfx from; // first sprite
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2201
		StationGfx to;   // last sprite
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2202
		byte delay;
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2203
	} AnimData;
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2204
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2205
	static const AnimData data[] = {
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2206
		{ GFX_RADAR_LARGE_FIRST,         GFX_RADAR_LARGE_LAST,         3 },
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2207
		{ GFX_WINDSACK_FIRST,            GFX_WINDSACK_LAST,            1 },
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2208
		{ GFX_RADAR_INTERNATIONAL_FIRST, GFX_RADAR_INTERNATIONAL_LAST, 3 },
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2209
		{ GFX_RADAR_METROPOLITAN_FIRST,  GFX_RADAR_METROPOLITAN_LAST,  3 },
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2210
		{ GFX_RADAR_DISTRICTWE_FIRST,    GFX_RADAR_DISTRICTWE_LAST,    3 },
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2211
		{ GFX_WINDSACK_INTERCON_FIRST,   GFX_WINDSACK_INTERCON_LAST,   1 }
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2212
	};
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2213
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2214
	StationGfx gfx = GetStationGfx(tile);
4467
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2215
	const AnimData* i;
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2216
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2217
	for (i = data; i != endof(data); i++) {
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2218
		if (i->from <= gfx && gfx <= i->to) {
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2219
			if ((_tick_counter & i->delay) == 0) {
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2220
				SetStationGfx(tile, gfx < i->to ? gfx + 1 : i->from);
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2221
				MarkTileDirtyByTile(tile);
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2222
			}
156585f085d2 (svn r6252) Replace a comglomerate of ifs for animated station tiles by a small table and a loop iterating over it
tron
parents: 4434
diff changeset
  2223
			break;
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3540
diff changeset
  2224
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2225
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2226
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2227
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  2228
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2229
static void ClickTile_Station(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2230
{
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2231
	if (IsHangar(tile)) {
4638
05955c6cb536 (svn r6513) -Codechange: unified the code to draw depot windows
bjarni
parents: 4619
diff changeset
  2232
		ShowDepotWindow(tile, VEH_Aircraft);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2233
	} else {
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2234
		ShowStationViewWindow(GetStationIndex(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2235
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2236
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2238
static const byte _enter_station_speedtable[12] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2239
	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
  2240
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2241
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2242
static uint32 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
  2243
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2244
	if (v->type == VEH_Train) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2245
		if (IsRailwayStation(tile) && IsFrontEngine(v) &&
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 4549
diff changeset
  2246
				!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) {
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2247
			StationID station_id = GetStationIndex(tile);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  2248
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2249
			if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
4527
fa30d19685c2 (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
  2250
					(v->current_order.type == OT_GOTO_STATION && v->current_order.dest == station_id)) {
555
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2251
				if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) &&
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2252
						v->current_order.type != OT_LEAVESTATION &&
02df8a1b7f33 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2253
						v->last_station_visited != station_id) {
3482
54b144f07963 (svn r4331) Replace some direction calculation magic with DiagDirection to make a bit more clear what's going on
tron
parents: 3480
diff changeset
  2254
					DiagDirection dir = DirToDiagDir(v->direction);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2967
diff changeset
  2255
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2256
					x &= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2257
					y &= 0xF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2258
3482
54b144f07963 (svn r4331) Replace some direction calculation magic with DiagDirection to make a bit more clear what's going on
tron
parents: 3480
diff changeset
  2259
					if (DiagDirToAxis(dir) != AXIS_X) intswap(x, y);
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  2260
					if (y == TILE_SIZE / 2) {
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  2261
						if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5990
diff changeset
  2262
						if (x == 12) return VETSB_ENTERED_STATION | (station_id << VETS_STATION_ID_OFFSET); /* enter station */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2263
						if (x < 12) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2264
							uint16 spd;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2265
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2266
							v->vehstatus |= VS_TRAIN_SLOWING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2267
							spd = _enter_station_speedtable[x];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2268
							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
  2269
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2270
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2271
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2272
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2273
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2274
	} else if (v->type == VEH_Road) {
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5998
diff changeset
  2275
		if (v->u.road.state < RVSB_IN_ROAD_STOP && v->u.road.frame == 0) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2276
			if (IsRoadStop(tile)) {
2671
2c2edd17e9cc (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2277
				/* Attempt to allocate a parking bay in a road stop */
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2278
				RoadStop *rs = GetRoadStopByTile(tile, GetRoadStopType(tile));
2671
2c2edd17e9cc (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2279
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2280
				if (IsDriveThroughStopTile(tile)) {
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2281
					/* Vehicles entering a drive-through stop from the 'normal' side use first bay (bay 0). */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2282
					byte side = ((DirToDiagDir(v->direction) == ReverseDiagDir(GetRoadStopDir(tile))) == (v->u.road.overtaking == 0)) ? 0 : 1;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2283
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2284
					if (!rs->IsFreeBay(side)) return VETSB_CANNOT_ENTER;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2285
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2286
					/* Check if the vehicle is stopping at this road stop */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2287
					if (GetRoadStopType(tile) == ((v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) &&
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2288
							v->current_order.dest == GetStationIndex(tile)) {
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2289
						SETBIT(v->u.road.state, RVS_IS_STOPPING);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2290
						rs->AllocateDriveThroughBay(side);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2291
					}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2292
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2293
					/* Indicate if vehicle is using second bay. */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2294
					if (side == 1) SETBIT(v->u.road.state, RVS_USING_SECOND_BAY);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2295
					/* Indicate a drive-through stop */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2296
					SETBIT(v->u.road.state, RVS_IN_DT_ROAD_STOP);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2297
					return VETSB_CONTINUE;
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2298
				}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2299
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2300
				/* For normal (non drive-through) road stops */
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2301
				/* Check if station is busy or if there are no free bays. */
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5990
diff changeset
  2302
				if (rs->IsEntranceBusy() || !rs->HasFreeBay()) return VETSB_CANNOT_ENTER;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2303
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5998
diff changeset
  2304
				SETBIT(v->u.road.state, RVS_IN_ROAD_STOP);
2671
2c2edd17e9cc (svn r3213) - Codechange: Clean up handling of road stops, avoiding unnecessary use of pointers and using the *BIT() macros.
peter1138
parents: 2660
diff changeset
  2305
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2306
				/* Allocate a bay and update the road state */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2307
				uint bay_nr = rs->AllocateBay();
6000
181ad2c1ab14 (svn r8715) -Codechange/cleanup: replace magic numbers related to state of road vehicles with enums. Original patch by mart3p.
rubidium
parents: 5998
diff changeset
  2308
				SB(v->u.road.state, RVS_USING_SECOND_BAY, 1, bay_nr);
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2309
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2310
				/* Mark the station entrace as busy */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5963
diff changeset
  2311
				rs->SetEntranceBusy(true);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2312
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2313
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2314
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2315
5991
ec2eebfe86de (svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium
parents: 5990
diff changeset
  2316
	return VETSB_CONTINUE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2317
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2318
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2319
/* this function is called for one station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2320
static void StationHandleBigTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2321
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2322
	UpdateStationAcceptance(st, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2323
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  2324
	if (st->facilities == 0 && ++st->delete_ctr >= 8) delete st;
1239
133586622b78 (svn r1743) -Fix: Multistop: Added some debug output and made sure that orphaned slots are cleared.
celestar
parents: 1231
diff changeset
  2325
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2326
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2327
500
8e52f7797b48 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 497
diff changeset
  2328
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
  2329
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2330
static void UpdateStationRating(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2331
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2332
	GoodsEntry *ge;
1551
b1c7df6daa63 (svn r2055) -CodeChange: Begun introducting StationID
celestar
parents: 1527
diff changeset
  2333
	int rating;
b1c7df6daa63 (svn r2055) -CodeChange: Begun introducting StationID
celestar
parents: 1527
diff changeset
  2334
	StationID index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2335
	int waiting;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2336
	bool waiting_changed = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2337
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2338
	byte_inc_sat(&st->time_since_load);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2339
	byte_inc_sat(&st->time_since_unload);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2340
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2341
	ge = st->goods;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2342
	do {
1266
eccd576e322f (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  2343
		if (ge->enroute_from != INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2344
			byte_inc_sat(&ge->enroute_time);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2345
			byte_inc_sat(&ge->days_since_pickup);
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
			rating = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2349
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2350
				int b = ge->last_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2351
				if ((b-=85) >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2352
					rating += b >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2353
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2354
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2355
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2356
				byte age = ge->last_age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2357
				(age >= 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2358
				(rating += 10, age >= 2) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2359
				(rating += 10, age >= 1) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2360
				(rating += 13, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2361
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2362
4850
93095755db8c (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4848
diff changeset
  2363
			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
  2364
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2365
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2366
				byte days = ge->days_since_pickup;
3580
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3576
diff changeset
  2367
				if (st->last_vehicle_type == VEH_Ship)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2368
							days >>= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2369
				(days > 21) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2370
				(rating += 25, days > 12) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2371
				(rating += 25, days > 6) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2372
				(rating += 45, days > 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2373
				(rating += 35, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2374
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2375
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2376
			{
2504
5ae89f643cdc (svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents: 2502
diff changeset
  2377
				waiting = GB(ge->waiting_acceptance, 0, 12);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2378
				(rating -= 90, waiting > 1500) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2379
				(rating += 55, waiting > 1000) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2380
				(rating += 35, waiting > 600) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2381
				(rating += 10, waiting > 300) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2382
				(rating += 20, waiting > 100) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2383
				(rating += 10, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2384
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2385
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2386
			{
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2387
				int or_ = ge->rating; // old rating
0
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
				// only modify rating in steps of -2, -1, 0, 1 or 2
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2390
				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
  2391
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2392
				// if rating is <= 64 and more than 200 items waiting, remove some random amount of goods from the station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2393
				if (rating <= 64 && waiting >= 200) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2394
					int dec = Random() & 0x1F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2395
					if (waiting < 400) dec &= 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2396
					waiting -= dec + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2397
					waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2398
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2400
				// if rating is <= 127 and there are any items waiting, maybe remove some goods.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2401
				if (rating <= 127 && waiting != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2402
					uint32 r = Random();
5660
1425b81374b8 (svn r8120) -Fix (r8055): Station cargo waiting value clamp should be signed not unsigned. This resulted in cargo magically appearing...
peter1138
parents: 5609
diff changeset
  2403
					if (rating <= (int)GB(r, 0, 7)) {
1425b81374b8 (svn r8120) -Fix (r8055): Station cargo waiting value clamp should be signed not unsigned. This resulted in cargo magically appearing...
peter1138
parents: 5609
diff changeset
  2404
						waiting = max(waiting - (int)GB(r, 8, 2) - 1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2405
						waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2406
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2407
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2408
2504
5ae89f643cdc (svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents: 2502
diff changeset
  2409
				if (waiting_changed) SB(ge->waiting_acceptance, 0, 12, waiting);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2410
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2411
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2412
	} while (++ge != endof(st->goods));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2413
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2414
	index = st->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2415
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2416
	if (waiting_changed) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2417
		InvalidateWindow(WC_STATION_VIEW, index);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2418
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2419
		InvalidateWindowWidget(WC_STATION_VIEW, index, 5);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4066
diff changeset
  2420
	}
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2423
/* called for every station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2424
static void StationHandleSmallTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2425
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2426
	byte b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2427
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2428
	if (st->facilities == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2429
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2430
	b = st->delete_ctr + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2431
	if (b >= 185) b = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2432
	st->delete_ctr = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2433
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2434
	if (b == 0) UpdateStationRating(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2435
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2436
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1078
diff changeset
  2437
void OnTick_Station(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2438
{
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
  2439
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2440
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2441
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2442
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2443
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2444
	i = _station_tick_ctr;
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5220
diff changeset
  2445
	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
  2446
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2447
	if (IsValidStationID(i)) StationHandleBigTick(GetStation(i));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2448
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2449
	FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2450
		StationHandleSmallTick(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2451
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2452
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2453
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1078
diff changeset
  2454
void StationMonthlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2455
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2456
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2457
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2458
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  2459
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
  2460
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2461
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2462
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2463
	FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2464
		if (st->owner == owner &&
1245
3822f77cbc53 (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1239
diff changeset
  2465
				DistanceManhattan(tile, st->xy) <= radius) {
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2466
			uint i;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2467
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2468
			for (i = 0; i != NUM_CARGO; i++) {
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2469
				GoodsEntry* ge = &st->goods[i];
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2470
1266
eccd576e322f (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  2471
				if (ge->enroute_from != INVALID_STATION) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2472
					ge->rating = clamp(ge->rating + amount, 0, 255);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2473
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2474
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2475
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2476
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2479
static void UpdateStationWaiting(Station *st, int type, uint amount)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2480
{
2504
5ae89f643cdc (svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents: 2502
diff changeset
  2481
	SB(st->goods[type].waiting_acceptance, 0, 12,
5ae89f643cdc (svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents: 2502
diff changeset
  2482
		min(0xFFF, GB(st->goods[type].waiting_acceptance, 0, 12) + amount)
5ae89f643cdc (svn r3030) More work for GB/SB, this time concerning the waiting_acceptance attribute of stations
tron
parents: 2502
diff changeset
  2483
	);
0
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
	st->goods[type].enroute_time = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2486
	st->goods[type].enroute_from = st->index;
5683
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5679
diff changeset
  2487
	st->goods[type].enroute_from_xy = st->xy;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2488
	InvalidateWindow(WC_STATION_VIEW, st->index);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  2489
	st->MarkTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2490
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2491
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2492
/** Rename a station
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  2493
 * @param tile unused
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2494
 * @param p1 station ID that is to be renamed
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2495
 * @param p2 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2496
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  2497
int32 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
  2498
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2499
	StringID str;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2500
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2501
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2502
	if (!IsValidStationID(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
1774
907db1b7a445 (svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents: 1751
diff changeset
  2503
	st = GetStation(p1);
907db1b7a445 (svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents: 1751
diff changeset
  2504
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4351
diff changeset
  2505
	if (!CheckOwnership(st->owner)) return CMD_ERROR;
1774
907db1b7a445 (svn r2278) When renaming a station, check if the station exists and belongs to the correct player
tron
parents: 1751
diff changeset
  2506
1820
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1786
diff changeset
  2507
	str = AllocateNameUnique(_cmd_text, 6);
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1784
diff changeset
  2508
	if (str == 0) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2509
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2510
	if (flags & DC_EXEC) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2511
		StringID old_str = st->string_id;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2512
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2513
		st->string_id = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2514
		UpdateStationVirtCoord(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2515
		DeleteName(old_str);
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  2516
		ResortStationLists();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2517
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2518
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2519
		DeleteName(str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2520
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2521
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2522
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2523
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2524
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2525
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2526
uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2527
{
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2528
	Station* around[8];
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2529
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2530
	uint moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2531
	uint best_rating, best_rating2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2532
	Station *st1, *st2;
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2533
	uint t;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2534
	int rad = 0;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2535
	int w_prod; //width and height of the "producer" of the cargo
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2536
	int h_prod;
568
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2537
	int max_rad;
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2538
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2539
	for (i = 0; i < lengthof(around); i++) around[i] = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2540
568
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2541
	if (_patches.modified_catchment) {
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2542
		w_prod = w;
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2543
		h_prod = h;
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2544
		w += 16;
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2545
		h += 16;
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2546
		max_rad = 8;
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2547
	} else {
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2548
		w_prod = 0;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2549
		h_prod = 0;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2550
		w += 8;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2551
		h += 8;
568
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2552
		max_rad = 4;
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2553
	}
b0d0df062880 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2554
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  2555
	BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2556
		Station* st;
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2557
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2558
		cur_tile = TILE_MASK(cur_tile);
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2559
		if (!IsTileType(cur_tile, MP_STATION)) continue;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2560
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2561
		st = GetStationByTile(cur_tile);
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2562
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2563
		for (i = 0; i != lengthof(around); i++) {
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2564
			if (around[i] == NULL) {
5896
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5890
diff changeset
  2565
				if (!st->IsBuoy() &&
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2566
						(st->town->exclusive_counter == 0 || st->town->exclusivity == st->owner) && // check exclusive transport rights
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2567
						st->goods[type].rating != 0 &&
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2568
						(!_patches.selectgoods || st->goods[type].last_speed > 0) && // if last_speed is 0, no vehicle has been there.
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2569
						((st->facilities & ~FACIL_BUS_STOP)   != 0 || type == CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2570
						((st->facilities & ~FACIL_TRUCK_STOP) != 0 || type != CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers
3001
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2571
					int x_dist;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2572
					int y_dist;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2573
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2574
					if (_patches.modified_catchment) {
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2575
						// min and max coordinates of the producer relative
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2576
						const int x_min_prod = 9;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2577
						const int x_max_prod = 8 + w_prod;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2578
						const int y_min_prod = 9;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2579
						const int y_max_prod = 8 + h_prod;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2580
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2581
						rad = FindCatchmentRadius(st);
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2582
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2583
						x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur);
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2584
						if (w_cur < x_min_prod) {
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2585
							x_dist = x_min_prod - w_cur;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2586
						} else if (w_cur > x_max_prod) {
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2587
							x_dist = w_cur - x_max_prod;
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2588
						}
3001
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2589
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2590
						y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur);
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2591
						if (h_cur < y_min_prod) {
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2592
							y_dist = y_min_prod - h_cur;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2593
						} else if (h_cur > y_max_prod) {
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2594
							y_dist = h_cur - y_max_prod;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2595
						}
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2596
					} else {
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2597
						x_dist = 0;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2598
						y_dist = 0;
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2599
					}
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2600
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2601
					if (x_dist <= rad && y_dist <= rad) around[i] = st;
3001
f7944d55b88d (svn r3581) Just noticed the indentation was totally off, fix it
tron
parents: 3000
diff changeset
  2602
				}
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2603
				break;
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2604
			} else if (around[i] == st) {
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2605
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2606
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2607
		}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  2608
	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
  2609
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2610
	/* no stations around at all? */
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2611
	if (around[0] == NULL) return 0;
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2612
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2613
	if (around[1] == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2614
		/* only one station around */
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2615
		moved = (amount * around[0]->goods[type].rating >> 8) + 1;
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2616
		UpdateStationWaiting(around[0], type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2617
		return moved;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2620
	/* several stations around, find the two with the highest rating */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2621
	st2 = st1 = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2622
	best_rating = best_rating2 = 0;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2623
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2624
	for (i = 0; i != lengthof(around) && around[i] != NULL; i++) {
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2625
		if (around[i]->goods[type].rating >= best_rating) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2626
			best_rating2 = best_rating;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2627
			st2 = st1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2628
3002
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2629
			best_rating = around[i]->goods[type].rating;
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2630
			st1 = around[i];
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2631
		} else if (around[i]->goods[type].rating >= best_rating2) {
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2632
			best_rating2 = around[i]->goods[type].rating;
0651b917cd92 (svn r3582) Restructure MoveGoodsToStation() to avoid double bookkeeping of StationIDs and station pointers
tron
parents: 3001
diff changeset
  2633
			st2 = around[i];
0
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
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2636
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2637
	assert(st1 != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2638
	assert(st2 != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2639
	assert(best_rating != 0 || best_rating2 != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2640
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2641
	/* the 2nd highest one gets a penalty */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2642
	best_rating2 >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2644
	/* amount given to station 1 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2645
	t = (best_rating * (amount + 1)) / (best_rating + best_rating2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2646
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2647
	moved = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2648
	if (t != 0) {
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2649
		moved = t * best_rating / 256 + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2650
		amount -= t;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2651
		UpdateStationWaiting(st1, type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2652
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2653
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2654
	if (amount != 0) {
3000
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2655
		amount = amount * best_rating2 / 256 + 1;
692dd5ed9fca (svn r3580) Some small cleanups before the real change, especially reduce the indentation by one by using continue
tron
parents: 2989
diff changeset
  2656
		moved += amount;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2657
		UpdateStationWaiting(st2, type, amount);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2658
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2659
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2660
	return moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2661
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2662
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2663
void BuildOilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2664
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2665
	uint j;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  2666
	Station *st = new Station();
2427
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2667
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2668
	if (st == NULL) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5362
diff changeset
  2669
		DEBUG(misc, 0, "Can't allocate station for oilrig at 0x%X, reverting to oilrig only", tile);
2427
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2670
		return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2671
	}
2427
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2672
	if (!GenerateStationName(st, tile, 2)) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5362
diff changeset
  2673
		DEBUG(misc, 0, "Can't allocate station-name for oilrig at 0x%X, reverting to oilrig only", tile);
2427
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2674
		return;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2675
	}
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2676
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2677
	st->town = ClosestTownFromTile(tile, (uint)-1);
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2678
	st->sign.width_1 = 0;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2679
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2680
	MakeOilrig(tile, st->index);
2427
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2681
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2682
	st->owner = OWNER_NONE;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2683
	st->airport_flags = 0;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2684
	st->airport_type = AT_OILRIG;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2685
	st->xy = tile;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2686
	st->bus_stops = NULL;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2687
	st->truck_stops = NULL;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2688
	st->airport_tile = tile;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2689
	st->dock_tile = tile;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2690
	st->train_tile = 0;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2691
	st->had_vehicle_of_type = 0;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2692
	st->time_since_load = 255;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2693
	st->time_since_unload = 255;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2694
	st->delete_ctr = 0;
3580
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3576
diff changeset
  2695
	st->last_vehicle_type = VEH_Invalid;
2427
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2696
	st->facilities = FACIL_AIRPORT | FACIL_DOCK;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2697
	st->build_date = _date;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2698
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2699
	for (j = 0; j != NUM_CARGO; j++) {
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2700
		st->goods[j].waiting_acceptance = 0;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2701
		st->goods[j].days_since_pickup = 0;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2702
		st->goods[j].enroute_from = INVALID_STATION;
5683
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5679
diff changeset
  2703
		st->goods[j].enroute_from_xy = INVALID_TILE;
2427
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2704
		st->goods[j].rating = 175;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2705
		st->goods[j].last_speed = 0;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2706
		st->goods[j].last_age = 255;
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2707
	}
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2708
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2709
	UpdateStationVirtCoordDirty(st);
5312305eecdd (svn r2953) - Fix: [ 1257766 ] Cannot make ships go to an oil platform (oilrig has no station). While it is still possible that oilrigs end up without a station, it is only the case where no more stations can be built at all
Darkvater
parents: 2425
diff changeset
  2710
	UpdateStationAcceptance(st, false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2711
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2712
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2713
void DeleteOilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2714
{
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2715
	Station* st = GetStationByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2716
5887
65b5fc3f9b02 (svn r8499) -Fix
tron
parents: 5879
diff changeset
  2717
	MakeWater(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2718
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2719
	st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2720
	st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2721
	st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2722
	st->airport_flags = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2723
	UpdateStationVirtCoordDirty(st);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  2724
	if (st->facilities == 0) delete st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2725
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2726
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2427
diff changeset
  2727
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
  2728
{
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
  2729
	if (!IsTileOwner(tile, old_player)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2730
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4638
diff changeset
  2731
	if (new_player != PLAYER_SPECTATOR) {
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2732
		Station* st = GetStationByTile(tile);
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2733
1902
86b7fb11f938 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1901
diff changeset
  2734
		SetTileOwner(tile, new_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2735
		st->owner = new_player;
3812
e6fc916c17ab (svn r4822) -Feature: Station List View can now be sorted and filtered (by waiting cargo type and facilities)
celestar
parents: 3789
diff changeset
  2736
		RebuildStationLists();
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 59
diff changeset
  2737
		InvalidateWindowClasses(WC_STATION_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2738
	} else {
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3482
diff changeset
  2739
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2740
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2741
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2742
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2743
static int32 ClearTile_Station(TileIndex tile, byte flags)
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1942
diff changeset
  2744
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2745
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2746
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2747
	if (flags & DC_AUTO) {
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2748
		switch (GetStationType(tile)) {
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2749
			case STATION_RAIL:    return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2750
			case STATION_AIRPORT: return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2751
			case STATION_TRUCK:   return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2752
			case STATION_BUS:     return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2753
			case STATION_BUOY:    return_cmd_error(STR_306A_BUOY_IN_THE_WAY);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2754
			case STATION_DOCK:    return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2755
			case STATION_OILRIG:
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2756
				SetDParam(0, STR_4807_OIL_RIG);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2757
				return_cmd_error(STR_4800_IN_THE_WAY);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2758
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2759
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2760
3315
c9d989783c55 (svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
tron
parents: 3282
diff changeset
  2761
	st = GetStationByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2762
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2763
	switch (GetStationType(tile)) {
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2764
		case STATION_RAIL:    return RemoveRailroadStation(st, tile, flags);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2765
		case STATION_AIRPORT: return RemoveAirport(st, flags);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2766
		case STATION_TRUCK:
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2767
			if (IsDriveThroughStopTile(tile) && GetStopBuiltOnTownRoad(tile))
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2768
				return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2769
			return RemoveRoadStop(st, flags, tile);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2770
		case STATION_BUS:
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2771
			if (IsDriveThroughStopTile(tile) && GetStopBuiltOnTownRoad(tile))
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2772
				return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION);
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6000
diff changeset
  2773
			return RemoveRoadStop(st, flags, tile);
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2774
		case STATION_BUOY:    return RemoveBuoy(st, flags);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2775
		case STATION_DOCK:    return RemoveDock(st, flags);
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2776
		default: break;
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2777
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2778
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2779
	return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2780
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2781
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1078
diff changeset
  2782
void InitializeStations(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2783
{
1272
9aa073c64fc7 (svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents: 1266
diff changeset
  2784
	/* Clean the station pool and create 1 block in it */
4980
1e1cb22b3d27 (svn r6983) Use the pool macros for the Station pool
tron
parents: 4910
diff changeset
  2785
	CleanPool(&_Station_pool);
1e1cb22b3d27 (svn r6983) Use the pool macros for the Station pool
tron
parents: 4910
diff changeset
  2786
	AddBlockToPool(&_Station_pool);
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2787
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  2788
	/* Clean the roadstop pool and create 1 block in it */
4981
44eeee2407f4 (svn r6984) Use the pool macros for the RoadStop pool
tron
parents: 4980
diff changeset
  2789
	CleanPool(&_RoadStop_pool);
44eeee2407f4 (svn r6984) Use the pool macros for the RoadStop pool
tron
parents: 4980
diff changeset
  2790
	AddBlockToPool(&_RoadStop_pool);
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2791
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2792
	_station_tick_ctr = 0;
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2793
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2794
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2795
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2796
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2797
void AfterLoadStations(void)
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2798
{
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2799
	Station *st;
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2800
	uint i;
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  2801
	TileIndex tile;
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2802
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2803
	/* Update the speclists of all stations to point to the currently loaded custom stations. */
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2804
	FOR_ALL_STATIONS(st) {
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2805
		for (i = 0; i < st->num_specs; i++) {
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2806
			if (st->speclist[i].grfid == 0) continue;
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2807
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2808
			st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx);
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2809
		}
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2810
	}
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  2811
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  2812
	for (tile = 0; tile < MapSize(); tile++) {
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  2813
		if (GetTileType(tile) != MP_STATION) continue;
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  2814
		st = GetStationByTile(tile);
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5668
diff changeset
  2815
		st->rect.BeforeAddTile(tile, StationRect::ADD_FORCE);
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  2816
	}
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2817
}
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2818
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2819
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2820
extern const TileTypeProcs _tile_type_station_procs = {
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2821
	DrawTile_Station,           /* draw_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2822
	GetSlopeZ_Station,          /* get_slope_z_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2823
	ClearTile_Station,          /* clear_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2824
	GetAcceptedCargo_Station,   /* get_accepted_cargo_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2825
	GetTileDesc_Station,        /* get_tile_desc_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2826
	GetTileTrackStatus_Station, /* get_tile_track_status_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2827
	ClickTile_Station,          /* click_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2828
	AnimateTile_Station,        /* animate_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2829
	TileLoop_Station,           /* tile_loop_clear */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2830
	ChangeTileOwner_Station,    /* change_tile_owner_clear */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2831
	NULL,                       /* get_produced_cargo_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2832
	VehicleEnter_Station,       /* vehicle_enter_tile_proc */
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2833
	GetSlopeTileh_Station,      /* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2834
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2835
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1876
diff changeset
  2836
static const SaveLoad _roadstop_desc[] = {
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2837
	SLE_VAR(RoadStop,xy,           SLE_UINT32),
5718
ce37296bb03c (svn r8212) -Fix
tron
parents: 5716
diff changeset
  2838
	SLE_CONDNULL(1, 0, 44),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2839
	SLE_VAR(RoadStop,status,       SLE_UINT8),
1285
4bda5c927b45 (svn r1789) -Fix: there is no need to save the index, it is done for us
truelight
parents: 1284
diff changeset
  2840
	/* Index was saved in some versions, but this is not needed */
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  2841
	SLE_CONDNULL(4, 0, 8),
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5709
diff changeset
  2842
	SLE_CONDNULL(2, 0, 44),
3479
3655a074a380 (svn r4324) Remove the unused road stop type attribute from struct RoadStop
tron
parents: 3478
diff changeset
  2843
	SLE_CONDNULL(1, 0, 25),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2844
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2845
	SLE_REF(RoadStop,next,         REF_ROADSTOPS),
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5844
diff changeset
  2846
	SLE_CONDNULL(2, 0, 44),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2847
3431
e3b4bc9c4375 (svn r4259) -[multistop] Fix/Feature/Codechange:
celestar
parents: 3429
diff changeset
  2848
	SLE_CONDNULL(4, 0, 24),
3475
150d89779e96 (svn r4320) -Fix/Codechange: rs->num_vehicles is no longer saved or loaded, but computed on the fly. Partly fixes FS#101
celestar
parents: 3474
diff changeset
  2849
	SLE_CONDNULL(1, 25, 25),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2850
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2851
	SLE_END()
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2852
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2853
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1876
diff changeset
  2854
static const SaveLoad _station_desc[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2855
	SLE_CONDVAR(Station, xy,                         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2856
	SLE_CONDVAR(Station, xy,                         SLE_UINT32,                  6, SL_MAX_VERSION),
5879
b3413b837d21 (svn r8477) -Fix
tron
parents: 5878
diff changeset
  2857
	SLE_CONDNULL(4, 0, 5), // bus/lorry tile
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2858
	SLE_CONDVAR(Station, train_tile,                 SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2859
	SLE_CONDVAR(Station, train_tile,                 SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2860
	SLE_CONDVAR(Station, airport_tile,               SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2861
	SLE_CONDVAR(Station, airport_tile,               SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2862
	SLE_CONDVAR(Station, dock_tile,                  SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2863
	SLE_CONDVAR(Station, dock_tile,                  SLE_UINT32,                  6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2864
	    SLE_REF(Station, town,                       REF_TOWN),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2865
	    SLE_VAR(Station, trainst_w,                  SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2866
	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
  2867
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2868
	// alpha_order was stored here in savegame format 0 - 3
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  2869
	SLE_CONDNULL(1, 0, 3),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2870
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2871
	    SLE_VAR(Station, string_id,                  SLE_STRINGID),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2872
	    SLE_VAR(Station, had_vehicle_of_type,        SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2873
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2874
	    SLE_VAR(Station, time_since_load,            SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2875
	    SLE_VAR(Station, time_since_unload,          SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2876
	    SLE_VAR(Station, delete_ctr,                 SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2877
	    SLE_VAR(Station, owner,                      SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2878
	    SLE_VAR(Station, facilities,                 SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2879
	    SLE_VAR(Station, airport_type,               SLE_UINT8),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2880
5878
b81cea0c5456 (svn r8476) -Fix
tron
parents: 5877
diff changeset
  2881
	SLE_CONDNULL(2, 0, 5), // Truck/bus stop status
5877
d7f1c1c58a25 (svn r8475) -Fix
tron
parents: 5876
diff changeset
  2882
	SLE_CONDNULL(1, 0, 4), // Blocked months
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2883
5995
4e57aeeeafcd (svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents: 5991
diff changeset
  2884
	SLE_CONDVAR(Station, airport_flags,              SLE_VAR_U64 | SLE_FILE_U16,  0,  2),
4e57aeeeafcd (svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents: 5991
diff changeset
  2885
	SLE_CONDVAR(Station, airport_flags,              SLE_VAR_U64 | SLE_FILE_U32,  3, 45),
4e57aeeeafcd (svn r8705) -Codechange: Increased the number of airport blocks to 64. This involves changing the enum of airport blocks to a static const uint64 as SOME platforms do not support 64-bit enums
celestar
parents: 5991
diff changeset
  2886
	SLE_CONDVAR(Station, airport_flags,              SLE_UINT64,                 46, SL_MAX_VERSION),
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2887
3580
14bf6e7715c8 (svn r4466) -Fix: (FS#71) Game no longer crashes when the last vehicle serving a station has been deleted.
celestar
parents: 3576
diff changeset
  2888
	SLE_CONDNULL(2, 0, 25), /* Ex last-vehicle */
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2889
	SLE_CONDVAR(Station, last_vehicle_type,          SLE_UINT8,                  26, SL_MAX_VERSION),
3554
86230061c3e7 (svn r4426) Code Cleaning : replacing tabs with spaces, removing obvious comments, aligning arrays etc...
belugas
parents: 3553
diff changeset
  2890
3574
280e134ce515 (svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents: 3568
diff changeset
  2891
	// Was custom station class and id
280e134ce515 (svn r4460) - Newstations: remove unused class_id / stat_id variables from the
peter1138
parents: 3568
diff changeset
  2892
	SLE_CONDNULL(2, 3, 25),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2893
	SLE_CONDVAR(Station, build_date,                 SLE_FILE_U16 | SLE_VAR_I32,  3, 30),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2894
	SLE_CONDVAR(Station, build_date,                 SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2895
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2896
	SLE_CONDREF(Station, bus_stops,                  REF_ROADSTOPS,               6, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2897
	SLE_CONDREF(Station, truck_stops,                REF_ROADSTOPS,               6, SL_MAX_VERSION),
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2898
3687
f421ffcfeb00 (svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents: 3682
diff changeset
  2899
	/* Used by newstations for graphic variations */
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2900
	SLE_CONDVAR(Station, random_bits,                SLE_UINT16,                 27, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2901
	SLE_CONDVAR(Station, waiting_triggers,           SLE_UINT8,                  27, SL_MAX_VERSION),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2902
	SLE_CONDVAR(Station, num_specs,                  SLE_UINT8,                  27, SL_MAX_VERSION),
3687
f421ffcfeb00 (svn r4612) - NewStations: add random bits (for graphic variation) to stations
peter1138
parents: 3682
diff changeset
  2903
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  2904
	// reserve extra space in savegame here. (currently 32 bytes)
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3183
diff changeset
  2905
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2906
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2907
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2908
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2909
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1876
diff changeset
  2910
static const SaveLoad _goods_desc[] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2911
	    SLE_VAR(GoodsEntry, waiting_acceptance, SLE_UINT16),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2912
	    SLE_VAR(GoodsEntry, days_since_pickup,  SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2913
	    SLE_VAR(GoodsEntry, rating,             SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2914
	SLE_CONDVAR(GoodsEntry, enroute_from,       SLE_FILE_U8 | SLE_VAR_U16,  0, 6),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2915
	SLE_CONDVAR(GoodsEntry, enroute_from,       SLE_UINT16,                 7, SL_MAX_VERSION),
5683
b027e5d5b4cd (svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
celestar
parents: 5679
diff changeset
  2916
	SLE_CONDVAR(GoodsEntry, enroute_from_xy,    SLE_UINT32,                44, SL_MAX_VERSION),
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2917
	    SLE_VAR(GoodsEntry, enroute_time,       SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2918
	    SLE_VAR(GoodsEntry, last_speed,         SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2919
	    SLE_VAR(GoodsEntry, last_age,           SLE_UINT8),
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
  2920
	SLE_CONDVAR(GoodsEntry, feeder_profit,      SLE_INT32,                 14, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2921
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2922
	SLE_END()
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
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2925
static const SaveLoad _station_speclist_desc[] = {
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2926
	SLE_CONDVAR(StationSpecList, grfid,    SLE_UINT32, 27, SL_MAX_VERSION),
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2927
	SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8,  27, SL_MAX_VERSION),
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2928
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2929
	SLE_END()
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2930
};
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2931
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2932
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2933
static void SaveLoad_STNS(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2934
{
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2935
	uint i;
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2936
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2937
	SlObject(st, _station_desc);
1266
eccd576e322f (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  2938
	for (i = 0; i != NUM_CARGO; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2939
		SlObject(&st->goods[i], _goods_desc);
1266
eccd576e322f (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  2940
eccd576e322f (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  2941
		/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2676
diff changeset
  2942
		if (CheckSavegameVersion(7) && st->goods[i].enroute_from == 0xFF) {
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  2943
			st->goods[i].enroute_from = INVALID_STATION;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2944
		}
5697
ffd6ba312a67 (svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents: 5690
diff changeset
  2945
		if (CheckSavegameVersion(44)) {
ffd6ba312a67 (svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents: 5690
diff changeset
  2946
			/* Store position of the station where the goods come from, so there are no
ffd6ba312a67 (svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents: 5690
diff changeset
  2947
			 * very high payments when stations get removed. However, if the station
ffd6ba312a67 (svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents: 5690
diff changeset
  2948
			 * where the goods came from is already removed, the source information is
ffd6ba312a67 (svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents: 5690
diff changeset
  2949
			 * lost. In that case we set it to the position of this station */
ffd6ba312a67 (svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents: 5690
diff changeset
  2950
			st->goods[i].enroute_from_xy = IsValidStationID(st->goods[i].enroute_from) ? GetStation(st->goods[i].enroute_from)->xy : st->xy;
ffd6ba312a67 (svn r8161) -Fix (FS#555, r8144): enroute_from_xy was not set properly for old savegames.
rubidium
parents: 5690
diff changeset
  2951
		}
1266
eccd576e322f (svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents: 1265
diff changeset
  2952
	}
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2953
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2954
	if (st->num_specs != 0) {
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2955
		/* Allocate speclist memory when loading a game */
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5601
diff changeset
  2956
		if (st->speclist == NULL) st->speclist = CallocT<StationSpecList>(st->num_specs);
3765
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2957
		for (i = 0; i < st->num_specs; i++) SlObject(&st->speclist[i], _station_speclist_desc);
a4ddbff73f9f (svn r4757) - Newstations: add saveload support for custom station speclists
peter1138
parents: 3763
diff changeset
  2958
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2959
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2960
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1078
diff changeset
  2961
static void Save_STNS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2962
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2963
	Station *st;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2964
	// Write the stations
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2965
	FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2966
		SlSetArrayIndex(st->index);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2967
		SlAutolength((AutolengthProc*)SaveLoad_STNS, st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2968
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2969
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2970
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1078
diff changeset
  2971
static void Load_STNS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2972
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2973
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2974
	while ((index = SlIterateArray()) != -1) {
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  2975
		Station *st = new (index) Station();
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents: 5660
diff changeset
  2976
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2977
		SaveLoad_STNS(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2978
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2979
		// this means it's an oldstyle savegame without support for nonuniform stations
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2980
		if (st->train_tile != 0 && st->trainst_h == 0) {
3033
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  2981
			uint w = GB(st->trainst_w, 4, 4);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  2982
			uint h = GB(st->trainst_w, 0, 4);
9cba043eb38f (svn r3613) Some more const, indentation, whitespace and similar stuff
tron
parents: 3032
diff changeset
  2983
3334
2999d2ddc0f9 (svn r4113) Moved all relevant map functions for stations to station_map.[ch]
celestar
parents: 3333
diff changeset
  2984
			if (GetRailStationAxis(st->train_tile) == AXIS_Y) uintswap(w, h);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2985
			st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2986
			st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2987
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2988
	}
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2989
1472
a2abe3b9d7a7 (svn r1976) Cleanups - mostly indentation and fiddling with loops
tron
parents: 1457
diff changeset
  2990
	/* This is to ensure all pointers are within the limits of _stations_size */
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5220
diff changeset
  2991
	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
  2992
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2993
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  2994
static void Save_ROADSTOP(void)
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  2995
{
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  2996
	RoadStop *rs;
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  2997
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  2998
	FOR_ALL_ROADSTOPS(rs) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2999
		SlSetArrayIndex(rs->index);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  3000
		SlObject(rs, _roadstop_desc);
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3001
	}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3002
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3003
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  3004
static void Load_ROADSTOP(void)
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3005
{
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3006
	int index;
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3007
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3008
	while ((index = SlIterateArray()) != -1) {
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5709
diff changeset
  3009
		RoadStop *rs = new (index) RoadStop(INVALID_TILE);
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5697
diff changeset
  3010
1284
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3011
		SlObject(rs, _roadstop_desc);
e1969eb0227b (svn r1788) -Add: Made RoadStops dynamic. You can now create up to 64k roadstops.
truelight
parents: 1272
diff changeset
  3012
	}
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3013
}
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3014
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  3015
extern const ChunkHandler _station_chunk_handlers[] = {
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3016
	{ 'STNS', Save_STNS,      Load_STNS,      CH_ARRAY },
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1214
diff changeset
  3017
	{ '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
  3018
};
5395
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  3019
7727da322d66 (svn r7585) -Codechange: CheckStationSpreadOut() took too much CPU. Station rectangle is now maintained instead of calculating it each time by walking through whole map. Should help with the performance issue related to AIs trying to build road stops too often. (idea by Celestar)
KUDr
parents: 5385
diff changeset
  3020