src/station.cpp
author rubidium
Wed, 26 Nov 2008 01:03:34 +0000
changeset 10383 7aee0e95303f
parent 10347 6da2d30f2fe8
permissions -rw-r--r--
(svn r14634) -Change: _rdtsc is defined by some platforms so we can't use that name.
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
     1
/* $Id$ */
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9043
diff changeset
     3
/** @file station.cpp Implementation of the station base class. */
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
     4
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
     5
#include "stdafx.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
     6
#include "openttd.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
     7
#include "bridge_map.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
     8
#include "debug.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
     9
#include "station_map.h"
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8784
diff changeset
    10
#include "station_base.h"
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    11
#include "town.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    12
#include "saveload.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    13
#include "company_func.h"
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    14
#include "airport.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    15
#include "sprite.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    16
#include "train.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    17
#include "water_map.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    18
#include "industry_map.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    19
#include "newgrf_callbacks.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    20
#include "newgrf_station.h"
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    21
#include "yapf/yapf.h"
7469
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
    22
#include "cargotype.h"
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
    23
#include "roadveh.h"
9043
eb4f06b99146 (svn r12862) -Codechange: reduce code duplication for VehicleType -> WindowClass lookup
smatz
parents: 8962
diff changeset
    24
#include "window_type.h"
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 7931
diff changeset
    25
#include "station_gui.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    26
#include "zoom_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    27
#include "functions.h"
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    28
#include "window_func.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    29
#include "date_func.h"
8211
29a8510dfd62 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8144
diff changeset
    30
#include "variables.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    31
#include "settings_type.h"
8275
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8270
diff changeset
    32
