station_cmd.c
author tron
Sat, 18 Dec 2004 12:40:34 +0000
changeset 700 c973846fe239
parent 679 e959706a3e4d
child 701 3a1b4771be58
permissions -rw-r--r--
(svn r1150) Fixes:
- Don't crash when building or destroying airport without depots (bugs were latent before r1149)
- Delete all hangar windows when destroying an airport, not just the first one (before r1149 none where deleted)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     2
#include "ttd.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 500
diff changeset
     3
#include "table/strings.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 595
diff changeset
     4
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     6
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "economy.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "airport.h"
405
6830ae7a0d5d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 403
diff changeset
    17
#include "sprite.h"
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
    18
#include "table/directions.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
// FIXME -- need to be embedded into Airport variable. Is dynamically
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
// deducteable from graphics-tile array, so will not be needed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
const byte _airport_size_x[5] = {4, 6, 1, 6, 7 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
const byte _airport_size_y[5] = {3, 6, 1, 6, 7 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
void ShowAircraftDepotWindow(uint tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
extern void UpdateAirplanesOnNewStation(Station *st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
static void MarkStationDirty(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	if (st->sign.width_1 != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
		InvalidateWindowWidget(WC_STATION_VIEW, st->index, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
		MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
			st->sign.left - 6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
			st->sign.top,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
			st->sign.left + (st->sign.width_1 << 2) + 12,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
			st->sign.top + 48);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
#define CHECK_STATIONS_ERR ((Station*)-1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
static Station *GetStationAround(uint tile, int w, int h, int closest_station)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	// check around to see if there's any stations there
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TILE_XY(1,1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
		if (IS_TILETYPE(tile_cur, MP_STATION)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
			int t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
			t = _map2[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
    50
			{
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
    51
				Station *st = DEREF_STATION(t);
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
    52
				// 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
    53
				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
    54
					continue;
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
    55
			}
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
    56
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
			if (closest_station == -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
				closest_station = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
			} else if (closest_station != t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
				_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
				return CHECK_STATIONS_ERR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TILE_XY(1,1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	return (closest_station == -1) ? NULL : DEREF_STATION(closest_station);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
55
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    68
TileIndex GetStationTileForVehicle(Vehicle *v, Station *st)
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    69
{
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    70
	switch (v->type) {
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    71
		case VEH_Train: 		return st->train_tile;
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    72
		case VEH_Aircraft:	return st->airport_tile;
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    73
		case VEH_Ship:			return st->dock_tile;
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    74
		case VEH_Road:			return (v->cargo_type == CT_PASSENGERS) ? st->bus_tile : st->lorry_tile;
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    75
		default:
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    76
			assert(false);
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    77
			return 0;
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    78
	}
73fae6c6568e (svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents: 43
diff changeset
    79
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
static bool CheckStationSpreadOut(Station *st, uint tile, int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	byte station_index = st->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	uint i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	uint x1 = GET_TILE_X(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	uint y1 = GET_TILE_Y(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	uint x2 = x1 + w - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	uint y2 = y1 + h - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	uint t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
	for(i=0; i!=TILES_X*TILES_Y; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
		if (IS_TILETYPE(i, MP_STATION) && _map2[i] == station_index) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
			t = GET_TILE_X(i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
			if (t < x1) x1 = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
			if (t > x2) x2 = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
			t = GET_TILE_Y(i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
			if (t < y1) y1 = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
			if (t > y2) y2 = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
	if (y2-y1 >= _patches.station_spread || x2-x1 >= _patches.station_spread) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
		_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
static Station *AllocateStation()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	Station *st, *a_free = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	int num_free = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	for(st = _stations, count = lengthof(_stations); count != 0; count--, st++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
		if (st->xy == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
			num_free++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
			if (a_free==NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
				a_free = st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	if (a_free == NULL ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
			(num_free < 30 && IS_HUMAN_PLAYER(_current_player))) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
		_error_message = STR_3008_TOO_MANY_STATIONS_LOADING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   132
	i = a_free->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
	memset(a_free, 0, sizeof(Station));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
	a_free->index = i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
	return a_free;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
static int CountMapSquareAround(uint tile, byte type, byte min, byte max) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	static const TileIndexDiff _count_square_table[7*7+1] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
		TILE_XY(-3,-3), 1, 1, 1, 1, 1, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
		TILE_XY(-6,1),  1, 1, 1, 1, 1, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
		TILE_XY(-6,1),  1, 1, 1, 1, 1, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
		TILE_XY(-6,1),  1, 1, 1, 1, 1, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
		TILE_XY(-6,1),  1, 1, 1, 1, 1, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
		TILE_XY(-6,1),  1, 1, 1, 1, 1, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
		TILE_XY(-6,1),  1, 1, 1, 1, 1, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
		0,
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   149
	};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	const TileIndexDiff *p = _count_square_table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	int num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	while ( (j=*p++) != 0 ) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
		tile = TILE_MASK(tile + j);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
		if (IS_TILETYPE(tile, type) && _map5[tile] >= min && _map5[tile] <= max)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
			num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	return num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
#define M(x) ((x) - STR_SV_STNAME)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
static bool GenerateStationName(Station *st, uint tile, int flag)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	static const uint32 _gen_station_name_bits[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
		0,																/* 0 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
		1 << M(STR_SV_STNAME_AIRPORT),		/* 1 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
		1 << M(STR_SV_STNAME_OILFIELD),		/* 2 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		1 << M(STR_SV_STNAME_DOCKS),			/* 3 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
		0x1FF << M(STR_SV_STNAME_BUOY_1),	/* 4 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
		1 << M(STR_SV_STNAME_HELIPORT),		/* 5 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	Town *t = st->town;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	uint32 free_names = (uint32)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	int found;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	uint z,z2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	unsigned long tmp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
		Station *s;
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
		FOR_ALL_STATIONS(s) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
			if (s != st && s->xy != 0 && s->town==t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
				uint str = M(s->string_id);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
				if (str <= 0x20) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
					if (str == M(STR_SV_STNAME_FOREST))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
						str = M(STR_SV_STNAME_WOODS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
					CLRBIT(free_names, str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   195
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   197
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	/* check default names */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	tmp = free_names & _gen_station_name_bits[flag];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	if (tmp != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
		found = FindFirstBit(tmp);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
		goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	/* check mine? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
		if (CountMapSquareAround(tile, MP_INDUSTRY, 0, 6) >= 2 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		    CountMapSquareAround(tile, MP_INDUSTRY, 0x64, 0x73) >= 2 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
				CountMapSquareAround(tile, MP_INDUSTRY, 0x2F, 0x33) >= 2 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
				CountMapSquareAround(tile, MP_INDUSTRY, 0x48, 0x58) >= 2 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
				CountMapSquareAround(tile, MP_INDUSTRY, 0x5B, 0x63) >= 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
					found = M(STR_SV_STNAME_MINES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
					goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	/* check close enough to town to get central as name? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	if (GetTileDist1D(tile,t->xy) < 8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
		found = M(STR_SV_STNAME);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		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
   221
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
		found = M(STR_SV_STNAME_CENTRAL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
		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
   224
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	/* Check lakeside */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
			!CheckDistanceFromEdge(tile, 20) &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
			CountMapSquareAround(tile, MP_WATER, 0, 0) >= 5) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
				found = M(STR_SV_STNAME_LAKESIDE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
				goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	/* Check woods */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && (
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
			CountMapSquareAround(tile, MP_TREES, 0, 255) >= 8 ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
			CountMapSquareAround(tile, MP_INDUSTRY, 0x10, 0x11) >= 2 )) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
				found = (_opt.landscape==LT_DESERT) ? M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
				goto done;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	/* check elevation compared to town */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	z = GetTileZ(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
	z2 = GetTileZ(t->xy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	if (z < z2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		found = M(STR_SV_STNAME_VALLEY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
		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
   248
	} else if (z > z2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		found = M(STR_SV_STNAME_HEIGHTS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
		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
   251
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
	/* check direction compared to town */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		static const int8 _direction_and_table[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
			~( (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
   257
			~( (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
   258
			~( (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
   259
			~( (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
   260
		};
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   261
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   262
		free_names &= _direction_and_table[
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   263
			(GET_TILE_X(tile) < GET_TILE_X(t->xy)) +
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
			(GET_TILE_Y(tile) < GET_TILE_Y(t->xy))*2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	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
   268
	if (tmp == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
		_error_message = STR_3007_TOO_MANY_STATIONS_LOADING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
		return false;
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
	found = FindFirstBit(tmp);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
done:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	st->string_id = found + STR_SV_STNAME;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
#undef M
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
static Station *GetClosestStationFromTile(uint tile, uint threshold, byte owner)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	Station *st, *best_station = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	uint cur_dist;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
		cur_dist = GetTileDist(tile, st->xy);
595
26c1858eefdd (svn r1017) Solved a Segfault if a station was built too close to the northern corner
Celestar
parents: 568
diff changeset
   287
		if (cur_dist < threshold && (owner == 0xFF || st->owner == owner) && (st->xy != 0)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
			threshold = cur_dist;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
			best_station = st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
		}
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
	return best_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
static void StationInitialize(Station *st, TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	GoodsEntry *ge;
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
	st->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
	st->bus_tile = st->lorry_tile = st->airport_tile = st->dock_tile = st->train_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	st->had_vehicle_of_type = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	st->time_since_load = 255;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	st->time_since_unload = 255;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	st->delete_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	st->facilities = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	st->last_vehicle = INVALID_VEHICLE;
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
	for(i=0,ge=st->goods; i!=NUM_CARGO; i++, ge++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
		ge->waiting_acceptance = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
		ge->days_since_pickup = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
		ge->enroute_from = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
		ge->rating = 175;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
		ge->last_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
		ge->last_age = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	}
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
   319
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
   320
	_global_station_sort_dirty = true; // build a new station
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
// 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
   324
// st = Station to update for.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
static void UpdateStationVirtCoord(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	Point pt = RemapCoords2(GET_TILE_X(st->xy) * 16, GET_TILE_Y(st->xy) * 16);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	pt.y -= 32;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	if (st->facilities&FACIL_AIRPORT && st->airport_type==AT_OILRIG) pt.y -= 16;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   331
	SetDParam(0, st->index);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   332
	SetDParam(1, st->facilities);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	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
   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
// Update the virtual coords needed to draw the station sign for all stations.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
void UpdateAllStationVirtCoord()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
		if (st->xy != 0)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   342
			UpdateStationVirtCoord(st);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
// 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
   347
static void UpdateStationVirtCoordDirty(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	MarkStationDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	UpdateStationVirtCoord(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	MarkStationDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
}
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
// Get a mask of the cargo types that the station accepts.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
static uint GetAcceptanceMask(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	uint mask = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	uint cur_mask = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
	for(i=0; i!=NUM_CARGO; i++,cur_mask*=2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
		if (st->goods[i].waiting_acceptance & 0x8000)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
			mask |= cur_mask;
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
	return mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
// 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
   368
// msg is the string id of the message to display.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
static void ShowRejectOrAcceptNews(Station *st, uint32 items, StringID msg)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	if (items) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   372
		SetDParam(2, items >> 16);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   373
		SetDParam(1, items & 0xFFFF);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   374
		SetDParam(0, st->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
		AddNewsItem(msg + ((items >> 16)?1:0), NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
// Get a list of the cargo types being produced around the tile.
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   380
void GetProductionAroundTiles(uint *produced, uint tile, int w, int h, int rad)
0
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
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
	int x1,y1,x2,y2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
	int xc,yc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
	byte cargos[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
	memset(produced, 0, NUM_CARGO * sizeof(uint));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	x = GET_TILE_X(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	y = GET_TILE_Y(tile);
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
	// expand the region by 4 tiles on each side
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
	// while making sure that we remain inside the board.
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   394
	x2 = min(x + w + rad, TILE_X_MAX+1);
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   395
	x1 = max(x-rad, 0);
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   396
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   397
	y2 = min(y + h + rad, TILE_Y_MAX+1);
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   398
	y1 = max(y-rad, 0);
0
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
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	yc = y1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
		xc = x1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
			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
   410
				GetProducedCargoProc *gpc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
				uint tile = TILE_XY(xc, yc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
				gpc = _tile_type_procs[GET_TILETYPE(tile)]->get_produced_cargo_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
				if (gpc != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
					cargos[0] = cargos[1] = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
					gpc(tile, cargos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
					if (cargos[0] != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
						produced[cargos[0]]++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
						if (cargos[1] != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
							produced[cargos[1]]++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
				}
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
		} while (++xc != x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
	} while (++yc != y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
// Get a list of the cargo types that are accepted around the tile.
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   429
void GetAcceptanceAroundTiles(uint *accepts, uint tile, int w, int h, int rad)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	int x1,y1,x2,y2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	int xc,yc;
473
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   434
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   435
	memset(accepts, 0, sizeof(AcceptedCargo));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	x = GET_TILE_X(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
	y = GET_TILE_Y(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
	// expand the region by 4 tiles on each side
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	// while making sure that we remain inside the board.
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   442
	x2 = min(x + w + rad, TILE_X_MAX+1);
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   443
	y2 = min(y + h + rad, TILE_Y_MAX+1);
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   444
	x1 = max(x-rad, 0);
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   445
	y1 = max(y-rad, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
	assert(x1 < x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	assert(y1 < y2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
	assert(w > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	assert(h > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
	yc = y1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
		xc = x1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
			uint tile = TILE_XY(xc, yc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
			if (!IS_TILETYPE(tile, MP_STATION)) {
473
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   458
				AcceptedCargo ac;
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   459
				int i;
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   460
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   461
				GetAcceptedCargo(tile, ac);
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   462
				for (i = 0; i < NUM_CARGO; ++i)
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
   463
					accepts[i] += ac[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
		} while (++xc != x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
	} while (++yc != y2);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
// Update the acceptance for a station.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
// 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
   471
static void UpdateStationAcceptance(Station *st, bool show_msg)
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
	uint old_acc, new_acc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
	TileIndex span[1+1+2+2+1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
	int min_x, min_y, max_x, max_y;
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   477
	int rad = 4;	//Put this to surpress a compiler warning
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	uint accepts[NUM_CARGO];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
	// Don't update acceptance for a buoy
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
	if (st->had_vehicle_of_type & HVOT_BUOY)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
	/* old accepted goods types */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
	old_acc = GetAcceptanceMask(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
	// 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
   488
	span[3] = span[5] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
	span[0] = st->bus_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
	span[1] = st->lorry_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
	span[2] = st->train_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
	if (st->train_tile != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
		span[3] = st->train_tile + TILE_XY(st->trainst_w-1, st->trainst_h-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	span[4] = st->airport_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	if (st->airport_tile != 0) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   497
		span[5] = st->airport_tile + TILE_XY(_airport_size_x[st->airport_type]-1, _airport_size_y[st->airport_type]-1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
	span[6] = st->dock_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
	// Construct a rectangle from those points
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
	min_x = min_y = 0x7FFFFFFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
	max_x = max_y = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
	for(i=0; i!=7; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
		uint tile = span[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
		if (tile) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
			min_x = min(min_x,GET_TILE_X(tile));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
			max_x = max(max_x,GET_TILE_X(tile));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
			min_y = min(min_y,GET_TILE_Y(tile));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
			max_y = max(max_y,GET_TILE_Y(tile));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
	}
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   514
	if (_patches.modified_catchment) {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   515
		FIND_CATCHMENT_RADIUS(st,rad)
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   516
	} else {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   517
		rad = 4;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   518
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
	// And retrieve the acceptance.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
	if (max_x != 0) {
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
   522
		GetAcceptanceAroundTiles(accepts, TILE_XY(min_x, min_y), max_x - min_x + 1, max_y-min_y+1,rad);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
		memset(accepts, 0, sizeof(accepts));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	// Adjust in case our station only accepts fewer kinds of goods
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	for(i=0; i!=NUM_CARGO; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
		uint amt = min(accepts[i], 15);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
		// Make sure the station can accept the goods type.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
		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
   533
				(i == CT_PASSENGERS && !(st->facilities & (byte)~FACIL_TRUCK_STOP)))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
			amt = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
		st->goods[i].waiting_acceptance = (st->goods[i].waiting_acceptance & ~0xF000) + (amt << 12);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
	// 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
   540
	new_acc = GetAcceptanceMask(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	if (old_acc == new_acc)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   543
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	// 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
   545
	if (show_msg && st->owner == _local_player && st->facilities) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
		uint32 accept=0, reject=0; /* these contain two string ids each */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
		const StringID *str = _cargoc.names_s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
			if (new_acc & 1) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   551
				if (!(old_acc & 1)) accept = (accept << 16) | *str;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
				if (old_acc & 1) reject = (reject << 16) | *str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
		} while (str++,(new_acc>>=1) != (old_acc>>=1));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
		ShowRejectOrAcceptNews(st, accept, STR_3040_NOW_ACCEPTS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
		ShowRejectOrAcceptNews(st, reject, STR_303E_NO_LONGER_ACCEPTS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	// redraw the station view since acceptance changed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
	InvalidateWindowWidget(WC_STATION_VIEW, st->index, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
// This is called right after a station was deleted.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
// 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
   567
// deleted after a little while.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
static void DeleteStationIfEmpty(Station *st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	if (st->facilities == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
		st->delete_ctr = 0;
28
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   571
		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
   572
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
// 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
   576
// Or an error code if it failed.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
int32 CheckFlatLandBelow(uint tile, uint w, uint h, uint flags, uint invalid_dirs, int *station)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
	int32 cost = 0, ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	uint tileh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
	int z, allowed_z = -1, flat_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
	BEGIN_TILE_LOOP(tile_cur, w, h, tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
		if (!EnsureNoVehicle(tile_cur))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
		tileh = GetTileSlope(tile_cur, &z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
		// steep slopes are completely prohibited
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 71
diff changeset
   591
		if (tileh & 0x10 || (((!_patches.ainew_active && _is_ai_player) || !_patches.build_on_slopes) && tileh != 0)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
			_error_message = STR_0007_FLAT_LAND_REQUIRED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
		flat_z = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		if (tileh) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
			// need to check so the entrance to the station is not pointing at a slope.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
			if ((invalid_dirs&1 && !(tileh & 0xC) && (uint)w_cur == w) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
					(invalid_dirs&2 && !(tileh & 6) &&	h_cur == 1) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
					(invalid_dirs&4 && !(tileh & 3) && w_cur == 1) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
					(invalid_dirs&8 && !(tileh & 9) && (uint)h_cur == h)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
				_error_message = STR_0007_FLAT_LAND_REQUIRED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
				return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
			cost += _price.terraform;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
			flat_z += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
		}
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
		// 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
   611
		if (allowed_z == -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
			// first tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
			allowed_z = flat_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
		} else if (allowed_z != flat_z) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
			_error_message = STR_0007_FLAT_LAND_REQUIRED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   619
		// if station is set, then we have special handling to allow building on top of already existing stations.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
		// so station points to -1 if we can build on any station. or it points to a station if we're only allowed to build
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
		// on exactly that station.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
		if (station && IS_TILETYPE(tile_cur, MP_STATION)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
			if (_map5[tile] >= 8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
				_error_message = STR_0007_FLAT_LAND_REQUIRED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
				return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
				int st = _map2[tile_cur];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
				if (*station == -1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
					*station = st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
				else if (*station != st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
					_error_message = STR_3006_ADJOINS_MORE_THAN_ONE_EXISTING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
					return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   636
			ret = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
			if (ret == CMD_ERROR) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
			cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
	END_TILE_LOOP(tile_cur, w, h, tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
static bool CanExpandRailroadStation(Station *st, uint *fin, int direction)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	uint curw = st->trainst_w, curh = st->trainst_h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	uint tile = fin[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	uint w = fin[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	uint h = fin[2];
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
	if (_patches.nonuniform_stations) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
		// determine new size of train station region..
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
		int x = min(GET_TILE_X(st->train_tile), GET_TILE_X(tile));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
		int y = min(GET_TILE_Y(st->train_tile), GET_TILE_Y(tile));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
		curw = max(GET_TILE_X(st->train_tile) + curw, GET_TILE_X(tile) + w) - x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
		curh = max(GET_TILE_Y(st->train_tile) + curh, GET_TILE_Y(tile) + h) - y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
		tile = TILE_XY(x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
		// check so the direction is the same
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
		if ((_map5[st->train_tile] & 1) != direction) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
		// check if the new station adjoins the old station in either direction
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
		if (curw == w && st->train_tile == tile + TILE_XY(0, h)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
			// above
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
			curh += h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
		} else if (curw == w && st->train_tile == tile - TILE_XY(0, curh)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
			// below
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
			tile -= TILE_XY(0, curh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
			curh += h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
		} else if (curh == h && st->train_tile == tile + TILE_XY(w, 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
			// to the left
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
			curw += w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
		} else if (curh == h && st->train_tile == tile - TILE_XY(curw, 0)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
			// to the right
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
			tile -= TILE_XY(curw, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
			curw += w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
		} else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
	// make sure the final size is not too big.
28
635ad4c62bec (svn r29) -Fix You cannot take ownership of an oilrig by building right next to it
darkvater
parents: 27
diff changeset
   682
	if (curw > _patches.station_spread || curh > _patches.station_spread) return false;
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
	// 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
   685
	// 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
   686
	fin[0] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
	fin[1] = curw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
	fin[2] = curh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	return true;
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
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   692
static inline byte *CreateSingle(byte *layout, int n)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
	do *layout++ = 0; while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
	layout[((n-1) >> 1)-n] = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
536
aef4753985d3 (svn r907) Sprinkle holy ANSI water:
tron
parents: 534
diff changeset
   700
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
   701
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	int i = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	do *layout++ = b; while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	if (n > 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
		layout[0-n] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
		layout[n-1-n] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
	return layout;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
// stolen from TTDPatch
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   712
static void GetStationLayout(byte *layout, int numtracks, int plat_len, struct StationSpec *spec)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
{
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   714
	if (spec != NULL && spec->lengths >= plat_len && spec->platforms[plat_len - 1] >= numtracks
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   715
	    && spec->layouts[plat_len - 1][numtracks - 1]) {
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   716
		/* Custom layout defined, follow it. */
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   717
		memcpy(layout, spec->layouts[plat_len - 1][numtracks - 1],
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   718
		       plat_len * numtracks);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   719
		return;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   720
	}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   721
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
	if (plat_len == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
		CreateSingle(layout, numtracks);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
		if (numtracks & 1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
			layout = CreateSingle(layout, plat_len);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
		numtracks>>=1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
		while (--numtracks >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
			layout = CreateMulti(layout, plat_len, 4);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
			layout = CreateMulti(layout, plat_len, 6);
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
/* build railroad station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
 * p1 & 1 - orientation
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
 * (p1 >> 8) & 0xFF - numtracks
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
 * (p1 >> 16) & 0xFF - platform length
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   740
 * p2 & 0xF  - railtype
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   741
 * p2 & 0x10 - set for custom station
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   742
 * p2 >> 8   - custom station id
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
int32 CmdBuildRailroadStation(int x_org, int y_org, uint32 flags, uint32 p1, uint32 p2)
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
	/* unpack params */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
	int w_org,h_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
	uint tile_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	int32 cost, ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	int est;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
	int plat_len, numtracks;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
	int direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
	uint finalvalues[3];
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
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
	tile_org = TILE_FROM_XY(x_org,y_org);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
	/* Does the authority allow this? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
		return CMD_ERROR;
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
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
		/* unpack parameters */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
		direction = p1 & 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
		plat_len = (p1 >> 16) & 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
		numtracks = (p1 >> 8) & 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
		/* w = length, h = num_tracks */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
		if (direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
			h_org = plat_len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
			w_org = numtracks;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
			w_org = plat_len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
			h_org = numtracks;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
		}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
	// 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
   781
	finalvalues[0] = tile_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
	finalvalues[1] = w_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	finalvalues[2] = h_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
	// Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
	est = -1;
313
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   787
	// If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   788
	//  for detail info, see: https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   789
	if ((ret=CheckFlatLandBelow(tile_org, w_org, h_org, flags&~DC_EXEC, 5 << direction, _patches.nonuniform_stations ? &est : NULL)) == CMD_ERROR) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
	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
   791
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	// Make sure there are no similar stations around us.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
	st = GetStationAround(tile_org, w_org, h_org, est);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
	if (st == CHECK_STATIONS_ERR) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
	// 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
   797
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
		st = GetClosestStationFromTile(tile_org, 8, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
		if (st != NULL && st->facilities) st = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
	if (st != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
		// Reuse an existing station.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
		if (st->owner != OWNER_NONE && st->owner != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
			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
   806
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
		if (st->train_tile != 0) {
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 71
diff changeset
   808
			// check if we want to expanding an already existing station?
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents: 71
diff changeset
   809
			if ((!_patches.ainew_active && _is_ai_player) || !_patches.join_stations || !CanExpandRailroadStation(st, finalvalues, direction))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
				return_cmd_error(STR_3005_TOO_CLOSE_TO_ANOTHER_RAILROAD);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
		if (!CheckStationSpreadOut(st, tile_org, w_org, h_org))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	}	else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
		// Create a new station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
		st = AllocateStation();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
		if (st == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
			return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   821
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
		st->town = ClosestTownFromTile(tile_org, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
		if (_current_player < MAX_PLAYERS && flags&DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
			SETBIT(st->town->have_ratings, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
		if (!GenerateStationName(st, tile_org, 0))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
			return CMD_ERROR;
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
		if (flags & DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
			StationInitialize(st, tile_org);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
		int tile_delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
		byte *layout_ptr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
		uint station_index = st->index;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   837
		struct StationSpec *statspec;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
313
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   839
		// Now really clear the land below the station
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   840
		// It should never return CMD_ERROR.. but you never know ;)
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   841
		//  (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags)
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   842
		if (CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << direction, _patches.nonuniform_stations ? &est : NULL) == CMD_ERROR) return CMD_ERROR;
6660bb7b38f1 (svn r319) -Fix: [ 1029064 ] Building a station acted weird in some rare situations
truelight
parents: 243
diff changeset
   843
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
		st->train_tile = finalvalues[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
		if (!st->facilities) st->xy = finalvalues[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
		st->facilities |= FACIL_TRAIN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
		st->owner = _current_player;
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
		st->trainst_w = finalvalues[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
		st->trainst_h = finalvalues[2];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   851
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
   852
		st->build_date = _date;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   853
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
		tile_delta = direction ? TILE_XY(0,1) : TILE_XY(1,0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   855
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   856
		statspec = (p2 & 0x10) != 0 ? GetCustomStation(STAT_CLASS_DFLT, p2 >> 8) : NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
		layout_ptr = alloca(numtracks * plat_len);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   858
		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
   859
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
			int tile = tile_org;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
			int w = plat_len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
			do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   865
				ModifyTile(tile,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
					MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   867
					MP_MAP2 | MP_MAP5 | MP_MAP3LO | MP_MAP3HI,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
					station_index, /* map2 parameter */
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   869
					p2 & 0xFF,     /* map3lo parameter */
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   870
					p2 >> 8,       /* map3hi parameter */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
					(*layout_ptr++) + direction   /* map5 parameter */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
				);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
				tile += tile_delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
			} while (--w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
			tile_org += tile_delta ^ TILE_XY(1,1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
		} while (--numtracks);
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
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
		UpdateStationAcceptance(st, false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
		InvalidateWindow(WC_STATION_LIST, st->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
static bool TileBelongsToRailStation(Station *st, uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	return IS_TILETYPE(tile, MP_STATION) && _map2[tile] == st->index && _map5[tile] < 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
static void MakeRailwayStationAreaSmaller(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
	uint w = st->trainst_w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	uint h = st->trainst_h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	uint tile = st->train_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
	uint i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
restart:
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   900
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	// too small?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
	if (w != 0 && h != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
		// check the left side, x = constant, y changes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
		for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(0,i)) ;)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
			// the left side is unused?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
			if (++i==h) { tile += TILE_XY(1, 0); w--; goto restart; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
		// check the right side, x = constant, y changes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
		for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(w-1,i)) ;)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
			// the right side is unused?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
			if (++i==h) { w--; goto restart; }
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
		// check the upper side, y = constant, x changes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
		for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(i,0)) ;)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
			// the left side is unused?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
			if (++i==w) { tile += TILE_XY(0, 1); h--; goto restart; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
		// check the lower side, y = constant, x changes
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
		for(i=0; !TileBelongsToRailStation(st, tile + TILE_XY(i,h-1)) ;)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
			// the left side is unused?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
			if (++i==w) { h--; goto restart; }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
		tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
	st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	st->train_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
// remove a single tile from a railroad station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
int32 CmdRemoveFromRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
	uint tile = TILE_FROM_XY(x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	// make sure the specified tile belongs to the current player, and that it is a railroad station.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	if (!IS_TILETYPE(tile, MP_STATION) || _map5[tile] >= 8 || !_patches.nonuniform_stations) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	st = DEREF_STATION(_map2[tile]);
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
   940
	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
   941
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	// 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
   943
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
		DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
		// 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
   946
		// we also need to adjust train_tile.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
		MakeRailwayStationAreaSmaller(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
		// 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
   950
		if (st->train_tile == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
			st->facilities &= ~FACIL_TRAIN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
			UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
			DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	return _price.remove_rail_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
// determine the number of platforms for the station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
uint GetStationPlatforms(Station *st, uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	uint t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	int dir,delta;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
	int len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	assert(TileBelongsToRailStation(st, tile));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
	len = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	dir = _map5[tile]&1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	delta = dir ? TILE_XY(0,1) : TILE_XY(1,0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	// find starting tile..
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
	t = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
	do { t -= delta; len++; } while (TileBelongsToRailStation(st, t) && (_map5[t]&1) == dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
	// find ending tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	t = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	do { t += delta; len++; }while (TileBelongsToRailStation(st, t) && (_map5[t]&1) == dir);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
	return len - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   983
/* TODO: Custom classes! */
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   984
/* Indexed by class, just STAT_CLASS_DFLT and STAT_CLASS_WAYP supported. */
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   985
static int _statspec_highest_id[2] = {-1, -1};
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   986
static struct StationSpec _station_spec[2][256];
399
ad3dcbfd2d48 (svn r591) -newgrf: Store whole struct StationSpec in SetCustomStation(), not just the rendering data. This will be needed for variational stationspecs (pasky).
darkvater
parents: 389
diff changeset
   987
400
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
   988
void SetCustomStation(byte local_stid, struct StationSpec *spec)
399
ad3dcbfd2d48 (svn r591) -newgrf: Store whole struct StationSpec in SetCustomStation(), not just the rendering data. This will be needed for variational stationspecs (pasky).
darkvater
parents: 389
diff changeset
   989
{
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   990
	enum StationClass sclass;
400
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
   991
	int stid = -1;
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
   992
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   993
	assert(spec->sclass == STAT_CLASS_DFLT || spec->sclass == STAT_CLASS_WAYP);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
   994
	sclass = spec->sclass - 1;
400
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
   995
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
   996
	if (spec->localidx != 0) {
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
   997
		/* Already allocated, try to resolve to global stid */
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
   998
		int i;
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
   999
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1000
		for (i = 0; i <= _statspec_highest_id[sclass]; i++) {
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1001
			if (_station_spec[sclass][i].grfid == spec->grfid
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1002
			    && _station_spec[sclass][i].localidx == local_stid + 1) {
400
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1003
				stid = i;
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1004
				/* FIXME: Release original SpriteGroup to
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1005
				 * prevent leaks. But first we need to
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1006
				 * refcount the SpriteGroup. --pasky */
400
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1007
				break;
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1008
			}
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1009
		}
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1010
	}
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1011
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1012
	if (stid == -1) {
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1013
		/* Allocate new one. */
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1014
		if (_statspec_highest_id[sclass] >= 255) {
400
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1015
			error("Too many custom stations allocated.");
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1016
			return;
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1017
		}
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1018
		stid = ++_statspec_highest_id[sclass];
400
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1019
		spec->localidx = local_stid + 1;
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1020
	}
d0608455bb77 (svn r592) -newgrf: Dynamically allocate global custom station IDs (pasky).
darkvater
parents: 399
diff changeset
  1021
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1022
	//debug("Registering station #%d of class %d", stid, sclass);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1023
	memcpy(&_station_spec[sclass][stid], spec, sizeof(*spec));
399
ad3dcbfd2d48 (svn r591) -newgrf: Store whole struct StationSpec in SetCustomStation(), not just the rendering data. This will be needed for variational stationspecs (pasky).
darkvater
parents: 389
diff changeset
  1024
}
ad3dcbfd2d48 (svn r591) -newgrf: Store whole struct StationSpec in SetCustomStation(), not just the rendering data. This will be needed for variational stationspecs (pasky).
darkvater
parents: 389
diff changeset
  1025
438
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 433
diff changeset
  1026
struct StationSpec *GetCustomStation(enum StationClass sclass, byte stid)
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 384
diff changeset
  1027
{
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1028
	assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1029
	sclass--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1030
	//debug("Asking for station #%d of class %d", stid, sclass);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1031
	if (stid > _statspec_highest_id[sclass])
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 384
diff changeset
  1032
		return NULL;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1033
	return &_station_spec[sclass][stid];
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 400
diff changeset
  1034
}
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 400
diff changeset
  1035
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1036
static struct RealSpriteGroup *
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1037
ResolveStationSpriteGroup(struct SpriteGroup *spritegroup, struct Station *stat)
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1038
{
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1039
	switch (spritegroup->type) {
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1040
		case SGT_REAL:
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1041
			return &spritegroup->g.real;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1042
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1043
		case SGT_DETERMINISTIC: {
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1044
			struct DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1045
			struct SpriteGroup *target;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1046
			int value = -1;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1047
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1048
			if ((dsg->variable >> 6) == 0) {
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1049
				/* General property */
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1050
				value = GetDeterministicSpriteValue(dsg->variable);
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1051
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1052
			} else {
433
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1053
				if (stat == NULL) {
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1054
					/* We are in a build dialog of something,
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1055
					 * and we are checking for something undefined.
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1056
					 * That means we should get the first target
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1057
					 * (NOT the default one). */
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1058
					if (dsg->num_ranges > 0) {
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1059
						target = &dsg->ranges[0].group;
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1060
					} else {
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1061
						target = dsg->default_group;
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1062
					}
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1063
					return ResolveStationSpriteGroup(target, NULL);
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1064
				}
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1065
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1066
				/* Station-specific property. */
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1067
				if (dsg->var_scope == VSG_SCOPE_PARENT) {
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1068
					/* TODO: Town structure. */
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1069
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1070
				} else /* VSG_SELF */ {
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1071
					if (dsg->variable == 0x40
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1072
					    || dsg->variable == 0x41) {
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1073
						/* FIXME: This is ad hoc only
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1074
						 * for waypoints. */
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1075
						value = 0x01010000;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1076
					} else {
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1077
						/* TODO: Only small fraction done. */
426
bd6f3c2cad9f (svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents: 413
diff changeset
  1078
						// TTDPatch runs on little-endian arch;
bd6f3c2cad9f (svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents: 413
diff changeset
  1079
						// Variable is 0x70 + offset in the TTD's station structure
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1080
						switch (dsg->variable - 0x70) {
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1081
							case 0x80:
433
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1082
								value = stat->facilities;
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1083
								break;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1084
							case 0x81:
433
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1085
								value = stat->airport_type;
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1086
								break;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1087
							case 0x82:
433
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1088
								value = stat->truck_stop_status;
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1089
								break;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1090
							case 0x83:
433
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1091
								value = stat->bus_stop_status;
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1092
								break;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1093
							case 0x86:
433
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1094
								value = stat->airport_flags & 0xFFFF;
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1095
								break;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1096
							case 0x87:
433
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1097
								value = stat->airport_flags & 0xFF;
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1098
								break;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1099
							case 0x8A:
433
00c1c7a58672 (svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents: 426
diff changeset
  1100
								value = stat->build_date;
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1101
								break;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1102
						}
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1103
					}
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1104
				}
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1105
			}
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1106
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1107
			target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1108
			return ResolveStationSpriteGroup(target, stat);
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1109
		}
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1110
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1111
		default:
445
0e3fa3da3899 (svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents: 438
diff changeset
  1112
		case SGT_RANDOMIZED:
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1113
			error("I don't know how to handle random spritegroups yet!");
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1114
			return NULL;
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1115
	}
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1116
}
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1117
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1118
uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat, byte ctype)
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 400
diff changeset
  1119
{
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1120
	struct RealSpriteGroup *rsg;
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1121
413
36afcda97345 (svn r610) -newgrf: Support for some basic deterministical spritegroups regarding stations. Waypoints look changes based on year now :^) (pasky).
darkvater
parents: 408
diff changeset
  1122
	rsg = ResolveStationSpriteGroup(&spec->spritegroup[ctype], stat);
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1123
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1124
	if (rsg->sprites_per_set != 0) {
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1125
		if (rsg->loading_count != 0) {
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1126
			return rsg->loading[0];
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1127
		} else if (rsg->loading_count != 0) {
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1128
			return rsg->loaded[0];
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1129
		}
403
bfb365c74e80 (svn r600) -newgrf: Relocation offset for custom station sprites is now stored separately, making it possible to show different sprites in waypoint selection dialog (pasky).
darkvater
parents: 400
diff changeset
  1130
	}
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1131
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1132
	error("Custom station 0x%08x::0x%02x has no sprites associated.",
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1133
	       spec->grfid, spec->localidx);
452
520e4ed6945d (svn r662) [newgrf] Moved grfspecial.c to newgrf.c/newgrf.h
dominik
parents: 449
diff changeset
  1134
	/* This is what gets subscribed of dtss->image in newgrf.c,
408
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1135
	 * so it's probably kinda "default offset". Try to use it as
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1136
	 * emergency measure. */
63a8c0505aab (svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents: 405
diff changeset
  1137
	return 0x42D;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 384
diff changeset
  1138
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 384
diff changeset
  1139
438
79b5df3f394a (svn r647) Cleanup custom station classes handling. (pasky)
miham
parents: 433
diff changeset
  1140
int GetCustomStationsCount(enum StationClass sclass)
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 384
diff changeset
  1141
{
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1142
	assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1143
	sclass--;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1144
	return _statspec_highest_id[sclass] + 1;
389
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 384
diff changeset
  1145
}
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 384
diff changeset
  1146
2d394eeba5e5 (svn r581) -newgrf: Basic support for new stations - only waypoints supported now and only
celestar
parents: 384
diff changeset
  1147
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1148
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
  1149
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	int w,h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1153
	/* 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
  1154
	if (_current_player == OWNER_WATER && _patches.nonuniform_stations)
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1155
		return DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  1156
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	/* Current player owns the station? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
	/* determine width and height of platforms */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	tile = st->train_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	w = st->trainst_w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
	h = st->trainst_h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1165
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
	assert(w != 0 && h != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
	/* cost is area * constant */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
	cost = w*h*_price.remove_rail_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	/* clear all areas of the station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
		int w_bak = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
			// for nonuniform stations, only remove tiles that are actually train station tiles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
			if (TileBelongsToRailStation(st, tile)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
				if (!EnsureNoVehicle(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
					return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
				if (flags & DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
					DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
			tile += TILE_XY(1, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
		} while (--w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
		w = w_bak;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
		tile = tile + TILE_XY(-w, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
	} while (--h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
		st->train_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
		st->facilities &= ~FACIL_TRAIN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1195
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
int32 DoConvertStationRail(uint tile, uint totype, bool exec)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
	st = DEREF_STATION(_map2[tile]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
	if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	// tile is not a railroad station?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	if (_map5[tile] >= 8) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	// tile is already of requested type?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
	if ( (uint)(_map3_lo[tile] & 0xF) == totype) return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
	if (exec) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
		// change type.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
		_map3_lo[tile] = (_map3_lo[tile] & 0xF0) + totype;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	return _price.build_rail >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
/* Build a bus station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
 * p1 - direction
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
 * p2 - unused
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
int32 CmdBuildBusStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	tile = TILE_FROM_XY(x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
	if ((cost=CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL)) == CMD_ERROR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
	st = GetStationAround(tile, 1, 1, -1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
	if (st == CHECK_STATIONS_ERR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
	/* Find a station close to us */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
		st = GetClosestStationFromTile(tile, 8, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
		if (st!=NULL && st->facilities) st = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
	if (st != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
		if (st->owner != OWNER_NONE && st->owner != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
			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
  1255
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		if (!CheckStationSpreadOut(st, tile, 1, 1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
		if (st->bus_tile != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
			return_cmd_error(STR_3044_TOO_CLOSE_TO_ANOTHER_BUS);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
		Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
		st = AllocateStation();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
		if (st == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
		st->town = t = ClosestTownFromTile(tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
		if (_current_player < MAX_PLAYERS && flags&DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
			SETBIT(t->have_ratings, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
		if (!GenerateStationName(st, tile, 0))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
		if (flags & DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
			StationInitialize(st, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	cost += _price.build_bus_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
		st->bus_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
		if (!st->facilities) st->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
		st->facilities |= FACIL_BUS_STOP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
		st->bus_stop_status = 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
		st->owner = _current_player;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1290
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  1291
		st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1293
		ModifyTile(tile,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
			MP_MAP2 | MP_MAP5 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
			st->index,			/* map2 parameter */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
			p1 + 0x47       /* map5 parameter */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
		UpdateStationAcceptance(st, false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
		InvalidateWindow(WC_STATION_LIST, st->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
// Remove a bus station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
static int32 RemoveBusStation(Station *st, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
	tile = st->bus_tile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1316
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
	if (!EnsureNoVehicle(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
		DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
		st->bus_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
		st->facilities &= ~FACIL_BUS_STOP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1330
	return _price.remove_bus_station;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
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
/* Build a truck station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
 * p1 - direction
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
 * p2 - unused
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
int32 CmdBuildTruckStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
	int32 cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
	tile = TILE_FROM_XY(x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
	if ((cost=CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL)) == CMD_ERROR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
	st = GetStationAround(tile, 1, 1, -1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
	if (st == CHECK_STATIONS_ERR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
	/* Find a station close to us */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
		st = GetClosestStationFromTile(tile, 8, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
		if (st!=NULL && st->facilities) st = NULL;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
	if (st != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
		if (st->owner != OWNER_NONE && st->owner != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
			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
  1367
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
		if (!CheckStationSpreadOut(st, tile, 1, 1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
		if (st->lorry_tile != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
			return_cmd_error(STR_3045_TOO_CLOSE_TO_ANOTHER_TRUCK);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
		Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
		st = AllocateStation();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
		if (st == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
		st->town = t = ClosestTownFromTile(tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
		if (_current_player < MAX_PLAYERS && flags&DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
			SETBIT(t->have_ratings, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
		if (!GenerateStationName(st, tile, 0))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
		if (flags & DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
			StationInitialize(st, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
	cost += _price.build_truck_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
		st->lorry_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
		if (!st->facilities) st->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
		st->facilities |= FACIL_TRUCK_STOP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
		st->truck_stop_status = 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
		st->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  1403
		st->build_date = _date;
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  1404
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1405
		ModifyTile(tile,
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1406
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
			st->index,			/* map2 parameter */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
			p1 + 0x43       /* map5 parameter */
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
		UpdateStationAcceptance(st, false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
		InvalidateWindow(WC_STATION_LIST, st->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
// Remove a truck station
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
static int32 RemoveTruckStation(Station *st, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
		return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1426
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
	tile = st->lorry_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
	if (!EnsureNoVehicle(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
		DoClearSquare(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1434
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
		st->lorry_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
		st->facilities &= ~FACIL_TRUCK_STOP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1442
	return _price.remove_truck_station;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
// FIXME -- need to move to its corresponding Airport variable
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
// Country Airfield (small)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
static const byte _airport_map5_tiles_country[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
	54, 53, 52, 65,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
	58, 57, 56, 55,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
	64, 63, 63, 62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
// City Airport (large)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
static const byte _airport_map5_tiles_town[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
	31, 9, 33, 9, 9, 32,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
	27, 36, 29, 34, 8, 10,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
	30, 11, 35, 13, 20, 21,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
	51, 12, 14, 17, 19, 28,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
	38, 13, 15, 16, 18, 39,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	26, 22, 23, 24, 25, 26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
// Metropolitain Airport (large) - 2 runways
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
static const byte _airport_map5_tiles_metropolitan[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
	31, 9, 33, 9, 9, 32,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
	27, 36, 29, 34, 8, 10,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
	30, 11, 35, 13, 20, 21,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
 102,  8,  8,  8,  8, 28,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
	83, 84, 84, 84, 84, 83,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
	26, 23, 23, 23, 23, 26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
// International Airport (large) - 2 runways
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
static const byte _airport_map5_tiles_international[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
  88, 89, 89, 89, 89, 89, 88,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
 	51,  8,  8,  8,  8,  8, 32,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
	30,  8, 11, 27, 11,  8, 10,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
	32,  8, 11, 27, 11,  8, 114,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
	87,  8, 11, 85, 11,  8, 114,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
	87,  8,  8,  8,  8,  8, 90,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
	26, 23, 23, 23, 23, 23, 26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
// Heliport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
static const byte _airport_map5_tiles_heliport[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
	66,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
};
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
static const byte * const _airport_map5_tiles[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
	_airport_map5_tiles_country,				// Country Airfield (small)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
	_airport_map5_tiles_town,						// City Airport (large)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
	_airport_map5_tiles_heliport,				// Heliport
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1493
	_airport_map5_tiles_metropolitan,   // Metropolitain Airport (large)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
	_airport_map5_tiles_international,	// International Airport (xlarge)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
/* Place an Airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1498
 * p1 - airport type
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
 * p2 - unused
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
	int w,h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1508
	bool airport_upgrade = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	tile = TILE_FROM_XY(x,y);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1513
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
	t = ClosestTownFromTile(tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
	/* Check if local auth refuses a new airport */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
		uint num = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
			if (st->xy != 0 && st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
				num++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
		if (num >= 2) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1527
			SetDParam(0, t->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
			return_cmd_error(STR_2035_LOCAL_AUTHORITY_REFUSES);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
	w = _airport_size_x[p1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
	h = _airport_size_y[p1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
	cost = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
	if (cost == CMD_ERROR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
	st = GetStationAround(tile, w, h, -1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
	if (st == CHECK_STATIONS_ERR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
	/* Find a station close to us */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
		st = GetClosestStationFromTile(tile, 8, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
		if (st!=NULL && st->facilities) st = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
	if (st != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
		if (st->owner != OWNER_NONE && st->owner != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
			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
  1552
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
		if (!CheckStationSpreadOut(st, tile, 1, 1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
		if (st->airport_tile != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
			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
  1558
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
		Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
		airport_upgrade = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
		st = AllocateStation();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
		if (st == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
		st->town = t = ClosestTownFromTile(tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
		if (_current_player < MAX_PLAYERS && flags&DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
			SETBIT(t->have_ratings, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
		// if airport type equals Heliport then generate
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
		// type 5 name, which is heliport, otherwise airport names (1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
		if (!GenerateStationName(st, tile, p1 == AT_HELIPORT ? 5 : 1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
			return CMD_ERROR;
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
		if (flags & DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
			StationInitialize(st, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
	cost += _price.build_airport * w * h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
		st->owner = _current_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
		if (_current_player == _local_player && p1 <= AT_INTERNATIONAL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
      _last_built_aircraft_depot_tile = tile + GetAirport(p1)->airport_depots[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
    }
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
		st->airport_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
		if (!st->facilities) st->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
		st->facilities |= FACIL_AIRPORT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1594
		st->airport_type = (byte)p1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
		st->airport_flags = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1596
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  1597
		st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
		/*	if airport was demolished while planes were en-route to it, the positions can no longer
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
				be the same (v->u.air.pos), since different airports have different indexes. So update
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
				all planes en-route to this airport. Only update if
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
				1. airport is upgraded
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
				2. airport is added to existing station (unfortunately unavoideable)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
		*/
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
		if (airport_upgrade) {UpdateAirplanesOnNewStation(st);}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1606
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
			const byte *b = _airport_map5_tiles[p1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
BEGIN_TILE_LOOP(tile_cur,w,h,tile)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1610
				ModifyTile(tile_cur,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
					MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
					MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1613
					st->index, *b++);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1614
END_TILE_LOOP(tile_cur,w,h,tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1616
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
		UpdateStationAcceptance(st, false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
		InvalidateWindow(WC_STATION_LIST, st->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
static int32 RemoveAirport(Station *st, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
	int w,h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
	int32 cost;
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
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
	tile = st->airport_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	w = _airport_size_x[st->airport_type];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
	h = _airport_size_y[st->airport_type];
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 = w * h * _price.remove_airport;
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
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
BEGIN_TILE_LOOP(tile_cur,w,h,tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
		if (!EnsureNoVehicle(tile_cur))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
		if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
			DeleteAnimatedTile(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
			DoClearSquare(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
END_TILE_LOOP(tile_cur, w,h,tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
	if (flags & DC_EXEC) {
700
c973846fe239 (svn r1150) Fixes:
tron
parents: 679
diff changeset
  1654
		const AirportFTAClass *afc = GetAirport(st->airport_type);
c973846fe239 (svn r1150) Fixes:
tron
parents: 679
diff changeset
  1655
		uint i;
c973846fe239 (svn r1150) Fixes:
tron
parents: 679
diff changeset
  1656
c973846fe239 (svn r1150) Fixes:
tron
parents: 679
diff changeset
  1657
		for (i = 0; i < afc->nof_depots; ++i)
c973846fe239 (svn r1150) Fixes:
tron
parents: 679
diff changeset
  1658
			DeleteWindowById(WC_VEHICLE_DEPOT,
c973846fe239 (svn r1150) Fixes:
tron
parents: 679
diff changeset
  1659
				tile + GetAirport(st->airport_type)->airport_depots[i]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
		st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
		st->facilities &= ~FACIL_AIRPORT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1663
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
		DeleteStationIfEmpty(st);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
	return cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1668
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1670
/* Build a buoy
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
 * p1,p2 unused
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
int32 CmdBuildBuoy(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
	FindLandscapeHeight(&ti, x, y);
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 (ti.type != MP_WATER || ti.tileh != 0 || ti.map5 != 0 || ti.tile == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
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
	st = AllocateStation();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
	if (st == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
	st->town = ClosestTownFromTile(ti.tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
	st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
	if (!GenerateStationName(st, ti.tile, 4))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1694
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1695
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
		StationInitialize(st, ti.tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
		st->dock_tile = ti.tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
		st->facilities |= FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1700
		st->had_vehicle_of_type |= HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
		st->owner = OWNER_NONE;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1702
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  1703
		st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
		ModifyTile(ti.tile,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
			MP_SETTYPE(MP_STATION) |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
			st->index,		/* map2 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
			OWNER_NONE,		/* map_owner */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
			0x52					/* map5 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
		UpdateStationVirtCoordDirty(st);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1714
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
		UpdateStationAcceptance(st, false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
		InvalidateWindow(WC_STATION_LIST, st->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
	return _price.build_dock;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
static int32 RemoveBuoy(Station *st, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
	uint tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
	if (_current_player >= MAX_PLAYERS) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
		/* XXX: strange stuff */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
		return_cmd_error(INVALID_STRING_ID);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
	tile = st->dock_tile;
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
	if (!EnsureNoVehicle(tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
		st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
		st->had_vehicle_of_type &= ~HVOT_BUOY;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1741
		ModifyTile(tile,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
			MP_SETTYPE(MP_WATER) |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
			MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
			OWNER_WATER, /* map_owner */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
			0			/* map5 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
	return _price.remove_truck_station;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
static const TileIndexDiff _dock_tileoffs_chkaround[4] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
	TILE_XY(-1,0),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
	0,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
	TILE_XY(0,-1),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
static const byte _dock_w_chk[4] = { 2,1,2,1 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
static const byte _dock_h_chk[4] = { 1,2,1,2 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1766
	int direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1767
	int32 cost;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
	uint tile, tile_cur;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1769
	Station *st;
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
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
	FindLandscapeHeight(&ti, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
	if ((direction=0,ti.tileh) != 3 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
			(direction++,ti.tileh) != 9 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
			(direction++,ti.tileh) != 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1778
			(direction++,ti.tileh) != 6)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1779
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1780
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
	if (!EnsureNoVehicle(ti.tile))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
	cost = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
	if (cost == CMD_ERROR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1786
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1787
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1788
	tile_cur = (tile=ti.tile) + _tileoffs_by_dir[direction];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
	if (!EnsureNoVehicle(tile_cur))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1792
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
	FindLandscapeHeightByTile(&ti, tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1794
	if (ti.tileh != 0 || ti.type != MP_WATER)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1796
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
	cost = DoCommandByTile(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
	if (cost == CMD_ERROR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
		return CMD_ERROR;
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
	tile_cur = tile_cur + _tileoffs_by_dir[direction];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
	FindLandscapeHeightByTile(&ti, tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
	if (ti.tileh != 0 || ti.type != MP_WATER)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1805
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
	/* middle */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1807
	st = GetStationAround(tile + _dock_tileoffs_chkaround[direction],
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
		_dock_w_chk[direction], _dock_h_chk[direction], -1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
	if (st == CHECK_STATIONS_ERR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
		return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1811
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1812
	/* Find a station close to us */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
	if (st == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
		st = GetClosestStationFromTile(tile, 8, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
		if (st!=NULL && st->facilities) st = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
	if (st != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
		if (st->owner != OWNER_NONE && st->owner != _current_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
			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
  1821
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
		if (!CheckStationSpreadOut(st, tile, 1, 1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
			return CMD_ERROR;
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
		if (st->dock_tile != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
			return_cmd_error(STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1828
		Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1829
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
		st = AllocateStation();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
		if (st == NULL)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
		st->town = t = ClosestTownFromTile(tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1835
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
		if (_current_player < MAX_PLAYERS && flags&DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1837
			SETBIT(t->have_ratings, _current_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1838
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
		st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
		if (!GenerateStationName(st, tile, 3))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1842
			return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1843
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1844
		if (flags & DC_EXEC)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
			StationInitialize(st, tile);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
		st->dock_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
		if (!st->facilities) st->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1851
		st->facilities |= FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1852
		st->owner = _current_player;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1853
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  1854
		st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1855
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1856
		ModifyTile(tile,
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1857
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1859
			MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1860
			st->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1861
			direction + 0x4C);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1863
		ModifyTile(tile + _tileoffs_by_dir[direction],
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1864
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR |
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
			MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
			st->index,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
			(direction&1) + 0x50);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  1869
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
		UpdateStationAcceptance(st, false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
		InvalidateWindow(WC_STATION_LIST, st->owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
	return _price.build_dock;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
static int32 RemoveDock(Station *st, uint32 flags)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1878
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
	uint tile1, tile2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
	if (!CheckOwnership(st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
	tile1 = st->dock_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
	tile2 = tile1 + _tileoffs_by_dir[_map5[tile1] - 0x4C];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
	if (!EnsureNoVehicle(tile1))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
	if (!EnsureNoVehicle(tile2))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
		return CMD_ERROR;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
		DoClearSquare(tile1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1895
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1896
		// convert the water tile to water.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
		ModifyTile(tile2, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR, OWNER_WATER, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
		st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
		st->facilities &= ~FACIL_DOCK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
		UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
		DeleteStationIfEmpty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
	return _price.remove_dock;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
#include "table/station_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1912
extern uint16 _custom_sprites_base;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1913
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
static void DrawTile_Station(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
	uint32 image_or_modificator;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1917
	uint32 image;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
	const DrawTileSeqStruct *dtss;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1919
	const DrawTileSprites *t = NULL;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1920
	byte railtype = _map3_lo[ti->tile] & 0xF;
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1921
	uint32 relocation = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
		uint owner = _map_owner[ti->tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
		image_or_modificator = 0x315 << 16; /* NOTE: possible bug in ttd here? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
		if (owner < MAX_PLAYERS)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
			image_or_modificator = PLAYER_SPRITE_COLOR(owner);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	// don't show foundation for docks (docks are between 76 (0x4C) and 81 (0x51))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
	if (ti->tileh != 0 && (ti->map5 < 0x4C || ti->map5 > 0x51))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
		DrawFoundation(ti, ti->tileh);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1934
	if (_map3_lo[ti->tile] & 0x10) {
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1935
		// look for customization
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1936
		struct StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _map3_hi[ti->tile]);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1937
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1938
		//debug("Cust-o-mized %p", statspec);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1939
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1940
		if (statspec != NULL) {
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1941
			Station *st = DEREF_STATION(_map2[ti->tile]);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1942
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1943
			relocation = GetCustomStationRelocation(statspec, st, 0);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1944
			//debug("Relocation %d", relocation);
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1945
			t = &statspec->renderdata[ti->map5];
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1946
		}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1947
	}
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1948
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1949
	if (t == NULL) t = &_station_display_datas[ti->map5];
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1950
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1951
	image = t->ground_sprite;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
	if (image & 0x8000)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
		image |= image_or_modificator;
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1954
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1955
	// station_land array has been increased from 82 elements to 114
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1956
	// but this is something else. If AI builds station with 114 it looks all weird
457
f656a2ff7b6c (svn r667) Fix bug in rendering stations from savegames
tron
parents: 452
diff changeset
  1957
	image += railtype * ((image & 0x3FFF) < _custom_sprites_base ? TRACKTYPE_SPRITE_PITCH : 1);
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1958
	DrawGroundSprite(image);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1959
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1960
	foreach_draw_tile_seq(dtss, t->seq) {
449
d9325d9f24bb (svn r659) Support for cutomized TTDPatch-style new stations (no selector GUI yet) (pasky)
tron
parents: 445
diff changeset
  1961
		image =	dtss->image + relocation;
457
f656a2ff7b6c (svn r667) Fix bug in rendering stations from savegames
tron
parents: 452
diff changeset
  1962
		// For custom sprites, there's no railtype-based pitching.
f656a2ff7b6c (svn r667) Fix bug in rendering stations from savegames
tron
parents: 452
diff changeset
  1963
		image += railtype * ((image & 0x3FFF) < _custom_sprites_base ? TRACKTYPE_SPRITE_PITCH : 0);
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1964
		if (_display_opt & DO_TRANS_BUILDINGS) {
497
2d6d31173813 (svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents: 494
diff changeset
  1965
			image = (image & 0x3FFF) | 0x03224000;
2d6d31173813 (svn r787) Invert the sense of the DO_TRANS_BUILDINGS flag to be consistent with its own name and all other DO_* flags.
tron
parents: 494
diff changeset
  1966
		} else {
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1967
			if (image&0x8000) image |= image_or_modificator;	
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1968
		}
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1969
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
		if ((byte)dtss->delta_z != 0x80) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
			AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y, dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1972
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
			AddChildSpriteScreen(image, dtss->delta_x, dtss->delta_y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1977
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
void StationPickerDrawSprite(int x, int y, int railtype, int image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
	uint32 ormod, img;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
	const DrawTileSeqStruct *dtss;
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1982
	const DrawTileSprites *t;
0
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
	/* baseimage */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1985
	railtype *= TRACKTYPE_SPRITE_PITCH;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1986
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1987
	ormod = PLAYER_SPRITE_COLOR(_local_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1988
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1989
	t = &_station_display_datas[image];
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1990
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1991
	img = t->ground_sprite;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1992
	if (img & 0x8000)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1993
		img |= ormod;
354
d9a179673155 (svn r542) -Fix: Display correct rail type in "build railway station" window
tron
parents: 313
diff changeset
  1994
	DrawSprite(img + railtype, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1995
384
bf1303e754ff (svn r576) -newgrf: Cleanup horrible table/(station|unmovable)_land.h DrawTileSeqStruct hacks needed for custom station supports (pasky)
darkvater
parents: 354
diff changeset
  1996
	foreach_draw_tile_seq(dtss, t->seq) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1997
		Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1998
		DrawSprite((dtss->image | ormod) + railtype, x + pt.x, y + pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1999
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2002
static uint GetSlopeZ_Station(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
	uint z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
	if (ti->tileh != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
		z += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2007
	return z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2008
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2009
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2010
static uint GetSlopeTileh_Station(TileInfo *ti)
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2011
{
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2012
	return 0;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2013
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2014
473
0da86c59e3ae (svn r724) Remove restriction that a tile can only accept 3 cargo types.
tron
parents: 457
diff changeset
  2015
static void GetAcceptedCargo_Station(uint tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2017
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2019
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2020
static void GetTileDesc_Station(uint tile, TileDesc *td)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2022
	byte m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2023
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2024
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2025
	td->owner = _map_owner[tile];
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  2026
	td->build_date = DEREF_STATION(_map2[tile])->build_date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2027
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2028
	m5 = _map5[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2029
	(str=STR_305E_RAILROAD_STATION, m5 < 8) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2030
	(str=STR_305F_AIRCRAFT_HANGAR, m5==32 || m5==45) || // hangars
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2031
	(str=STR_3060_AIRPORT, m5 < 0x43 || (m5 >= 83 && m5 <= 114)) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2032
	(str=STR_3061_TRUCK_LOADING_AREA, m5 < 0x47) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2033
	(str=STR_3062_BUS_STATION, m5 < 0x4B) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2034
	(str=STR_4807_OIL_RIG, m5 == 0x4B) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
	(str=STR_3063_SHIP_DOCK, m5 != 0x52) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
	(str=STR_3069_BUOY, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
	td->str = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2038
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2041
static const byte _tile_track_status_rail[8] = { 1,2,1,2,1,2,1,2 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  2043
static uint32 GetTileTrackStatus_Station(uint tile, TransportType mode) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
	uint i = _map5[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
	uint j = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2046
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  2047
	if (mode == TRANSPORT_RAIL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
		if (i < 8)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2049
			j = _tile_track_status_rail[i];
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  2050
		j += (j << 8);
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  2051
	} else if (mode == TRANSPORT_WATER) {
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  2052
		// buoy is coded as a station, it is always on open water
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  2053
		// (0x3F, all tracks available)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
		if (i == 0x52) j = 0x3F;
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  2055
		j += (j << 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2056
	}
159
139cf78bfb28 (svn r160) -Codechange: made GetTileTrackStatus more readable (blathijs)
truelight
parents: 149
diff changeset
  2057
	return j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2058
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2060
static void TileLoop_Station(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2061
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2062
  //FIXME -- GetTileTrackStatus_Station -> animated stationtiles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
  // hardcoded.....not good
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
  // 0x27 - large big airport (39)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2065
  // 0x66 - radar metropolitan airport (102)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2066
  // 0x5A - radar international airport (90)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2067
  // 0x3A - flag small airport (58)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2068
	if (_map5[tile] == 39 || _map5[tile] == 58 || _map5[tile] == 90 || _map5[tile] == 102)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2069
		AddAnimatedTile(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2070
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2071
	// treat a bouy tile as water.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2072
	else if (_map5[tile] == 0x52)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2073
		TileLoop_Water(tile);
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  2074
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  2075
	// treat a oilrig (the station part) as water
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  2076
	else if (_map5[tile] == 0x4B)
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  2077
		TileLoop_Water(tile);
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
  2078
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2081
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2082
static void AnimateTile_Station(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2083
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
	byte m5 = _map5[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
	//FIXME -- AnimateTile_Station -> not nice code, lots of things double
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
  // again hardcoded...was a quick hack
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
  // turning radar / windsack on airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
	if (m5 >= 39 && m5 <= 50) { // turning radar (39 - 50)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
		if (_tick_counter & 3)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
			return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2092
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
		if (++m5 == 50+1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
			m5 = 39;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2096
		_map5[tile] = m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
  //added - begin
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
	} else if (m5 >= 90 && m5 <= 113) { // turning radar with ground under it (different fences) (90 - 101 | 102 - 113)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2100
		if (_tick_counter & 3)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
			return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2102
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
		m5++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2104
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2105
		if (m5 == 101+1) {m5 = 90;}  // radar with fences in south
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
		else if (m5 == 113+1) {m5 = 102;} // radar with fences in north
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
		_map5[tile] = m5;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2109
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
	//added - end
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2111
	} else if (m5 >= 0x3A && m5 <= 0x3D) {  // windsack (58 - 61)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
		if (_tick_counter & 1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2113
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2114
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
		if (++m5 == 0x3D+1)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
			m5 = 0x3A;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2117
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
		_map5[tile] = m5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2119
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2122
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
static void ClickTile_Station(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2124
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2125
  // 0x20 - hangar large airport (32)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
  // 0x41 - hangar small airport (65)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
	if (_map5[tile] == 32 || _map5[tile] == 65) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2128
		ShowAircraftDepotWindow(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2129
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2130
		ShowStationViewWindow(_map2[tile]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2133
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 497
diff changeset
  2134
static inline bool IsTrainStationTile(uint tile) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
	return IS_TILETYPE(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0, 8);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2138
static const byte _enter_station_speedtable[12] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2139
	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
  2140
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2141
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2142
static uint32 VehicleEnter_Station(Vehicle *v, uint tile, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
	byte station_id;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2145
	byte dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2146
	uint16 spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2148
	if (v->type == VEH_Train) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2149
		if (IS_BYTE_INSIDE(_map5[tile], 0, 8) && v->subtype == 0 &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
			!IsTrainStationTile(tile + _tileoffs_by_dir[v->direction >> 1])) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2151
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2152
			station_id = _map2[tile];
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2153
			if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2154
					(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) {
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2155
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2156
				if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) &&
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2157
						v->current_order.type != OT_LEAVESTATION &&
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2158
						v->last_station_visited != station_id) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
					x &= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2160
					y &= 0xF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2161
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
					dir = v->direction & 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
					if (dir & 2) intswap(x,y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2164
					if (y == 8) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
						if (dir != 2 && dir != 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2166
							x = (~x)&0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2167
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2168
						if (x == 12) return 2 | (station_id << 8); /* enter station */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
						if (x < 12) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2170
							v->vehstatus |= VS_TRAIN_SLOWING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2171
							spd = _enter_station_speedtable[x];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2172
							if (spd < v->cur_speed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
								v->cur_speed = spd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
						}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2175
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2176
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2177
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2178
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2179
	} else if (v->type == VEH_Road) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2180
		if (v->u.road.state < 16 && (v->u.road.state&4)==0 && v->u.road.frame==0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2181
			Station *st = DEREF_STATION(_map2[tile]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2182
			byte m5 = _map5[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2183
			byte *b, bb,state;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2184
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2185
			if (IS_BYTE_INSIDE(m5, 0x43, 0x4B)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2186
				b = (m5 >= 0x47) ? &st->bus_stop_status : &st->truck_stop_status;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2188
				bb = *b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2189
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2190
				/* bb bits 1..0 describe current the two parking spots.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2191
				0 means occupied, 1 means free. */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2192
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2193
				// Station busy?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2194
				if (bb & 0x80 || (bb&3) == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2195
					return 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2196
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2197
				state = v->u.road.state + 32;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
				if (bb & 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2199
					bb &= ~1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2200
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2201
					bb &= ~2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2202
					state += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2203
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2204
				*b = bb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2205
				v->u.road.state = state;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2206
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2207
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2208
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2209
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2210
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2211
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2212
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2213
static void DeleteStation(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2214
{
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2215
	Order order;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2216
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2217
	st->xy = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2219
	DeleteName(st->string_id);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2220
	MarkStationDirty(st);
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2221
	_global_station_sort_dirty = true; // delete station, remove sign
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 59
diff changeset
  2222
	InvalidateWindowClasses(WC_STATION_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2223
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2224
	index = st->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2225
	DeleteWindowById(WC_STATION_VIEW, index);
555
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2226
	order.type = OT_GOTO_STATION;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2227
	order.flags = 0;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2228
	order.station = index;
eec6c0294435 (svn r955) Replace uint16 for orders with struct Order
tron
parents: 543
diff changeset
  2229
	DeleteCommandFromVehicleSchedule(order);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2230
	DeleteSubsidyWithStation(index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2231
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2232
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2233
void DeleteAllPlayerStations()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2234
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2235
	Station *st;
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
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2238
		if (st->xy && st->owner < MAX_PLAYERS)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2239
			DeleteStation(st);
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2242
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2243
/* this function is called for one station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2244
static void StationHandleBigTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2245
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2246
	UpdateStationAcceptance(st, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2247
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2248
	if (st->facilities == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2249
		if (++st->delete_ctr >= 8)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2250
			DeleteStation(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2251
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2252
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2253
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 497
diff changeset
  2254
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
  2255
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2256
static byte _rating_boost[3] = { 0, 31, 63};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2257
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2258
static void UpdateStationRating(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2259
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2260
	GoodsEntry *ge;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2261
	int rating, index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2262
	int waiting;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2263
	bool waiting_changed = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2265
	byte_inc_sat(&st->time_since_load);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2266
	byte_inc_sat(&st->time_since_unload);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2268
	ge = st->goods;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2269
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2270
		if (ge->enroute_from != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2271
			byte_inc_sat(&ge->enroute_time);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2272
			byte_inc_sat(&ge->days_since_pickup);
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
			rating = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2276
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2277
				int b = ge->last_speed;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2278
				if ((b-=85) >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2279
					rating += b >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2280
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2281
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2282
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2283
				byte age = ge->last_age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2284
				(age >= 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2285
				(rating += 10, age >= 2) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2286
				(rating += 10, age >= 1) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2287
				(rating += 13, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2288
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2289
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2290
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2291
				if (!IS_HUMAN_PLAYER(st->owner) && st->owner != OWNER_NONE)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2292
							rating += _rating_boost[_opt.diff.competitor_intelligence];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2293
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2294
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2295
			if (st->owner < 8 && HASBIT(st->town->statues, st->owner))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2296
				rating += 26;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2297
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2298
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2299
				byte days = ge->days_since_pickup;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2300
				if (st->last_vehicle != INVALID_VEHICLE &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2301
						(&_vehicles[st->last_vehicle])->type == VEH_Ship)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2302
							days >>= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2303
				(days > 21) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2304
				(rating += 25, days > 12) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2305
				(rating += 25, days > 6) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2306
				(rating += 45, days > 3) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2307
				(rating += 35, true);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2308
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2309
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2310
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2311
				waiting = ge->waiting_acceptance & 0xFFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2312
				(rating -= 90, waiting > 1500) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2313
				(rating += 55, waiting > 1000) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2314
				(rating += 35, waiting > 600) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2315
				(rating += 10, waiting > 300) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2316
				(rating += 20, waiting > 100) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2317
				(rating += 10, true);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2320
			{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2321
				int or = ge->rating; // old rating
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2323
				// only modify rating in steps of -2, -1, 0, 1 or 2
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2324
				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
  2325
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2326
				// 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
  2327
				if (rating <= 64 && waiting >= 200) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2328
					int dec = Random() & 0x1F;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2329
					if (waiting < 400) dec &= 7;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2330
					waiting -= dec + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2331
					waiting_changed = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2332
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2333
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2334
				// 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
  2335
				if (rating <= 127 && waiting != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2336
					uint32 r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2337
					if ( (uint)rating <= (r & 0x7F) ) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2338
						waiting = max(waiting - ((r >> 8)&3) - 1, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2339
						waiting_changed = true;
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
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2342
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2343
				if (waiting_changed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2344
					ge->waiting_acceptance = (ge->waiting_acceptance & ~0xFFF) + waiting;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2345
			}
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
	} while (++ge != endof(st->goods));
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2348
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2349
	index = st->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2351
	if (waiting_changed)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2352
		InvalidateWindow(WC_STATION_VIEW, index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2353
	else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2354
		InvalidateWindowWidget(WC_STATION_VIEW, index, 5);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2357
/* called for every station each tick */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2358
static void StationHandleSmallTick(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2359
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2360
	byte b;
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
	if (st->facilities == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2363
		return;
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
	b = st->delete_ctr + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2366
	if (b >= 185) b = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2367
	st->delete_ctr = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2368
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2369
	if (b == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2370
		UpdateStationRating(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2371
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2372
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2373
void OnTick_Station()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2374
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2375
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2376
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2378
	if (_game_mode == GM_EDITOR)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2379
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2381
	i = _station_tick_ctr;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2382
	if (++_station_tick_ctr == lengthof(_stations))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2383
		_station_tick_ctr = 0;
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
	st = DEREF_STATION(i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2386
	if (st->xy != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2387
		StationHandleBigTick(st);
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
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2390
		if (st->xy != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2391
			StationHandleSmallTick(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2392
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2393
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2394
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2395
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2396
void StationMonthlyLoop()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2397
{
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2401
void ModifyStationRatingAround(TileIndex tile, byte owner, int amount, uint radius)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2402
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2403
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2404
	GoodsEntry *ge;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2405
	int i;
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
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2408
		if (st->xy != 0 && st->owner == owner && GetTileDist(tile, st->xy) <= radius) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2409
			ge = st->goods;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2410
			for(i=0; i!=NUM_CARGO; i++,ge++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2411
				if (ge->enroute_from != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2412
					ge->rating = clamp(ge->rating + amount, 0, 255);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2413
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2414
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2415
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2416
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2417
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2418
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2419
static void UpdateStationWaiting(Station *st, int type, uint amount)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2420
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2421
	st->goods[type].waiting_acceptance =
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2422
		(st->goods[type].waiting_acceptance & ~0xFFF) +
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2423
			min(0xFFF, (st->goods[type].waiting_acceptance & 0xFFF) + amount);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2424
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2425
	st->goods[type].enroute_time = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2426
	st->goods[type].enroute_from = st->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2427
	InvalidateWindow(WC_STATION_VIEW, st->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2428
}
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
int32 CmdRenameStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2431
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2432
	StringID str,old_str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2433
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2434
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 536
diff changeset
  2435
	str = AllocateNameUnique((byte*)_decode_parameters, 6);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2436
	if (str == 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2437
		return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2438
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2439
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2440
		st = DEREF_STATION(p1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2441
		old_str = st->string_id;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2442
		st->string_id = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2443
		UpdateStationVirtCoord(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2444
		DeleteName(old_str);
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2445
		_station_sort_dirty[st->owner] = true; // rename a station
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2446
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2447
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2448
		DeleteName(str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2449
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2451
	return 0;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2454
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2455
uint MoveGoodsToStation(uint tile, int w, int h, int type, uint amount)
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
	Station *around_ptr[8];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2458
	byte around[8], st_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2459
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2460
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2461
	uint moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2462
	uint best_rating, best_rating2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2463
	Station *st1, *st2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2464
	int t;
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2465
	int rad=0;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2466
	int w_prod=0, h_prod=0; //width and height of the "producer" of the cargo
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2467
	int x_min_prod, x_max_prod;     //min and max coordinates of the producer
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2468
	int y_min_prod, y_max_prod;     //relative
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2469
	int x_dist, y_dist;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2470
	int max_rad;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2471
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2472
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2473
	memset(around, 0xff, sizeof(around));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2474
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2475
	if (_patches.modified_catchment) {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2476
		w_prod = w;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2477
		h_prod = h;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2478
		w += 16;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2479
		h += 16;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2480
		max_rad = 8;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2481
	} else {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2482
 		w += 8;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2483
 		h += 8;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2484
		max_rad = 4;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2485
	}
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2486
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2487
	BEGIN_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(max_rad,max_rad))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2488
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2489
		if (IS_TILETYPE(cur_tile, MP_STATION)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2490
			st_index = _map2[cur_tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2491
			for(i=0; i!=8; i++)	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2492
				if (around[i] == 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2493
					st = DEREF_STATION(st_index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2494
					if ((st->had_vehicle_of_type & HVOT_BUOY) == 0 &&
121
c2f18f4d8be1 (svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents: 84
diff changeset
  2495
							( !st->town->exclusive_counter || (st->town->exclusivity == st->owner) ) && // check exclusive transport rights
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2496
							st->goods[type].rating != 0 &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2497
							(!_patches.selectgoods || st->goods[type].last_speed) && // if last_speed is 0, no vehicle has been there.
22
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  2498
							((st->facilities & (byte)~FACIL_BUS_STOP)!=0 || type==CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers
fe6f35cc987b (svn r23) -Some omments on the code (blathijs)
darkvater
parents: 0
diff changeset
  2499
							((st->facilities & (byte)~FACIL_TRUCK_STOP)!=0 || type!=CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2500
								if (_patches.modified_catchment) {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2501
									FIND_CATCHMENT_RADIUS(st,rad)
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2502
									x_min_prod = y_min_prod = 9;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2503
									x_max_prod = 8 + w_prod;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2504
									y_max_prod = 8 + h_prod;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2505
		
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2506
									x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur);
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2507
		
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2508
									if (w_cur < x_min_prod) {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2509
										x_dist = x_min_prod - w_cur;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2510
									} else {        //save cycles
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2511
										if (w_cur > x_max_prod) x_dist = w_cur - x_max_prod;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2512
									}
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2513
		
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2514
									y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur);
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2515
									if (h_cur < y_min_prod) {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2516
										y_dist = y_min_prod - h_cur;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2517
									} else {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2518
										if (h_cur > y_max_prod) y_dist = h_cur - y_max_prod;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2519
									}
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2520
		
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2521
								} else {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2522
									x_dist = y_dist = 0;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2523
								}
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2524
		
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2525
								if ( !(x_dist > rad) && !(y_dist > rad) ) {
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2526
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2527
									around[i] = st_index;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2528
									around_ptr[i] = st;
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2529
								}
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2530
							}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2531
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2532
				} else if (around[i] == st_index)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2533
					break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2534
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2535
		}
568
6eb7d394fb35 (svn r979) Allow more realistically sized catchment areas
Celestar
parents: 555
diff changeset
  2536
	END_TILE_LOOP(cur_tile, w, h, tile - TILE_XY(max_rad, max_rad))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2537
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2538
	/* no stations around at all? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2539
	if (around[0] == 0xFF)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2540
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2541
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2542
	if (around[1] == 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2543
		/* only one station around */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2544
		moved = (amount * around_ptr[0]->goods[type].rating >> 8) + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2545
		UpdateStationWaiting(around_ptr[0], type, moved);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2546
		return moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2547
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2548
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2549
	/* 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
  2550
	st2 = st1 = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2551
	best_rating = best_rating2 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2552
	for(i=0; i!=8 && around[i] != 0xFF; i++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2553
		if (around_ptr[i]->goods[type].rating >= best_rating) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2554
			best_rating2 = best_rating;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2555
			st2 = st1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2556
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2557
			best_rating = around_ptr[i]->goods[type].rating;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2558
			st1 = around_ptr[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2559
		} else if (around_ptr[i]->goods[type].rating >= best_rating2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2560
			best_rating2 = around_ptr[i]->goods[type].rating;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2561
			st2 = around_ptr[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2562
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2563
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2564
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2565
	assert(st1 != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2566
	assert(st2 != NULL);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2567
	assert(best_rating != 0 || best_rating2 != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2568
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2569
	/* the 2nd highest one gets a penalty */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2570
	best_rating2 >>= 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2571
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2572
	/* amount given to station 1 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2573
	t = (best_rating * (amount + 1)) / (best_rating + best_rating2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2574
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2575
	moved = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2576
	if (t != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2577
		moved = (t * best_rating >> 8) + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2578
		amount -= t;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2579
		UpdateStationWaiting(st1, type, moved);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2580
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2581
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2582
	assert(amount >= 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2583
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2584
	if (amount != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2585
		moved += (amount = (amount * best_rating2 >> 8) + 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2586
		UpdateStationWaiting(st2, type, amount);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2587
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2588
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2589
	return moved;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2590
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2591
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2592
void BuildOilRig(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2593
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2594
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2595
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2596
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2597
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2598
		if (st->xy == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2599
			st->town = ClosestTownFromTile(tile, (uint)-1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2600
			st->sign.width_1 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2601
			if (!GenerateStationName(st, tile, 2))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2602
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2603
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2604
			_map_type_and_height[tile] &= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2605
			_map_type_and_height[tile] |= MP_STATION << 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2606
			_map5[tile] = 0x4B;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2607
			_map_owner[tile] = OWNER_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2608
			_map3_lo[tile] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2609
			_map3_hi[tile] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2610
			_map2[tile] = st->index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2611
27
87c8058a69b5 (svn r28) -Fix removing station merged with oilrig, will reset oilrigs ownership
darkvater
parents: 22
diff changeset
  2612
			st->owner = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2613
      st->airport_flags = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2614
			st->airport_type = AT_OILRIG;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2615
			st->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2616
			st->bus_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2617
			st->lorry_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2618
			st->airport_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2619
			st->dock_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2620
			st->train_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2621
			st->had_vehicle_of_type = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2622
			st->time_since_load = 255;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2623
			st->time_since_unload = 255;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2624
			st->delete_ctr = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2625
			st->last_vehicle = INVALID_VEHICLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2626
			st->facilities = FACIL_AIRPORT | FACIL_DOCK;
71
1b8e15a10515 (svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents: 65
diff changeset
  2627
			st->build_date = _date;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2628
			for(j=0; j!=NUM_CARGO; j++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2629
				st->goods[j].waiting_acceptance = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2630
				st->goods[j].days_since_pickup = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2631
				st->goods[j].enroute_from = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2632
				st->goods[j].rating = 175;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2633
				st->goods[j].last_speed = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2634
				st->goods[j].last_age = 255;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2635
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2636
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2637
			UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2638
			UpdateStationAcceptance(st, false);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2639
			return;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2642
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2644
void DeleteOilRig(uint tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2645
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2646
	Station *st = DEREF_STATION(_map2[tile]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2647
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2648
	DoClearSquare(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2649
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2650
	st->dock_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2651
	st->airport_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2652
	st->facilities &= ~(FACIL_AIRPORT | FACIL_DOCK);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2653
	st->airport_flags = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2654
	UpdateStationVirtCoordDirty(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2655
	DeleteStation(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2656
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2657
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2658
static void ChangeTileOwner_Station(uint tile, byte old_player, byte new_player)
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
	if (_map_owner[tile] != old_player)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2661
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2662
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2663
	if (new_player != 255) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2664
		Station *st = DEREF_STATION(_map2[tile]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2665
		_map_owner[tile] = new_player;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2666
		st->owner = new_player;
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2667
		_global_station_sort_dirty = true; // transfer ownership of station to another player
65
f9f866bc609c (svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents: 59
diff changeset
  2668
		InvalidateWindowClasses(WC_STATION_LIST);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2669
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2670
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2671
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2672
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2673
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2674
static int32 ClearTile_Station(uint tile, byte flags) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2675
	byte m5 = _map5[tile];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2676
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2677
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2678
	if (flags & DC_AUTO) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2679
		if (m5 < 8) return_cmd_error(STR_300B_MUST_DEMOLISH_RAILROAD);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2680
		if (m5 < 0x43 || (m5 >= 83 && m5 <= 114)) return_cmd_error(STR_300E_MUST_DEMOLISH_AIRPORT_FIRST);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2681
		if (m5 < 0x47) return_cmd_error(STR_3047_MUST_DEMOLISH_TRUCK_STATION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2682
		if (m5 < 0x4B) return_cmd_error(STR_3046_MUST_DEMOLISH_BUS_STATION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2683
		if (m5 == 0x52) return_cmd_error(STR_306A_BUOY_IN_THE_WAY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2684
		if (m5 != 0x4B && m5 < 0x53) return_cmd_error(STR_304D_MUST_DEMOLISH_DOCK_FIRST);
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  2685
		SetDParam(0, STR_4807_OIL_RIG);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2686
		return_cmd_error(STR_4800_IN_THE_WAY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2687
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2689
	st = DEREF_STATION(_map2[tile]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2690
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2691
	if (m5 < 8)
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 123
diff changeset
  2692
		return RemoveRailroadStation(st, tile, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2693
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2694
	// original airports < 67, new airports between 83 - 114
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2695
	if (m5 < 0x43 || ( m5 >= 83 && m5 <= 114) )
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2696
		return RemoveAirport(st, flags);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2697
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2698
	if (m5 < 0x47)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2699
		return RemoveTruckStation(st, flags);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2700
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2701
	if (m5 < 0x4B)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2702
		return RemoveBusStation(st, flags);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2703
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2704
	if (m5 == 0x52)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2705
		return RemoveBuoy(st, flags);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2706
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2707
	if (m5 != 0x4B && m5 < 0x53)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2708
		return RemoveDock(st, flags);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2709
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2710
	return CMD_ERROR;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2713
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2714
void InitializeStations()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2715
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2716
	int i;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 536
diff changeset
  2717
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2718
	memset(_stations, 0, sizeof(_stations));
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2719
	for(i = 0; i != lengthof(_stations); i++)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2720
		_stations[i].index=i;
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2721
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2722
	_station_tick_ctr = 0;
243
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2723
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2724
	// set stations to be sorted on load of savegame
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2725
	memset(_station_sort_dirty, true, sizeof(_station_sort_dirty));
9a40daa560ae (svn r244) -Fix: Stations were not sorted for non-player-0 players
darkvater
parents: 222
diff changeset
  2726
	_global_station_sort_dirty = true; // load of savegame
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2727
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2728
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2729
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2730
const TileTypeProcs _tile_type_station_procs = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2731
	DrawTile_Station,						/* draw_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2732
	GetSlopeZ_Station,					/* get_slope_z_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2733
	ClearTile_Station,					/* clear_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2734
	GetAcceptedCargo_Station,		/* get_accepted_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2735
	GetTileDesc_Station,				/* get_tile_desc_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2736
	GetTileTrackStatus_Station,	/* get_tile_track_status_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2737
	ClickTile_Station,					/* click_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2738
	AnimateTile_Station,				/* animate_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2739
	TileLoop_Station,						/* tile_loop_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2740
	ChangeTileOwner_Station,		/* change_tile_owner_clear */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2741
	NULL,												/* get_produced_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2742
	VehicleEnter_Station,				/* vehicle_enter_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2743
	NULL,												/* vehicle_leave_tile_proc */
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 28
diff changeset
  2744
	GetSlopeTileh_Station,			/* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2745
};
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2748
static const byte _station_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2749
	SLE_VAR(Station,xy,							SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2750
	SLE_VAR(Station,bus_tile,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2751
	SLE_VAR(Station,lorry_tile,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2752
	SLE_VAR(Station,train_tile,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2753
	SLE_VAR(Station,airport_tile,		SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2754
	SLE_VAR(Station,dock_tile,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2755
	SLE_REF(Station,town,						REF_TOWN),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2756
	SLE_VAR(Station,trainst_w,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2757
	SLE_CONDVAR(Station,trainst_h,	SLE_UINT8, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2758
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2759
	// alpha_order was stored here in savegame format 0 - 3
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2760
	SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 1, 0, 3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2761
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2762
	SLE_VAR(Station,string_id,			SLE_STRINGID),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2763
	SLE_VAR(Station,had_vehicle_of_type,SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2764
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2765
	SLE_VAR(Station,time_since_load,		SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2766
	SLE_VAR(Station,time_since_unload,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2767
	SLE_VAR(Station,delete_ctr,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2768
	SLE_VAR(Station,owner,							SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2769
	SLE_VAR(Station,facilities,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2770
	SLE_VAR(Station,airport_type,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2771
	SLE_VAR(Station,truck_stop_status,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2772
	SLE_VAR(Station,bus_stop_status,		SLE_UINT8),
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
  2773
123
d550772c61e6 (svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents: 121
diff changeset
  2774
	// blocked_months was stored here in savegame format 0 - 4.0
d550772c61e6 (svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents: 121
diff changeset
  2775
	SLE_CONDVAR(Station,blocked_months_obsolete,	SLE_UINT8, 0, 4),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2776
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2777
	SLE_CONDVAR(Station,airport_flags,			SLE_VAR_U32 | SLE_FILE_U16, 0, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2778
	SLE_CONDVAR(Station,airport_flags,			SLE_UINT32, 3, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2779
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2780
	SLE_VAR(Station,last_vehicle,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2781
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2782
	SLE_CONDVAR(Station,class_id,				SLE_UINT8, 3, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2783
	SLE_CONDVAR(Station,stat_id,				SLE_UINT8, 3, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2784
	SLE_CONDVAR(Station,build_date,			SLE_UINT16, 3, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2785
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2786
	// reserve extra space in savegame here. (currently 32 bytes)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2787
	SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 32, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2788
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2789
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2790
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2791
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2792
static const byte _goods_desc[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2793
	SLE_VAR(GoodsEntry,waiting_acceptance,SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2794
	SLE_VAR(GoodsEntry,days_since_pickup,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2795
	SLE_VAR(GoodsEntry,rating,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2796
	SLE_VAR(GoodsEntry,enroute_from,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2797
	SLE_VAR(GoodsEntry,enroute_time,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2798
	SLE_VAR(GoodsEntry,last_speed,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2799
	SLE_VAR(GoodsEntry,last_age,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2800
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2801
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2802
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2803
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2804
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2805
static void SaveLoad_STNS(Station *st)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2806
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2807
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2808
	SlObject(st, _station_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2809
	for(i=0; i!=NUM_CARGO; i++)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2810
		SlObject(&st->goods[i], _goods_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2811
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2812
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2813
static void Save_STNS()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2814
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2815
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2816
	// Write the vehicles
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2817
	FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2818
		if (st->xy != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2819
			SlSetArrayIndex(st->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2820
			SlAutolength((AutolengthProc*)SaveLoad_STNS, st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2821
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2822
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2823
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2824
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2825
static void Load_STNS()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2826
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2827
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2828
	while ((index = SlIterateArray()) != -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2829
		Station *st = &_stations[index];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2830
		SaveLoad_STNS(st);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2831
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2832
		// this means it's an oldstyle savegame without support for nonuniform stations
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2833
		if (st->train_tile && st->trainst_h == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2834
			int w = st->trainst_w >> 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2835
			int h = st->trainst_w & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2836
			if (_map5[st->train_tile]&1) intswap(w,h);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2837
			st->trainst_w = w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2838
			st->trainst_h = h;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2839
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2840
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2841
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2842
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2843
const ChunkHandler _station_chunk_handlers[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2844
	{ 'STNS', Save_STNS, Load_STNS, CH_ARRAY | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2845
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2846