#include "command_func.h"
8784
c2e9d649a9ce (svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents: 8763
diff changeset
    33
#include "order_func.h"
10123
f73d96619303 (svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz
parents: 9413
diff changeset
    34
#include "news_func.h"
10155
9dbb48444f7f (svn r14344) -Fix: when a new airport is built in the same tick as the old station is deleted, aircraft may go crazy (and crash the game)
smatz
parents: 10123
diff changeset
    35
#include "aircraft.h"
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    36
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    37
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    38
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    39
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    40
Station::Station(TileIndex tile)
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    41
{
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    42
	DEBUG(station, cDebugCtorLevel, "I+%3d", index);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    43
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    44
	xy = tile;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    45
	airport_tile = dock_tile = train_tile = 0;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    46
	bus_stops = truck_stops = NULL;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    47
	had_vehicle_of_type = 0;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    48
	time_since_load = 255;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    49
	time_since_unload = 255;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    50
	delete_ctr = 0;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    51
	facilities = 0;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    52
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
    53
	last_vehicle_type = VEH_INVALID;
10347
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10290
diff changeset
    54
	indtype = IT_INVALID;
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    55
5721
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
    56
	random_bits = 0; // Random() must be called when station is really built (DC_EXEC)
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    57
	waiting_triggers = 0;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    58
}
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    59
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    60
/**
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6259
diff changeset
    61
 * Clean up a station by clearing vehicle orders and invalidating windows.
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6259
diff changeset
    62
 * Aircraft-Hangar orders need special treatment here, as the hangars are
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6259
diff changeset
    63
 * actually part of a station (tiletype is STATION), but the order type
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6259
diff changeset
    64
 * is OT_GOTO_DEPOT.
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6259
diff changeset
    65
 */
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    66
Station::~Station()
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    67
{
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    68
	DEBUG(station, cDebugCtorLevel, "I-%3d", index);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    69
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
    70
	free(this->name);
7413
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7377
diff changeset
    71
	free(this->speclist);
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7377
diff changeset
    72
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7377
diff changeset
    73
	if (CleaningPool()) return;
a590f7f0edb3 (svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium
parents: 7377
diff changeset
    74
7453
f0e43db55531 (svn r10931) -Fix [FS#1131]: when a station was destroyed and a vehicle was still loading, changing the current order of the loading vehicle caused a crash. This could happen with removing docks and oil rigs.
rubidium
parents: 7420
diff changeset
    75
	while (!loading_vehicles.empty()) {
f0e43db55531 (svn r10931) -Fix [FS#1131]: when a station was destroyed and a vehicle was still loading, changing the current order of the loading vehicle caused a crash. This could happen with removing docks and oil rigs.
rubidium
parents: 7420
diff changeset
    76
		loading_vehicles.front()->LeaveStation();
f0e43db55531 (svn r10931) -Fix [FS#1131]: when a station was destroyed and a vehicle was still loading, changing the current order of the loading vehicle caused a crash. This could happen with removing docks and oil rigs.
rubidium
parents: 7420
diff changeset
    77
	}
f0e43db55531 (svn r10931) -Fix [FS#1131]: when a station was destroyed and a vehicle was still loading, changing the current order of the loading vehicle caused a crash. This could happen with removing docks and oil rigs.
rubidium
parents: 7420
diff changeset
    78
10155
9dbb48444f7f (svn r14344) -Fix: when a new airport is built in the same tick as the old station is deleted, aircraft may go crazy (and crash the game)
smatz
parents: 10123
diff changeset
    79
	Vehicle *v;
9dbb48444f7f (svn r14344) -Fix: when a new airport is built in the same tick as the old station is deleted, aircraft may go crazy (and crash the game)
smatz
parents: 10123
diff changeset
    80
	FOR_ALL_VEHICLES(v) {
9dbb48444f7f (svn r14344) -Fix: when a new airport is built in the same tick as the old station is deleted, aircraft may go crazy (and crash the game)
smatz
parents: 10123
diff changeset
    81
		if (v->type == VEH_AIRCRAFT && IsNormalAircraft(v) && v->u.air.targetairport == this->index) {
9dbb48444f7f (svn r14344) -Fix: when a new airport is built in the same tick as the old station is deleted, aircraft may go crazy (and crash the game)
smatz
parents: 10123
diff changeset
    82
			v->u.air.targetairport = INVALID_STATION;
9dbb48444f7f (svn r14344) -Fix: when a new airport is built in the same tick as the old station is deleted, aircraft may go crazy (and crash the game)
smatz
parents: 10123
diff changeset
    83
		}
9dbb48444f7f (svn r14344) -Fix: when a new airport is built in the same tick as the old station is deleted, aircraft may go crazy (and crash the game)
smatz
parents: 10123
diff changeset
    84
	}
9dbb48444f7f (svn r14344) -Fix: when a new airport is built in the same tick as the old station is deleted, aircraft may go crazy (and crash the game)
smatz
parents: 10123
diff changeset
    85
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    86
	MarkDirty();
9297
1cb8d7bbdc8a (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium
parents: 9111
diff changeset
    87
	InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    88
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    89
	DeleteWindowById(WC_STATION_VIEW, index);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    90
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    91
	/* Now delete all orders that go to the station */
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    92
	RemoveOrderFromAllVehicles(OT_GOTO_STATION, index);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    93
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
    94
	/* Subsidies need removal as well */
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    95
	DeleteSubsidyWithStation(index);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
    96
10123
f73d96619303 (svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz
parents: 9413
diff changeset
    97
	/* Remove all news items */
f73d96619303 (svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz
parents: 9413
diff changeset
    98
	DeleteStationNews(this->index);
f73d96619303 (svn r14307) -Fix: when deleting a station, remove news items regarding it
smatz
parents: 9413
diff changeset
    99
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   100
	xy = 0;
7010
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6823
diff changeset
   101
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6823
diff changeset
   102
	for (CargoID c = 0; c < NUM_CARGO; c++) {
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6823
diff changeset
   103
		goods[c].cargo.Truncate(0);
6f0d9f03180d (svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium
parents: 6823
diff changeset
   104
	}
7376
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7010
diff changeset
   105
}
066596e64cd5 (svn r10745) -Codechange: generalize the pool cleanup/initialize functions for stations (in such a manner that they can be used for other pools too).
rubidium
parents: 7010
diff changeset
   106
7469
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   107
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   108
/**
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   109
 * Get the primary road stop (the first road stop) that the given vehicle can load/unload.
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   110
 * @param v the vehicle to get the first road stop for
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   111
 * @return the first roadstop that this vehicle can load at
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   112
 */
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   113
RoadStop *Station::GetPrimaryRoadStop(const Vehicle *v) const
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   114
{
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8784
diff changeset
   115
	RoadStop *rs = this->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK);
7469
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   116
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   117
	for (; rs != NULL; rs = rs->next) {
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   118
		/* The vehicle cannot go to this roadstop (different roadtype) */
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   119
		if ((GetRoadTypes(rs->xy) & v->u.road.compatible_roadtypes) == ROADTYPES_NONE) continue;
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   120
		/* The vehicle is articulated and can therefor not go the a standard road stop */
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   121
		if (IsStandardRoadStopTile(rs->xy) && RoadVehHasArticPart(v)) continue;
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   122
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   123
		/* The vehicle can actually go to this road stop. So, return it! */
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   124
		break;
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   125
	}
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   126
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   127
	return rs;
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   128
}
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   129
5721
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   130
/** Called when new facility is built on the station. If it is the first facility
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6259
diff changeset
   131
 * it initializes also 'xy' and 'random_bits' members */
5721
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   132
void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy)
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   133
{
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   134
	if (facilities == 0) {
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   135
		xy = facil_xy;
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   136
		random_bits = Random();
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   137
	}
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   138
	facilities |= new_facility_bit;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10155
diff changeset
   139
	owner = _current_company;
5721
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   140
	build_date = _date;
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   141
}
fa4e587f59f5 (svn r8231) -Fix (r8125): MP desync caused by calling Random() from station constructor. This was wrong because station constructor is called also when loading savegame and when player tries to build station when it is not sure that it will succeed (thanks Rubidium)
KUDr
parents: 5718
diff changeset
   142
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   143
void Station::MarkDirty() const
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   144
{
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   145
	if (sign.width_1 != 0) {
8016
1c7062ad5f50 (svn r11576) -Codechange: enumerize and comment station GUI
smatz
parents: 7931
diff changeset
   146
		InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_CAPTION);
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   147
6700
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
   148
		/* We use ZOOM_LVL_MAX here, as every viewport can have an other zoom,
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
   149
		 *  and there is no way for us to know which is the biggest. So make the
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
   150
		 *  biggest area dirty, and we are safe for sure. */
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   151
		MarkAllViewportsDirty(
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   152
			sign.left - 6,
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   153
			sign.top,
6700
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
   154
			sign.left + ScaleByZoom(sign.width_1 + 12, ZOOM_LVL_MAX),
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
   155
			sign.top + ScaleByZoom(12, ZOOM_LVL_MAX));
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   156
	}
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   157
}
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   158
6823
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   159
void Station::MarkTilesDirty(bool cargo_change) const
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   160
{
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   161
	TileIndex tile = train_tile;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   162
	int w, h;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   163
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   164
	/* XXX No station is recorded as 0, not INVALID_TILE... */
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   165
	if (tile == 0) return;
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   166
6823
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   167
	/* cargo_change is set if we're refreshing the tiles due to cargo moving
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   168
	 * around. */
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   169
	if (cargo_change) {
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   170
		/* Don't waste time updating if there are no custom station graphics
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   171
		 * that might change. Even if there are custom graphics, they might
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   172
		 * not change. Unfortunately we have no way of telling. */
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   173
		if (this->num_specs == 0) return;
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   174
	}
1f2075619543 (svn r10062) -Codechange: Don't redraw all station tiles when cargo is added or removed if the station has no custom graphics.
peter1138
parents: 6700
diff changeset
   175
5665
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   176
	for (h = 0; h < trainst_h; h++) {
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   177
		for (w = 0; w < trainst_w; w++) {
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   178
			if (TileBelongsToRailStation(tile)) {
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   179
				MarkTileDirtyByTile(tile);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   180
			}
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   181
			tile += TileDiffXY(1, 0);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   182
		}
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   183
		tile += TileDiffXY(-w, 1);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   184
	}
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   185
}
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   186
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   187
bool Station::TileBelongsToRailStation(TileIndex tile) const
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   188
{
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   189
	return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == index && IsRailwayStation(tile);
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   190
}
d6b5c720ad67 (svn r8125) -Codechange: Station is now constructed/destroyed using new/delete operators (don't worry, they still use the same memory pool). Few station related functions turned into Station::methods (just first step). All this new stuff moved from station_cmd.cpp to the new file (station.cpp).
KUDr
parents:
diff changeset
   191
5998
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   192
/** Obtain the length of a platform
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   193
 * @pre tile must be a railway station tile
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   194
 * @param tile A tile that contains the platform in question
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6259
diff changeset
   195
 * @return The length of the platform
5998
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   196
 */
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   197
uint Station::GetPlatformLength(TileIndex tile) const
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   198
{
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   199
	TileIndex t;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   200
	TileIndexDiff delta;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   201
	uint len = 0;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   202
	assert(TileBelongsToRailStation(tile));
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   203
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   204
	delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   205
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   206
	t = tile;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   207
	do {
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   208
		t -= delta;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   209
		len++;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   210
	} while (IsCompatibleTrainStationTile(t, tile));
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   211
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   212
	t = tile;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   213
	do {
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   214
		t += delta;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   215
		len++;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   216
	} while (IsCompatibleTrainStationTile(t, tile));
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   217
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   218
	return len - 1;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   219
}
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   220
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   221
/** Determines the REMAINING length of a platform, starting at (and including)
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   222
 * the given tile.
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   223
 * @param tile the tile from which to start searching. Must be a railway station tile
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   224
 * @param dir The direction in which to search.
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   225
 * @return The platform length
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   226
 */
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   227
uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   228
{
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   229
	TileIndex start_tile = tile;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   230
	uint length = 0;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   231
	assert(IsRailwayStationTile(tile));
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   232
	assert(dir < DIAGDIR_END);
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   233
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   234
	do {
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   235
		length ++;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   236
		tile += TileOffsByDiagDir(dir);
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   237
	} while (IsCompatibleTrainStationTile(tile, start_tile));
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   238
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   239
	return length;
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   240
}
2bfbade143ac (svn r8709) -Fix/Codechange: Rename the function GetStationPlatforms into GetPlatformLength because that is what it really does. Overload it because there is already a GetPlatformLength (one gives the length of the whole platform, the other gives the remaining length in a given direction). Turned both functions into methods of Station. While messing around with it, fix a problem where loading times for overhanging trains are miscomputed.
celestar
parents: 5997
diff changeset
   241
5896
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   242
/** Determines whether a station is a buoy only.
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   243
 * @todo Ditch this encoding of buoys
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   244
 */
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   245
bool Station::IsBuoy() const
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   246
{
5997
e6d057d90fce (svn r8708) -Codechange(r8514): No need to use "this->" in methods
celestar
parents: 5996
diff changeset
   247
	return (had_vehicle_of_type & HVOT_BUOY) != 0;
5896
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   248
}
a9f7bdd841d4 (svn r8514) -Codechange: Turn IsBuoy into a method of stations
celestar
parents: 5867
diff changeset
   249
10290
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   250
/** Determines the catchment radius of the station
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   251
 * @return The radius
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   252
 */
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   253
uint Station::GetCatchmentRadius() const
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   254
{
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   255
	uint ret = CA_NONE;
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   256
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   257
	if (_settings_game.station.modified_catchment) {
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   258
		if (this->bus_stops    != NULL) ret = max<uint>(ret, CA_BUS);
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   259
		if (this->truck_stops  != NULL) ret = max<uint>(ret, CA_TRUCK);
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   260
		if (this->train_tile   != 0)    ret = max<uint>(ret, CA_TRAIN);
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   261
		if (this->dock_tile    != 0)    ret = max<uint>(ret, CA_DOCK);
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   262
		if (this->airport_tile != 0)    ret = max<uint>(ret, this->Airport()->catchment);
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   263
	} else {
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   264
		if (this->bus_stops != NULL || this->truck_stops != NULL || this->train_tile != 0 || this->dock_tile != 0 || this->airport_tile != 0) {
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   265
			ret = CA_UNMODIFIED;
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   266
		}
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   267
	}
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   268
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   269
	return ret;
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   270
}
56925f09d693 (svn r14529) -Codechange: Turn FindCatchmentRadius() into Station::GetCatchmentRadius().
frosch
parents: 10260
diff changeset
   271
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   272
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   273
/************************************************************************/
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   274
/*                     StationRect implementation                       */
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   275
/************************************************************************/
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   276
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   277
StationRect::StationRect()
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   278
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   279
	MakeEmpty();
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   280
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   281
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   282
void StationRect::MakeEmpty()
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   283
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   284
	left = top = right = bottom = 0;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   285
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   286
5910
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   287
/**
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   288
 * Determines whether a given point (x, y) is within a certain distance of
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   289
 * the station rectangle.
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   290
 * @note x and y are in Tile coordinates
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   291
 * @param x X coordinate
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   292
 * @param y Y coordinate
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   293
 * @param distance The maxmium distance a point may have (L1 norm)
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   294
 * @return true if the point is within distance tiles of the station rectangle
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   295
 */
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   296
bool StationRect::PtInExtendedRect(int x, int y, int distance) const
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   297
{
5910
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   298
	return (left - distance <= x && x <= right + distance && top - distance <= y && y <= bottom + distance);
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   299
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   300
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   301
bool StationRect::IsEmpty() const
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   302
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   303
	return (left == 0 || left > right || top > bottom);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   304
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   305
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   306
bool StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   307
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   308
	int x = TileX(tile);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   309
	int y = TileY(tile);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   310
	if (IsEmpty()) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   311
		/* we are adding the first station tile */
10241
06397873be0d (svn r14469) -Fix [FS#2355]: Empty station spreads (e.g. from greyed station signs) were modified in test mode.
frosch
parents: 10208
diff changeset
   312
		if (mode != ADD_TEST) {
06397873be0d (svn r14469) -Fix [FS#2355]: Empty station spreads (e.g. from greyed station signs) were modified in test mode.
frosch
parents: 10208
diff changeset
   313
			left = right = x;
06397873be0d (svn r14469) -Fix [FS#2355]: Empty station spreads (e.g. from greyed station signs) were modified in test mode.
frosch
parents: 10208
diff changeset
   314
			top = bottom = y;
06397873be0d (svn r14469) -Fix [FS#2355]: Empty station spreads (e.g. from greyed station signs) were modified in test mode.
frosch
parents: 10208
diff changeset
   315
		}
5910
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   316
	} else if (!PtInExtendedRect(x, y)) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   317
		/* current rect is not empty and new point is outside this rect */
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   318
		/* make new spread-out rectangle */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   319
		Rect new_rect = {min(x, left), min(y, top), max(x, right), max(y, bottom)};
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   320
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   321
		/* check new rect dimensions against preset max */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   322
		int w = new_rect.right - new_rect.left + 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   323
		int h = new_rect.bottom - new_rect.top + 1;
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9354
diff changeset
   324
		if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   325
			assert(mode != ADD_TRY);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   326
			_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   327
			return false;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   328
		}
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   329
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   330
		/* spread-out ok, return true */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   331
		if (mode != ADD_TEST) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   332
			/* we should update the station rect */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   333
			*this = new_rect;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   334
		}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   335
	} else {
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   336
		; // new point is inside the rect, we don't need to do anything
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   337
	}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   338
	return true;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   339
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   340
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   341
bool StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   342
{
10241
06397873be0d (svn r14469) -Fix [FS#2355]: Empty station spreads (e.g. from greyed station signs) were modified in test mode.
frosch
parents: 10208
diff changeset
   343
	return (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) && // important when the old rect is completely inside the new rect, resp. the old one was empty
06397873be0d (svn r14469) -Fix [FS#2355]: Empty station spreads (e.g. from greyed station signs) were modified in test mode.
frosch
parents: 10208
diff changeset
   344
			BeforeAddTile(tile, mode) && BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   345
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   346
10260
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   347
/**
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   348
 * Check whether station tiles of the given station id exist in the given rectangle
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   349
 * @param st_id    Station ID to look for in the rectangle
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   350
 * @param left_a   Minimal tile X edge of the rectangle
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   351
 * @param top_a    Minimal tile Y edge of the rectangle
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   352
 * @param right_a  Maximal tile X edge of the rectangle (inclusive)
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   353
 * @param bottom_a Maximal tile Y edge of the rectangle (inclusive)
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   354
 * @return \c true if a station tile with the given \a st_id exists in the rectangle, \c false otherwise
c6ec6b3c1b18 (svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium
parents: 10241
diff changeset
   355
 */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   356
/*static*/ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   357
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   358
	TileIndex top_left = TileXY(left_a, top_a);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   359
	int width = right_a - left_a + 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   360
	int height = bottom_a - top_a + 1;
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   361
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   362
	BEGIN_TILE_LOOP(tile, width, height, top_left)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   363
		if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   364
	END_TILE_LOOP(tile, width, height, top_left);
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   365
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   366
	return false;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   367
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   368
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   369
bool StationRect::AfterRemoveTile(Station *st, TileIndex tile)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   370
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   371
	int x = TileX(tile);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   372
	int y = TileY(tile);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   373
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   374
	/* look if removed tile was on the bounding rect edge
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   375
	 * and try to reduce the rect by this edge
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   376
	 * do it until we have empty rect or nothing to do */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   377
	for (;;) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   378
		/* check if removed tile is on rect edge */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   379
		bool left_edge = (x == left);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   380
		bool right_edge = (x == right);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   381
		bool top_edge = (y == top);
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   382
		bool bottom_edge = (y == bottom);
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   383
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   384
		/* can we reduce the rect in either direction? */
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   385
		bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, top, x, bottom));
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   386
		bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->index, left, y, right, y));
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   387
		if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce)
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   388
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   389
		if (reduce_x) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   390
			/* reduce horizontally */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   391
			if (left_edge) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   392
				/* move left edge right */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   393
				left = x = x + 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   394
			} else {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   395
				/* move right edge left */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   396
				right = x = x - 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   397
			}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   398
		}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   399
		if (reduce_y) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   400
			/* reduce vertically */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   401
			if (top_edge) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   402
				/* move top edge down */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   403
				top = y = y + 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   404
			} else {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   405
				/* move bottom edge up */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   406
				bottom = y = y - 1;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   407
			}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   408
		}
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   409
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   410
		if (left > right || top > bottom) {
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   411
			/* can't continue, if the remaining rectangle is empty */
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   412
			MakeEmpty();
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   413
			return true; // empty remaining rect
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   414
		}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   415
	}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   416
	return false; // non-empty remaining rect
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   417
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   418
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   419
bool StationRect::AfterRemoveRect(Station *st, TileIndex tile, int w, int h)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   420
{
5910
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   421
	assert(PtInExtendedRect(TileX(tile), TileY(tile)));
f1409c7e8a87 (svn r8536) -Fix (FS#577): Road Vehicles now can obtain a slot even if the station is very spread out
celestar
parents: 5896
diff changeset
   422
	assert(PtInExtendedRect(TileX(tile) + w - 1, TileY(tile) + h - 1));
5678
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   423
2669a5a2aa02 (svn r8138) -Cleanup: comment style corrections
KUDr
parents: 5676
diff changeset
   424
	bool empty = AfterRemoveTile(st, tile);
5676
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   425
	if (w != 1 || h != 1) empty = empty || AfterRemoveTile(st, TILE_ADDXY(tile, w - 1, h - 1));
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   426
	return empty;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   427
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   428
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   429
StationRect& StationRect::operator = (Rect src)
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   430
{
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   431
	left = src.left;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   432
	top = src.top;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   433
	right = src.right;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   434
	bottom = src.bottom;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   435
	return *this;
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   436
}
7a641ebbc080 (svn r8136) -Codechange: Station spread rectangle manipulators turned into StationRect::methods.
KUDr
parents: 5670
diff changeset
   437
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   438
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   439
/************************************************************************/
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   440
/*                     RoadStop implementation                          */
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   441
/************************************************************************/
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   442
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   443
/** Initializes a RoadStop */
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5713
diff changeset
   444
RoadStop::RoadStop(TileIndex tile) :
5713
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   445
	xy(tile),
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   446
	status(3), // stop is free
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   447
	num_vehicles(0),
5867
b7aa408ce6f3 (svn r8449) -Fix
tron
parents: 5835
diff changeset
   448
	next(NULL)
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   449
{
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5713
diff changeset
   450
	DEBUG(ms, cDebugCtorLevel,  "I+ at %d[0x%x]", tile, tile);
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   451
}
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   452
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   453
/** De-Initializes a RoadStops. This includes clearing all slots that vehicles might
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   454
  * have and unlinks it from the linked list of road stops at the given station
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   455
  */
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   456
RoadStop::~RoadStop()
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   457
{
7420
0e3afa8102f0 (svn r10813) -Fix (r10799): some destructors were performing too much during the pool cleanups, which could cause crashes as already removed pool items could then be dereferenced by other destructors.
rubidium
parents: 7413
diff changeset
   458
	if (CleaningPool()) return;
0e3afa8102f0 (svn r10813) -Fix (r10799): some destructors were performing too much during the pool cleanups, which could cause crashes as already removed pool items could then be dereferenced by other destructors.
rubidium
parents: 7413
diff changeset
   459
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   460
	/* Clear the slot assignment of all vehicles heading for this road stop */
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   461
	if (num_vehicles != 0) {
5713
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   462
		Vehicle *v;
979dc0617902 (svn r8203) -Fix:
tron
parents: 5708
diff changeset
   463
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   464
		FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   465
			if (v->type == VEH_ROAD && v->u.road.slot == this) ClearSlot(v);
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   466
		}
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   467
	}
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   468
	assert(num_vehicles == 0);
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   469
5716
7176379debd0 (svn r8207) -Fix
tron
parents: 5713
diff changeset
   470
	DEBUG(ms, cDebugCtorLevel , "I- at %d[0x%x]", xy, xy);
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   471
7377
b6479e048c6e (svn r10746) -Codechange: add a generic superclass for almost all pool items so we do not have to duplicate code for each of the pool item classes and use it for the station and roadstop classes.
rubidium
parents: 7376
diff changeset
   472
	xy = 0;
5708
4c4c5ec2bed6 (svn r8185) -Codechange: Equipped Roadstops with new/delete operators and gave them proper constructors/destructors (Thanks to KUDr for a nice interactive C++ lesson)
celestar
parents: 5678
diff changeset
   473
}
5835
7ef65a4a70ef (svn r8401) -Codechange: Make 'IsValidRoadStop' a method of RoadStop and rename it to 'IsValid'
celestar
parents: 5721
diff changeset
   474
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   475
/** Checks whether there is a free bay in this road stop */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   476
bool RoadStop::HasFreeBay() const
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   477
{
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   478
	return GB(status, 0, MAX_BAY_COUNT) != 0;
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   479
}
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   480
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   481
/** Checks whether the given bay is free in this road stop */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   482
bool RoadStop::IsFreeBay(uint nr) const
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   483
{
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   484
	assert(nr < MAX_BAY_COUNT);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7496
diff changeset
   485
	return HasBit(status, nr);
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   486
}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   487
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   488
/**
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   489
 * Allocates a bay
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   490
 * @return the allocated bay number
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   491
 * @pre this->HasFreeBay()
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   492
 */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   493
uint RoadStop::AllocateBay()
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   494
{
6005
f9ddc290e8b0 (svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents: 5998
diff changeset
   495
	assert(HasFreeBay());
f9ddc290e8b0 (svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents: 5998
diff changeset
   496
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   497
	/* Find the first free bay. If the bit is set, the bay is free. */
6005
f9ddc290e8b0 (svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents: 5998
diff changeset
   498
	uint bay_nr = 0;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7496
diff changeset
   499
	while (!HasBit(status, bay_nr)) bay_nr++;
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   500
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   501
	ClrBit(status, bay_nr);
6005
f9ddc290e8b0 (svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents: 5998
diff changeset
   502
	return bay_nr;
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   503
}
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   504
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   505
/**
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   506
 * Allocates a bay in a drive-through road stop
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   507
 * @param nr the number of the bay to allocate
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   508
 */
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   509
void RoadStop::AllocateDriveThroughBay(uint nr)
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   510
{
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   511
	assert(nr < MAX_BAY_COUNT);
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   512
	ClrBit(status, nr);
6012
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   513
}
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   514
065d7234a7a9 (svn r8735) -Feature: drive-through road stops made possible by the hard work of mart3p.
rubidium
parents: 6005
diff changeset
   515
/**
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   516
 * Frees the given bay
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   517
 * @param nr the number of the bay to free
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   518
 */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   519
void RoadStop::FreeBay(uint nr)
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   520
{
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   521
	assert(nr < MAX_BAY_COUNT);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   522
	SetBit(status, nr);
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   523
}
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   524
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   525
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   526
/** Checks whether the entrance of the road stop is occupied by a vehicle */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   527
bool RoadStop::IsEntranceBusy() const
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   528
{
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7496
diff changeset
   529
	return HasBit(status, 7);
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   530
}
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   531
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   532
/** Makes an entrance occupied or free */
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   533
void RoadStop::SetEntranceBusy(bool busy)
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   534
{
6005
f9ddc290e8b0 (svn r8726) -Codechange: bools are 1 or 0 according to the C++ standard and refactor RoadStop::AllocateBay to remove a loop condition. Suggestions by Tron.
rubidium
parents: 5998
diff changeset
   535
	SB(status, 7, 1, busy);
5990
280fbef32d44 (svn r8694) -Codechange: make RoadStop's status accessible via accessor functions.
rubidium
parents: 5910
diff changeset
   536
}
7469
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   537
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   538
/**
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   539
 * Get the next road stop accessible by this vehicle.
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   540
 * @param v the vehicle to get the next road stop for.
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   541
 * @return the next road stop accessible.
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   542
 */
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   543
RoadStop *RoadStop::GetNextRoadStop(const Vehicle *v) const
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   544
{
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   545
	for (RoadStop *rs = this->next; rs != NULL; rs = rs->next) {
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   546
		/* The vehicle cannot go to this roadstop (different roadtype) */
7471
e7e359e79b6a (svn r10978) -Fix (r10974): only the first road stop (with correct roadtype) was considered when distributing vehicles.
rubidium
parents: 7469
diff changeset
   547
		if ((GetRoadTypes(rs->xy) & v->u.road.compatible_roadtypes) == ROADTYPES_NONE) continue;
7469
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   548
		/* The vehicle is articulated and can therefor not go the a standard road stop */
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   549
		if (IsStandardRoadStopTile(rs->xy) && RoadVehHasArticPart(v)) continue;
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   550
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   551
		/* The vehicle can actually go to this road stop. So, return it! */
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   552
		return rs;
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   553
	}
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   554
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   555
	return NULL;
2c1dd5ce245d (svn r10974) -Fix [FS#1144, FS#1155]: road vehicles that could not (properly) use a road stop still tried to go to that road stop.
rubidium
parents: 7453
diff changeset
   556
}